From e2213d77a22a1d3d5d17167eb2760352760405e8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Feb 2020 21:55:57 +0100 Subject: [PATCH] Set 'ref' properly for local trees --- src/libstore/fetchers/git.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstore/fetchers/git.cc b/src/libstore/fetchers/git.cc index 1c74d92a4..35a5c18b5 100644 --- a/src/libstore/fetchers/git.cc +++ b/src/libstore/fetchers/git.cc @@ -23,6 +23,11 @@ static Path getCacheInfoPathFor(const std::string & name, const Hash & rev) return cacheDir + "/" + linkName + ".link"; } +static std::string readHead(const Path & path) +{ + return chomp(runProgram("git", true, { "-C", path, "rev-parse", "--abbrev-ref", "HEAD" })); +} + static void cacheGitInfo( Store & store, const std::string & name, @@ -268,7 +273,7 @@ struct GitInput : Input } } - if (!input->ref) input->ref = isLocal ? "HEAD" : "master"; + if (!input->ref) input->ref = isLocal ? readHead(actualUrl) : "master"; Path repoDir;