From 2e6f06c37e26a5ac5be35fe18f283a1b26de64bf Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Fri, 22 Dec 2017 14:18:29 -0600 Subject: fetchGit: Fix handling of local repo when not using 'master' branch Add tests checking this behavior. --- src/libexpr/primops/fetchGit.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc index e92e0638031f..0d0b11958a4b 100644 --- a/src/libexpr/primops/fetchGit.cc +++ b/src/libexpr/primops/fetchGit.cc @@ -23,7 +23,7 @@ struct GitInfo }; GitInfo exportGit(ref store, const std::string & uri, - std::experimental::optional ref, const std::string & rev, + std::experimental::optional ref, std::string rev, const std::string & name) { if (!ref && rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.git")) { @@ -68,6 +68,10 @@ GitInfo exportGit(ref store, const std::string & uri, return gitInfo; } + + // clean working tree, but no ref or rev specified. Use 'HEAD'. + rev = chomp(runProgram("git", true, { "-C", uri, "rev-parse", "HEAD" })); + ref = "HEAD"s; } if (!ref) ref = "master"s; -- cgit 1.4.1