Fetch specific Git revisions

This is more efficient, and necessary when using shallow=1 with a rev.
This commit is contained in:
Eelco Dolstra 2023-11-15 16:15:47 +01:00
parent f450c8773c
commit e4066c0444
2 changed files with 5 additions and 4 deletions

View file

@ -518,8 +518,11 @@ struct GitInputScheme : InputScheme
if (doFetch) {
try {
auto fetchRef = getAllRefsAttr(input)
auto fetchRef =
getAllRefsAttr(input)
? "refs/*"
: input.getRev()
? input.getRev()->gitRev()
: ref.compare(0, 5, "refs/") == 0
? ref
: ref == "HEAD"

View file

@ -51,9 +51,7 @@ git -C $repo add differentbranch
git -C $repo commit -m 'Test2'
git -C $repo checkout master
devrev=$(git -C $repo rev-parse devtest)
out=$(nix eval --impure --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; }" 2>&1) || status=$?
[[ $status == 1 ]]
[[ $out =~ 'Cannot find Git revision' ]]
nix eval --impure --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; }"
[[ $(nix eval --raw --expr "builtins.readFile (builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; allRefs = true; } + \"/differentbranch\")") = 'different file' ]]