1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 14:10:59 +01:00

libfetchers: Fix fetchGit with ref = "HEAD"

This seems to have been broken in ee9fa0d360.
Adding the HEAD:HEAD refspec looks like the correct solution.

Suggested-by: hxtmdev on github
(cherry picked from commit 18f3598d57)
This commit is contained in:
Sergei Zimmerman 2025-11-29 05:39:04 +03:00 committed by github-actions[bot]
parent ca5f35fcf7
commit 1d1d553083
2 changed files with 5 additions and 1 deletions

View file

@ -682,7 +682,7 @@ struct GitInputScheme : InputScheme
auto fetchRef = getAllRefsAttr(input) ? "refs/*:refs/*" auto fetchRef = getAllRefsAttr(input) ? "refs/*:refs/*"
: input.getRev() ? input.getRev()->gitRev() : input.getRev() ? input.getRev()->gitRev()
: ref.compare(0, 5, "refs/") == 0 ? fmt("%1%:%1%", ref) : ref.compare(0, 5, "refs/") == 0 ? fmt("%1%:%1%", ref)
: ref == "HEAD" ? ref : ref == "HEAD" ? "HEAD:HEAD"
: fmt("%1%:%1%", "refs/heads/" + ref); : fmt("%1%:%1%", "refs/heads/" + ref);
repo->fetch(repoUrl.to_string(), fetchRef, shallow); repo->fetch(repoUrl.to_string(), fetchRef, shallow);

View file

@ -228,6 +228,10 @@ path8=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$rep
rev4=$(git -C "$repo" rev-parse HEAD) rev4=$(git -C "$repo" rev-parse HEAD)
rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).rev") rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).rev")
[[ $rev4 = "$rev4_nix" ]] [[ $rev4 = "$rev4_nix" ]]
export _NIX_FORCE_HTTP=1
rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).rev")
[[ $rev4 = "$rev4_nix" ]]
unset _NIX_FORCE_HTTP
# The name argument should be handled # The name argument should be handled
path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath") path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath")