@@ -12,25 +12,25 @@ repo=$TEST_ROOT/./git
1212
1313export _NIX_FORCE_HTTP=1
1414
15- rm -rf $repo ${repo} -tmp $TEST_HOME /.cache/nix $TEST_ROOT /worktree $TEST_ROOT /minimal
16-
17- git init $repo
18- git -C
$repo config user.email
" [email protected] " 19- git -C $repo config user.name " Foobar"
20-
21- echo utrecht > $repo /hello
22- touch $repo /.gitignore
23- git -C $repo add hello .gitignore
24- git -C $repo commit -m ' Bla1'
25- rev1=$( git -C $repo rev-parse HEAD)
26- git -C $repo tag -a tag1 -m tag1
27-
28- echo world > $repo /hello
29- git -C $repo commit -m ' Bla2' -a
30- git -C $repo worktree add $TEST_ROOT /worktree
31- echo hello >> $TEST_ROOT /worktree/hello
32- rev2=$( git -C $repo rev-parse HEAD)
33- git -C $repo tag -a tag2 -m tag2
15+ rm -rf " $repo " " ${repo} " -tmp " $TEST_HOME " /.cache/nix " $TEST_ROOT " /worktree " $TEST_ROOT " /minimal
16+
17+ git init " $repo "
18+ git -C
" $repo " config user.email
" [email protected] " 19+ git -C " $repo " config user.name " Foobar"
20+
21+ echo utrecht > " $repo " /hello
22+ touch " $repo " /.gitignore
23+ git -C " $repo " add hello .gitignore
24+ git -C " $repo " commit -m ' Bla1'
25+ rev1=$( git -C " $repo " rev-parse HEAD)
26+ git -C " $repo " tag -a tag1 -m tag1
27+
28+ echo world > " $repo " /hello
29+ git -C " $repo " commit -m ' Bla2' -a
30+ git -C " $repo " worktree add " $TEST_ROOT " /worktree
31+ echo hello >> " $TEST_ROOT " /worktree/hello
32+ rev2=$( git -C " $repo " rev-parse HEAD)
33+ git -C " $repo " tag -a tag2 -m tag2
3434
3535# Check whether fetching in read-only mode works.
3636nix-instantiate --eval -E " builtins.readFile ((builtins.fetchGit file://$TEST_ROOT /worktree) + \" /hello\" ) == \" utrecht\\ n\" "
@@ -40,52 +40,52 @@ unset _NIX_FORCE_HTTP
4040expectStderr 0 nix eval -vvvv --impure --raw --expr " (builtins.fetchGit file://$TEST_ROOT /worktree).outPath" | grepQuiet " copying '$TEST_ROOT /worktree/' to the store"
4141path0=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$TEST_ROOT /worktree).outPath" )
4242path0_=$( nix eval --impure --raw --expr " (builtins.fetchTree { type = \" git\" ; url = file://$TEST_ROOT /worktree; }).outPath" )
43- [[ $path0 = $path0_ ]]
43+ [[ $path0 = " $path0_ " ]]
4444path0_=$( nix eval --impure --raw --expr " (builtins.fetchTree git+file://$TEST_ROOT /worktree).outPath" )
45- [[ $path0 = $path0_ ]]
45+ [[ $path0 = " $path0_ " ]]
4646export _NIX_FORCE_HTTP=1
47- [[ $( tail -n 1 $path0 /hello) = " hello" ]]
47+ [[ $( tail -n 1 " $path0 " /hello) = " hello" ]]
4848
4949# Nuke the cache
50- rm -rf $TEST_HOME /.cache/nix
50+ rm -rf " $TEST_HOME " /.cache/nix
5151
5252# Fetch the default branch.
5353path=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
54- [[ $( cat $path /hello) = world ]]
54+ [[ $( cat " $path " /hello) = world ]]
5555
5656# Fetch again. This should be cached.
5757# NOTE: This has to be done before the test case below which tries to pack-refs
5858# the reason being that the lookup on the cache uses the ref-file `/refs/heads/master`
5959# which does not exist after packing.
60- mv $repo ${repo} -tmp
60+ mv " $repo " " ${repo} " -tmp
6161path2=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
62- [[ $path = $path2 ]]
62+ [[ $path = " $path2 " ]]
6363
6464[[ $( nix eval --impure --expr " (builtins.fetchGit file://$repo ).revCount" ) = 2 ]]
65- [[ $( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).rev" ) = $rev2 ]]
66- [[ $( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).shortRev" ) = ${rev2: 0: 7} ]]
65+ [[ $( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).rev" ) = " $rev2 " ]]
66+ [[ $( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).shortRev" ) = " ${rev2: 0: 7} " ]]
6767
6868# Fetching with a explicit hash should succeed.
6969path2=$( nix eval --refresh --raw --expr " (builtins.fetchGit { url = file://$repo ; rev = \" $rev2 \" ; }).outPath" )
70- [[ $path = $path2 ]]
70+ [[ $path = " $path2 " ]]
7171
7272path2=$( nix eval --refresh --raw --expr " (builtins.fetchGit { url = file://$repo ; rev = \" $rev1 \" ; }).outPath" )
73- [[ $( cat $path2 /hello) = utrecht ]]
73+ [[ $( cat " $path2 " /hello) = utrecht ]]
7474
75- mv ${repo} -tmp $repo
75+ mv " ${repo} " -tmp " $repo "
7676
7777# Fetch when the cache has packed-refs
7878# Regression test of #8822
79- git -C $TEST_HOME /.cache/nix/gitv3/* / pack-refs --all
79+ git -C " $TEST_HOME " /.cache/nix/gitv3/* / pack-refs --all
8080path=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
8181
8282# Fetch a rev from another branch
83- git -C $repo checkout -b devtest
84- echo " different file" >> $TEST_ROOT /git/differentbranch
85- git -C $repo add differentbranch
86- git -C $repo commit -m ' Test2'
87- git -C $repo checkout master
88- devrev=$( git -C $repo rev-parse devtest)
83+ git -C " $repo " checkout -b devtest
84+ echo " different file" >> " $TEST_ROOT " /git/differentbranch
85+ git -C " $repo " add differentbranch
86+ git -C " $repo " commit -m ' Test2'
87+ git -C " $repo " checkout master
88+ devrev=$( git -C " $repo " rev-parse devtest)
8989nix eval --raw --expr " builtins.fetchGit { url = file://$repo ; rev = \" $devrev \" ; }"
9090
9191[[ $( nix eval --raw --expr " builtins.readFile (builtins.fetchGit { url = file://$repo ; rev = \" $devrev \" ; allRefs = true; } + \" /differentbranch\" )" ) = ' different file' ]]
@@ -96,7 +96,7 @@ nix eval --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"
9696
9797# Fetch using an explicit revision hash.
9898path2=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$repo ; rev = \" $rev2 \" ; }).outPath" )
99- [[ $path = $path2 ]]
99+ [[ $path = " $path2 " ]]
100100
101101# In pure eval mode, fetchGit with a revision should succeed.
102102[[ $( nix eval --raw --expr " builtins.readFile (fetchGit { url = file://$repo ; rev = \" $rev2 \" ; } + \" /hello\" )" ) = world ]]
@@ -106,40 +106,40 @@ expectStderr 1 nix eval --expr 'builtins.fetchGit "file:///foo"' | grepQuiet "'f
106106
107107# Using a clean working tree should produce the same result.
108108path2=$( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).outPath" )
109- [[ $path = $path2 ]]
109+ [[ $path = " $path2 " ]]
110110
111111# Using an unclean tree should yield the tracked but uncommitted changes.
112- mkdir $repo /dir1 $repo /dir2
113- echo foo > $repo /dir1/foo
114- echo bar > $repo /bar
115- echo bar > $repo /dir2/bar
116- git -C $repo add dir1/foo
117- git -C $repo rm hello
112+ mkdir " $repo " /dir1 " $repo " /dir2
113+ echo foo > " $repo " /dir1/foo
114+ echo bar > " $repo " /bar
115+ echo bar > " $repo " /dir2/bar
116+ git -C " $repo " add dir1/foo
117+ git -C " $repo " rm hello
118118
119119unset _NIX_FORCE_HTTP
120120path2=$( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).outPath" )
121- [ ! -e $path2 /hello ]
122- [ ! -e $path2 /bar ]
123- [ ! -e $path2 /dir2/bar ]
124- [ ! -e $path2 /.git ]
125- [[ $( cat $path2 /dir1/foo) = foo ]]
121+ [ ! -e " $path2 " /hello ]
122+ [ ! -e " $path2 " /bar ]
123+ [ ! -e " $path2 " /dir2/bar ]
124+ [ ! -e " $path2 " /.git ]
125+ [[ $( cat " $path2 " /dir1/foo) = foo ]]
126126
127127[[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).rev" ) = 0000000000000000000000000000000000000000 ]]
128128[[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).dirtyRev" ) = " ${rev2} -dirty" ]]
129129[[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).dirtyShortRev" ) = " ${rev2: 0: 7} -dirty" ]]
130130
131131# ... unless we're using an explicit ref or rev.
132132path3=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = $repo ; ref = \" master\" ; }).outPath" )
133- [[ $path = $path3 ]]
133+ [[ $path = " $path3 " ]]
134134
135135path3=$( nix eval --raw --expr " (builtins.fetchGit { url = $repo ; rev = \" $rev2 \" ; }).outPath" )
136- [[ $path = $path3 ]]
136+ [[ $path = " $path3 " ]]
137137
138138# Committing should not affect the store path.
139- git -C $repo commit -m ' Bla3' -a
139+ git -C " $repo " commit -m ' Bla3' -a
140140
141141path4=$( nix eval --impure --refresh --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
142- [[ $path2 = $path4 ]]
142+ [[ $path2 = " $path4 " ]]
143143
144144[[ $( nix eval --impure --expr " builtins.hasAttr \" rev\" (builtins.fetchGit $repo )" ) == " true" ]]
145145[[ $( nix eval --impure --expr " builtins.hasAttr \" dirtyRev\" (builtins.fetchGit $repo )" ) == " false" ]]
@@ -148,7 +148,7 @@ path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchGit file://$rep
148148expect 102 nix eval --raw --expr " (builtins.fetchGit { url = $repo ; rev = \" $rev2 \" ; narHash = \" sha256-B5yIPHhEm0eysJKEsO7nqxprh9vcblFxpJG11gXJus1=\" ; }).outPath"
149149
150150path5=$( nix eval --raw --expr " (builtins.fetchGit { url = $repo ; rev = \" $rev2 \" ; narHash = \" sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\" ; }).outPath" )
151- [[ $path = $path5 ]]
151+ [[ $path = " $path5 " ]]
152152
153153# Ensure that NAR hashes are checked.
154154expectStderr 102 nix eval --raw --expr " (builtins.fetchGit { url = $repo ; rev = \" $rev2 \" ; narHash = \" sha256-Hr8g6AqANb4xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\" ; }).outPath" | grepQuiet " error: NAR hash mismatch"
@@ -157,22 +157,22 @@ expectStderr 102 nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev =
157157expectStderr 0 nix eval --raw --expr " (builtins.fetchGit { url = $repo ; ref = \" tag2\" ; narHash = \" sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\" ; }).outPath" | grepQuiet " warning: Input .* is unlocked"
158158
159159# tarball-ttl should be ignored if we specify a rev
160- echo delft > $repo /hello
161- git -C $repo add hello
162- git -C $repo commit -m ' Bla4'
163- rev3=$( git -C $repo rev-parse HEAD)
160+ echo delft > " $repo " /hello
161+ git -C " $repo " add hello
162+ git -C " $repo " commit -m ' Bla4'
163+ rev3=$( git -C " $repo " rev-parse HEAD)
164164nix eval --tarball-ttl 3600 --expr " builtins.fetchGit { url = $repo ; rev = \" $rev3 \" ; }" > /dev/null
165165
166166# Update 'path' to reflect latest master
167167path=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
168168
169169# Check behavior when non-master branch is used
170- git -C $repo checkout $rev2 -b dev
171- echo dev > $repo /hello
170+ git -C " $repo " checkout " $rev2 " -b dev
171+ echo dev > " $repo " /hello
172172
173173# File URI uses dirty tree unless specified otherwise
174174path2=$( nix eval --impure --raw --expr " (builtins.fetchGit file://$repo ).outPath" )
175- [ $( cat $path2 /hello) = dev ]
175+ [ " $( cat " $path2 " /hello) " = dev ]
176176
177177# Using local path with branch other than 'master' should work when clean or dirty
178178path3=$( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).outPath" )
@@ -181,53 +181,53 @@ path3=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
181181[[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).shortRev" ) = 0000000 ]]
182182# Making a dirty tree clean again and fetching it should
183183# record correct revision information. See: #4140
184- echo world > $repo /hello
185- [[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).rev" ) = $rev2 ]]
184+ echo world > " $repo " /hello
185+ [[ $( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).rev" ) = " $rev2 " ]]
186186
187187# Committing shouldn't change store path, or switch to using 'master'
188- echo dev > $repo /hello
189- git -C $repo commit -m ' Bla5' -a
188+ echo dev > " $repo " /hello
189+ git -C " $repo " commit -m ' Bla5' -a
190190path4=$( nix eval --impure --raw --expr " (builtins.fetchGit $repo ).outPath" )
191- [[ $( cat $path4 /hello) = dev ]]
192- [[ $path3 = $path4 ]]
191+ [[ $( cat " $path4 " /hello) = dev ]]
192+ [[ $path3 = " $path4 " ]]
193193
194194# Using remote path with branch other than 'master' should fetch the HEAD revision.
195195# (--tarball-ttl 0 to prevent using the cached repo above)
196196export _NIX_FORCE_HTTP=1
197197path4=$( nix eval --tarball-ttl 0 --impure --raw --expr " (builtins.fetchGit $repo ).outPath" )
198- [[ $( cat $path4 /hello) = dev ]]
199- [[ $path3 = $path4 ]]
198+ [[ $( cat " $path4 " /hello) = dev ]]
199+ [[ $path3 = " $path4 " ]]
200200unset _NIX_FORCE_HTTP
201201
202202# Confirm same as 'dev' branch
203203path5=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = $repo ; ref = \" dev\" ; }).outPath" )
204- [[ $path3 = $path5 ]]
204+ [[ $path3 = " $path5 " ]]
205205
206206
207207# Nuke the cache
208- rm -rf $TEST_HOME /.cache/nix
208+ rm -rf " $TEST_HOME " /.cache/nix
209209
210210# Try again. This should work.
211211path5=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = $repo ; ref = \" dev\" ; }).outPath" )
212- [[ $path3 = $path5 ]]
212+ [[ $path3 = " $path5 " ]]
213213
214214# Fetching from a repo with only a specific revision and no branches should
215215# not fall back to copying files and record correct revision information. See: #5302
216- mkdir $TEST_ROOT /minimal
217- git -C $TEST_ROOT /minimal init
218- git -C $TEST_ROOT /minimal fetch $repo $rev2
219- git -C $TEST_ROOT /minimal checkout $rev2
220- [[ $( nix eval --impure --raw --expr " (builtins.fetchGit { url = $TEST_ROOT /minimal; }).rev" ) = $rev2 ]]
216+ mkdir " $TEST_ROOT " /minimal
217+ git -C " $TEST_ROOT " /minimal init
218+ git -C " $TEST_ROOT " /minimal fetch " $repo " " $rev2 "
219+ git -C " $TEST_ROOT " /minimal checkout " $rev2 "
220+ [[ $( nix eval --impure --raw --expr " (builtins.fetchGit { url = $TEST_ROOT /minimal; }).rev" ) = " $rev2 " ]]
221221
222222# Explicit ref = "HEAD" should work, and produce the same outPath as without ref
223223path7=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; ref = \" HEAD\" ; }).outPath" )
224224path8=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; }).outPath" )
225- [[ $path7 = $path8 ]]
225+ [[ $path7 = " $path8 " ]]
226226
227227# ref = "HEAD" should fetch the HEAD revision
228- rev4=$( git -C $repo rev-parse HEAD)
228+ rev4=$( git -C " $repo " rev-parse HEAD)
229229rev4_nix=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; ref = \" HEAD\" ; }).rev" )
230- [[ $rev4 = $rev4_nix ]]
230+ [[ $rev4 = " $rev4_nix " ]]
231231
232232# The name argument should be handled
233233path9=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; ref = \" HEAD\" ; name = \" foo\" ; }).outPath" )
@@ -236,33 +236,36 @@ path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$rep
236236# Specifying a ref without a rev shouldn't pick a cached rev for a different ref
237237export _NIX_FORCE_HTTP=1
238238rev_tag1_nix=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; ref = \" refs/tags/tag1\" ; }).rev" )
239- rev_tag1=$( git -C $repo rev-parse refs/tags/tag1^{commit})
240- [[ $rev_tag1_nix = $rev_tag1 ]]
239+ # shellcheck disable=SC1083
240+ rev_tag1=$( git -C " $repo " rev-parse refs/tags/tag1^{commit})
241+ [[ $rev_tag1_nix = " $rev_tag1 " ]]
241242rev_tag2_nix=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repo \" ; ref = \" refs/tags/tag2\" ; }).rev" )
242- rev_tag2=$( git -C $repo rev-parse refs/tags/tag2^{commit})
243- [[ $rev_tag2_nix = $rev_tag2 ]]
243+ # shellcheck disable=SC1083
244+ rev_tag2=$( git -C " $repo " rev-parse refs/tags/tag2^{commit})
245+ [[ $rev_tag2_nix = " $rev_tag2 " ]]
244246unset _NIX_FORCE_HTTP
245247
246248# Ensure .gitattributes is respected
247- touch $repo /not-exported-file
248- touch $repo /exported-wonky
249- echo " /not-exported-file export-ignore" >> $repo /.gitattributes
250- echo " /exported-wonky export-ignore=wonk" >> $repo /.gitattributes
251- git -C $repo add not-exported-file exported-wonky .gitattributes
252- git -C $repo commit -m ' Bla6'
253- rev5=$( git -C $repo rev-parse HEAD)
249+ touch " $repo " /not-exported-file
250+ touch " $repo " /exported-wonky
251+ echo " /not-exported-file export-ignore" >> " $repo " /.gitattributes
252+ echo " /exported-wonky export-ignore=wonk" >> " $repo " /.gitattributes
253+ git -C " $repo " add not-exported-file exported-wonky .gitattributes
254+ git -C " $repo " commit -m ' Bla6'
255+ rev5=$( git -C " $repo " rev-parse HEAD)
254256path12=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$repo ; rev = \" $rev5 \" ; }).outPath" )
255257[[ ! -e $path12 /not-exported-file ]]
256258[[ -e $path12 /exported-wonky ]]
257259
258260# should fail if there is no repo
259- rm -rf $repo /.git
260- rm -rf $TEST_HOME /.cache/nix
261+ rm -rf " $repo " /.git
262+ rm -rf " $TEST_HOME " /.cache/nix
261263(! nix eval --impure --raw --expr " (builtins.fetchGit \" file://$repo \" ).outPath" )
262264
263265# should succeed for a repo without commits
264- git init $repo
265- git -C $repo add hello # need to add at least one file to cause the root of the repo to be visible
266+ git init " $repo "
267+ git -C " $repo " add hello # need to add at least one file to cause the root of the repo to be visible
268+ # shellcheck disable=SC2034
266269path10=$( nix eval --impure --raw --expr " (builtins.fetchGit \" file://$repo \" ).outPath" )
267270
268271# should succeed for a path with a space
@@ -277,6 +280,7 @@ touch "$repo/.gitignore"
277280git -C " $repo " add hello .gitignore
278281git -C " $repo " commit -m ' Bla1'
279282cd " $repo "
283+ # shellcheck disable=SC2034
280284path11=$( nix eval --impure --raw --expr " (builtins.fetchGit ./.).outPath" )
281285
282286# Test a workdir with no commits.
0 commit comments