Skip to content

Commit a562d0b

Browse files
authored
Merge pull request #12386 from DeterminateSystems/git-fixes
Git fetcher: Don't create refs when fetching by revision
2 parents 1a8dfc0 + c8b2264 commit a562d0b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/libfetchers/git.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::optional<std::string> readHead(const Path & path)
6969

7070
std::string_view line = output;
7171
line = line.substr(0, line.find("\n"));
72-
if (const auto parseResult = git::parseLsRemoteLine(line)) {
72+
if (const auto parseResult = git::parseLsRemoteLine(line); parseResult && parseResult->reference == "HEAD") {
7373
switch (parseResult->kind) {
7474
case git::LsRemoteRefLine::Kind::Symbolic:
7575
debug("resolved HEAD ref '%s' for repo '%s'", parseResult->target, path);
@@ -459,8 +459,14 @@ struct GitInputScheme : InputScheme
459459
url);
460460
}
461461
repoInfo.location = std::filesystem::absolute(url.path);
462-
} else
462+
} else {
463+
if (url.scheme == "file")
464+
/* Query parameters are meaningless for file://, but
465+
Git interprets them as part of the file name. So get
466+
rid of them. */
467+
url.query.clear();
463468
repoInfo.location = url;
469+
}
464470

465471
// If this is a local directory and no ref or revision is
466472
// given, then allow the use of an unclean working tree.
@@ -605,16 +611,16 @@ struct GitInputScheme : InputScheme
605611
try {
606612
auto fetchRef =
607613
getAllRefsAttr(input)
608-
? "refs/*"
614+
? "refs/*:refs/*"
609615
: input.getRev()
610616
? input.getRev()->gitRev()
611617
: ref.compare(0, 5, "refs/") == 0
612-
? ref
618+
? fmt("%1%:%1%", ref)
613619
: ref == "HEAD"
614620
? ref
615-
: "refs/heads/" + ref;
621+
: fmt("%1%:%1%", "refs/heads/" + ref);
616622

617-
repo->fetch(repoUrl.to_string(), fmt("%s:%s", fetchRef, fetchRef), getShallowAttr(input));
623+
repo->fetch(repoUrl.to_string(), fetchRef, getShallowAttr(input));
618624
} catch (Error & e) {
619625
if (!std::filesystem::exists(localRefFile)) throw;
620626
logError(e.info());

0 commit comments

Comments
 (0)