about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2018-12-14T19·07+0100
committerDaiderd Jordan <daiderd@gmail.com>2018-12-14T19·12+0100
commit7e35e914c1aa24957107c666c76f1d834ebae90a (patch)
tree1cc09dcf703bbb299a6c81f491e7196ca15fc85e /src/libexpr
parentc37e6d77ea86df249aeaf65d329a6be3b837ad62 (diff)
fetchGit: allow fetching explicit refs
Trying to fetch refs that are not in refs/heads currently fails because
it looks for refs/heads/refs/foo instead of refs/foo.

eg.

	builtins.fetchGit {
	  url = https://github.com/NixOS/nixpkgs.git;
	  ref = "refs/pull/1024/head;
	}
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops/fetchGit.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc
index b46d2f258265..588b0fa4d53b 100644
--- a/src/libexpr/primops/fetchGit.cc
+++ b/src/libexpr/primops/fetchGit.cc
@@ -94,7 +94,11 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
         runProgram("git", true, { "init", "--bare", cacheDir });
     }
 
-    Path localRefFile = cacheDir + "/refs/heads/" + *ref;
+    Path localRefFile;
+    if (ref->compare(0, 5, "refs/") == 0)
+        localRefFile = cacheDir + "/" + *ref;
+    else
+        localRefFile = cacheDir + "/refs/heads/" + *ref;
 
     bool doFetch;
     time_t now = time(0);