1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 19:01:16 +02:00

Merge pull request #12429 from NixOS/mergify/bp/2.26-maintenance/pr-12386

Git fetcher: Don't create refs when fetching by revision (backport #12386)
This commit is contained in:
Eelco Dolstra 2025-02-06 15:24:14 +01:00 committed by GitHub
commit 31bdb2a8ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -69,7 +69,7 @@ std::optional<std::string> readHead(const Path & path)
std::string_view line = output; std::string_view line = output;
line = line.substr(0, line.find("\n")); line = line.substr(0, line.find("\n"));
if (const auto parseResult = git::parseLsRemoteLine(line)) { if (const auto parseResult = git::parseLsRemoteLine(line); parseResult && parseResult->reference == "HEAD") {
switch (parseResult->kind) { switch (parseResult->kind) {
case git::LsRemoteRefLine::Kind::Symbolic: case git::LsRemoteRefLine::Kind::Symbolic:
debug("resolved HEAD ref '%s' for repo '%s'", parseResult->target, path); debug("resolved HEAD ref '%s' for repo '%s'", parseResult->target, path);
@ -459,8 +459,14 @@ struct GitInputScheme : InputScheme
url); url);
} }
repoInfo.location = std::filesystem::absolute(url.path); repoInfo.location = std::filesystem::absolute(url.path);
} else } else {
if (url.scheme == "file")
/* Query parameters are meaningless for file://, but
Git interprets them as part of the file name. So get
rid of them. */
url.query.clear();
repoInfo.location = url; repoInfo.location = url;
}
// If this is a local directory and no ref or revision is // If this is a local directory and no ref or revision is
// given, then allow the use of an unclean working tree. // given, then allow the use of an unclean working tree.
@ -605,16 +611,16 @@ struct GitInputScheme : InputScheme
try { try {
auto fetchRef = auto fetchRef =
getAllRefsAttr(input) getAllRefsAttr(input)
? "refs/*" ? "refs/*:refs/*"
: input.getRev() : input.getRev()
? input.getRev()->gitRev() ? input.getRev()->gitRev()
: ref.compare(0, 5, "refs/") == 0 : ref.compare(0, 5, "refs/") == 0
? ref ? fmt("%1%:%1%", ref)
: ref == "HEAD" : ref == "HEAD"
? ref ? ref
: "refs/heads/" + ref; : fmt("%1%:%1%", "refs/heads/" + ref);
repo->fetch(repoUrl.to_string(), fmt("%s:%s", fetchRef, fetchRef), getShallowAttr(input)); repo->fetch(repoUrl.to_string(), fetchRef, getShallowAttr(input));
} catch (Error & e) { } catch (Error & e) {
if (!std::filesystem::exists(localRefFile)) throw; if (!std::filesystem::exists(localRefFile)) throw;
logError(e.info()); logError(e.info());