Skip to content

Commit

Permalink
readHead(): Make sure we're returning the HEAD ref line
Browse files Browse the repository at this point in the history
If we previously fetched by revision, the output of "git ls-remote"
won't start with the expected line like

  ref: refs/heads/master HEAD

but will be something like

  5c4410e3b9891c05ab40d723de78c6f0be45ad30        refs/heads/5c4410e3b9891c05ab40d723de78c6f0be45ad30

This then causes Nix to treat that revision as a refname, which then
leads to warnings like

  warning: could not update cached head '5c4410e3b9891c05ab40d723de78c6f0be45ad30' for 'file:///tmp/repo'
  • Loading branch information
edolstra committed Jan 30, 2025
1 parent ee9fa0d commit c8b2264
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::optional<std::string> readHead(const Path & path)

std::string_view line = output;
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) {
case git::LsRemoteRefLine::Kind::Symbolic:
debug("resolved HEAD ref '%s' for repo '%s'", parseResult->target, path);
Expand Down

0 comments on commit c8b2264

Please sign in to comment.