Skip to content

Commit

Permalink
Fetch specific Git revisions
Browse files Browse the repository at this point in the history
This is more efficient, and necessary when using shallow=1 with a rev.
  • Loading branch information
edolstra committed Nov 20, 2023
1 parent f450c87 commit e4066c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/fetchGit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]]

Expand Down

0 comments on commit e4066c0

Please sign in to comment.