@@ -14,8 +14,9 @@ git -C "$TEST_ROOT/shallow-parent" config user.email "foobar@example.com"
1414git -C " $TEST_ROOT /shallow-parent" config user.name " Foobar"
1515
1616# Add several commits to have history
17- echo " first" > " $TEST_ROOT /shallow-parent/file.txt"
18- git -C " $TEST_ROOT /shallow-parent" add file.txt
17+ echo " { outputs = _: {}; }" > " $TEST_ROOT /shallow-parent/flake.nix"
18+ echo " " > " $TEST_ROOT /shallow-parent/file.txt"
19+ git -C " $TEST_ROOT /shallow-parent" add file.txt flake.nix
1920git -C " $TEST_ROOT /shallow-parent" commit -m " First commit"
2021
2122echo " second" > " $TEST_ROOT /shallow-parent/file.txt"
@@ -52,16 +53,23 @@ expectStderr 1 nix eval --expr 'builtins.fetchTree { type = "git"; url = "file:/
5253git -C " $TEST_ROOT /shallow-clone" worktree add " $TEST_ROOT /shallow-worktree"
5354
5455# Prior to the fix, this would error out because of the shallow clone's
55- # inability to find parent commits. Now it should return a partial revCount.
56- revCount=$( nix eval --impure --expr " (builtins.fetchGit { url = \" file://$TEST_ROOT /shallow-worktree\" ; }).revCount" )
57-
58- # Verify we got a valid revCount (will be 1 since it's a depth=1 clone)
59- [[ " ${revCount} " -eq 1 ]]
60-
61- # Also verify that we can get the revCount with fetchTree
62- revCount=$( nix eval --impure --expr " (builtins.fetchTree { type = \" git\" ; url = \" file://$TEST_ROOT /shallow-worktree\" ; }).revCount" )
63- [[ " ${revCount} " -eq 1 ]]
64-
65- # Verify that we can get other attributes too
66- rev=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$TEST_ROOT /shallow-worktree\" ; }).rev" )
67- [[ " ${rev} " != " 0000000000000000000000000000000000000000" ]]
56+ # inability to find parent commits. Now it should return an error.
57+ if nix eval --impure --expr " (builtins.fetchGit { url = \" file://$TEST_ROOT /shallow-worktree\" ; }).revCount" 2> /dev/null; then
58+ echo " fetchGit unexpectedly succeeded on shallow clone" >&2
59+ exit 1
60+ fi
61+
62+ # Also verify that fetchTree fails similarly
63+ if nix eval --impure --expr " (builtins.fetchTree { type = \" git\" ; url = \" file://$TEST_ROOT /shallow-worktree\" ; }).revCount" 2> /dev/null; then
64+ echo " fetchTree unexpectedly succeeded on shallow clone" >&2
65+ exit 1
66+ fi
67+
68+ # Verify that we can shallow fetch the worktree
69+ git -C " $TEST_ROOT /shallow-worktree" rev-list --count HEAD > /dev/null
70+ nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$TEST_ROOT /shallow-worktree\" ; shallow = true; }).rev"
71+
72+ # Normal flake operation work because they use shallow by default
73+ pushd " $TEST_ROOT /shallow-worktree"
74+ nix flake metadata
75+ popd
0 commit comments