Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ce2c755d2aa4
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a15f9b37eba8
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Oct 7, 2019

  1. fetchGit: Support Git trees without any commits

    Fixes
    
      $ nix build
      fatal: bad revision 'HEAD'
      error: program 'git' failed with exit code 128
    
    on a new flake. It is now detected as a dirty tree with revCount = 0.
    edolstra committed Oct 7, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a15f9b3 View commit details
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/libexpr/primops/fetchGit.cc
16 changes: 11 additions & 5 deletions src/libexpr/primops/fetchGit.cc
Original file line number Diff line number Diff line change
@@ -33,13 +33,19 @@ GitInfo exportGit(ref<Store> store, std::string uri,
// or revision is given, then allow the use of an unclean working
// tree.
if (!ref && !rev && isLocal) {
bool clean = true;
bool clean = false;

/* Check whether this repo has any commits. There are
probably better ways to do this. */
bool haveCommits = !readDirectory(uri + "/.git/refs/heads").empty();

try {
runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" });
if (haveCommits) {
runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" });
clean = true;
}
} catch (ExecError & e) {
if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw;
clean = false;
}

if (!clean) {
@@ -75,10 +81,10 @@ GitInfo exportGit(ref<Store> store, std::string uri,
};

gitInfo.storePath = store->addToStore("source", uri, true, htSHA256, filter);
gitInfo.revCount = std::stoull(runProgram("git", true, { "-C", uri, "rev-list", "--count", "HEAD" }));
gitInfo.revCount = haveCommits ? std::stoull(runProgram("git", true, { "-C", uri, "rev-list", "--count", "HEAD" })) : 0;
// FIXME: maybe we should use the timestamp of the last
// modified dirty file?
gitInfo.lastModified = std::stoull(runProgram("git", true, { "-C", uri, "show", "-s", "--format=%ct", "HEAD" }));
gitInfo.lastModified = haveCommits ? std::stoull(runProgram("git", true, { "-C", uri, "show", "-s", "--format=%ct", "HEAD" })) : 0;

return gitInfo;
}