@@ -11,7 +11,7 @@ clearStoreIfPossible
1111rootRepo=$TEST_ROOT /gitSubmodulesRoot
1212subRepo=$TEST_ROOT /gitSubmodulesSub
1313
14- rm -rf ${rootRepo} ${subRepo} $TEST_HOME /.cache/nix
14+ rm -rf " ${rootRepo} " " ${subRepo} " " $TEST_HOME " /.cache/nix
1515
1616# Submodules can't be fetched locally by default, which can cause
1717# information leakage vulnerabilities, but for these tests our
@@ -23,47 +23,47 @@ export XDG_CONFIG_HOME=$TEST_HOME/.config
2323git config --global protocol.file.allow always
2424
2525initGitRepo () {
26- git init $1
27- git -C
$1 config user.email
" [email protected] " 28- git -C $1 config user.name " Foobar"
26+ git init " $1 "
27+ git -C
" $1 " config user.email
" [email protected] " 28+ git -C " $1 " config user.name " Foobar"
2929}
3030
3131addGitContent () {
32- echo " lorem ipsum" > $1 /content
33- git -C $1 add content
34- git -C $1 commit -m " Initial commit"
32+ echo " lorem ipsum" > " $1 " /content
33+ git -C " $1 " add content
34+ git -C " $1 " commit -m " Initial commit"
3535}
3636
37- initGitRepo $subRepo
38- addGitContent $subRepo
37+ initGitRepo " $subRepo "
38+ addGitContent " $subRepo "
3939
40- initGitRepo $rootRepo
40+ initGitRepo " $rootRepo "
4141
42- git -C $rootRepo submodule init
43- git -C $rootRepo submodule add $subRepo sub
44- git -C $rootRepo add sub
45- git -C $rootRepo commit -m " Add submodule"
42+ git -C " $rootRepo " submodule init
43+ git -C " $rootRepo " submodule add " $subRepo " sub
44+ git -C " $rootRepo " add sub
45+ git -C " $rootRepo " commit -m " Add submodule"
4646
47- rev=$( git -C $rootRepo rev-parse HEAD)
47+ rev=$( git -C " $rootRepo " rev-parse HEAD)
4848
4949r1=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; rev = \" $rev \" ; }).outPath" )
5050r2=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; rev = \" $rev \" ; submodules = false; }).outPath" )
5151r3=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; rev = \" $rev \" ; submodules = true; }).outPath" )
5252
53- [[ $r1 == $r2 ]]
54- [[ $r2 != $r3 ]]
53+ [[ $r1 == " $r2 " ]]
54+ [[ $r2 != " $r3 " ]]
5555
5656r4=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; ref = \" master\" ; rev = \" $rev \" ; }).outPath" )
5757r5=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; ref = \" master\" ; rev = \" $rev \" ; submodules = false; }).outPath" )
5858r6=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; ref = \" master\" ; rev = \" $rev \" ; submodules = true; }).outPath" )
5959r7=$( nix eval --raw --expr " (builtins.fetchGit { url = $rootRepo ; ref = \" master\" ; rev = \" $rev \" ; submodules = true; }).outPath" )
6060r8=$( nix eval --raw --expr " (builtins.fetchGit { url = $rootRepo ; rev = \" $rev \" ; submodules = true; }).outPath" )
6161
62- [[ $r1 == $r4 ]]
63- [[ $r4 == $r5 ]]
64- [[ $r3 == $r6 ]]
65- [[ $r6 == $r7 ]]
66- [[ $r7 == $r8 ]]
62+ [[ $r1 == " $r4 " ]]
63+ [[ $r4 == " $r5 " ]]
64+ [[ $r3 == " $r6 " ]]
65+ [[ $r6 == " $r7 " ]]
66+ [[ $r7 == " $r8 " ]]
6767
6868have_submodules=$( nix eval --expr " (builtins.fetchGit { url = $rootRepo ; rev = \" $rev \" ; }).submodules" )
6969[[ $have_submodules == false ]]
@@ -80,13 +80,13 @@ pathWithSubmodulesAgain=$(nix eval --raw --expr "(builtins.fetchGit { url = file
8080pathWithSubmodulesAgainWithRef=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; ref = \" master\" ; rev = \" $rev \" ; submodules = true; }).outPath" )
8181
8282# The resulting store path cannot be the same.
83- [[ $pathWithoutSubmodules != $pathWithSubmodules ]]
83+ [[ $pathWithoutSubmodules != " $pathWithSubmodules " ]]
8484
8585# Checking out the same repo with submodules returns in the same store path.
86- [[ $pathWithSubmodules == $pathWithSubmodulesAgain ]]
86+ [[ $pathWithSubmodules == " $pathWithSubmodulesAgain " ]]
8787
8888# Checking out the same repo with submodules returns in the same store path.
89- [[ $pathWithSubmodulesAgain == $pathWithSubmodulesAgainWithRef ]]
89+ [[ $pathWithSubmodulesAgain == " $pathWithSubmodulesAgainWithRef " ]]
9090
9191# The submodules flag is actually honored.
9292[[ ! -e $pathWithoutSubmodules /sub/content ]]
@@ -98,14 +98,14 @@ pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url
9898test " $( find " $pathWithSubmodules " -name .git) " = " "
9999
100100# Git repos without submodules can be fetched with submodules = true.
101- subRev=$( git -C $subRepo rev-parse HEAD)
101+ subRev=$( git -C " $subRepo " rev-parse HEAD)
102102noSubmoduleRepoBaseline=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$subRepo ; rev = \" $subRev \" ; }).outPath" )
103103noSubmoduleRepo=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$subRepo ; rev = \" $subRev \" ; submodules = true; }).outPath" )
104104
105- [[ $noSubmoduleRepoBaseline == $noSubmoduleRepo ]]
105+ [[ $noSubmoduleRepoBaseline == " $noSubmoduleRepo " ]]
106106
107107# Test .gitmodules with entries that refer to non-existent objects or objects that are not submodules.
108- cat >> $rootRepo /.gitmodules << EOF
108+ cat >> " $rootRepo " /.gitmodules << EOF
109109[submodule "missing"]
110110 path = missing
111111 url = https://example.org/missing.git
@@ -114,56 +114,56 @@ cat >> $rootRepo/.gitmodules <<EOF
114114 path = file
115115 url = https://example.org/file.git
116116EOF
117- echo foo > $rootRepo /file
118- git -C $rootRepo add file
119- git -C $rootRepo commit -a -m " Add bad submodules"
117+ echo foo > " $rootRepo " /file
118+ git -C " $rootRepo " add file
119+ git -C " $rootRepo " commit -a -m " Add bad submodules"
120120
121- rev=$( git -C $rootRepo rev-parse HEAD)
121+ rev=$( git -C " $rootRepo " rev-parse HEAD)
122122
123123r=$( nix eval --raw --expr " builtins.fetchGit { url = file://$rootRepo ; rev = \" $rev \" ; submodules = true; }" )
124124
125125[[ -f $r /file ]]
126126[[ ! -e $r /missing ]]
127127
128128# Test relative submodule URLs.
129- rm $TEST_HOME /.cache/nix/fetcher-cache*
130- rm -rf $rootRepo /.git $rootRepo /.gitmodules $rootRepo /sub
131- initGitRepo $rootRepo
132- git -C $rootRepo submodule add ../gitSubmodulesSub sub
133- git -C $rootRepo commit -m " Add submodule"
134- rev2=$( git -C $rootRepo rev-parse HEAD)
129+ rm " $TEST_HOME " /.cache/nix/fetcher-cache*
130+ rm -rf " $rootRepo " /.git " $rootRepo " /.gitmodules " $rootRepo " /sub
131+ initGitRepo " $rootRepo "
132+ git -C " $rootRepo " submodule add ../gitSubmodulesSub sub
133+ git -C " $rootRepo " commit -m " Add submodule"
134+ rev2=$( git -C " $rootRepo " rev-parse HEAD)
135135pathWithRelative=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$rootRepo ; rev = \" $rev2 \" ; submodules = true; }).outPath" )
136- diff -r -x .gitmodules $pathWithSubmodules $pathWithRelative
136+ diff -r -x .gitmodules " $pathWithSubmodules " " $pathWithRelative "
137137
138138# Test clones that have an upstream with relative submodule URLs.
139- rm $TEST_HOME /.cache/nix/fetcher-cache*
139+ rm " $TEST_HOME " /.cache/nix/fetcher-cache*
140140cloneRepo=$TEST_ROOT /a/b/gitSubmodulesClone # NB /a/b to make the relative path not work relative to $cloneRepo
141- git clone $rootRepo $cloneRepo
141+ git clone " $rootRepo " " $cloneRepo "
142142pathIndirect=$( nix eval --raw --expr " (builtins.fetchGit { url = file://$cloneRepo ; rev = \" $rev2 \" ; submodules = true; }).outPath" )
143- [[ $pathIndirect = $pathWithRelative ]]
143+ [[ $pathIndirect = " $pathWithRelative " ]]
144144
145145# Test submodule export-ignore interaction
146- git -C
$rootRepo /sub config user.email
" [email protected] " 147- git -C $rootRepo /sub config user.name " Foobar"
146+ git -C
" $rootRepo " /sub config user.email
" [email protected] " 147+ git -C " $rootRepo " /sub config user.name " Foobar"
148148
149- echo " /exclude-from-root export-ignore" >> $rootRepo /.gitattributes
149+ echo " /exclude-from-root export-ignore" >> " $rootRepo " /.gitattributes
150150# TBD possible semantics for submodules + exportIgnore
151151# echo "/sub/exclude-deep export-ignore" >> $rootRepo/.gitattributes
152- echo nope > $rootRepo /exclude-from-root
153- git -C $rootRepo add .gitattributes exclude-from-root
154- git -C $rootRepo commit -m " Add export-ignore"
152+ echo nope > " $rootRepo " /exclude-from-root
153+ git -C " $rootRepo " add .gitattributes exclude-from-root
154+ git -C " $rootRepo " commit -m " Add export-ignore"
155155
156- echo " /exclude-from-sub export-ignore" >> $rootRepo /sub/.gitattributes
157- echo nope > $rootRepo /sub/exclude-from-sub
156+ echo " /exclude-from-sub export-ignore" >> " $rootRepo " /sub/.gitattributes
157+ echo nope > " $rootRepo " /sub/exclude-from-sub
158158# TBD possible semantics for submodules + exportIgnore
159159# echo aye > $rootRepo/sub/exclude-from-root
160- git -C $rootRepo /sub add .gitattributes exclude-from-sub
161- git -C $rootRepo /sub commit -m " Add export-ignore (sub)"
160+ git -C " $rootRepo " /sub add .gitattributes exclude-from-sub
161+ git -C " $rootRepo " /sub commit -m " Add export-ignore (sub)"
162162
163- git -C $rootRepo add sub
164- git -C $rootRepo commit -m " Update submodule"
163+ git -C " $rootRepo " add sub
164+ git -C " $rootRepo " commit -m " Update submodule"
165165
166- git -C $rootRepo status
166+ git -C " $rootRepo " status
167167
168168# # TBD: not supported yet, because semantics are undecided and current implementation leaks rules from the root to submodules
169169# # exportIgnore can be used with submodules
@@ -199,39 +199,40 @@ test_submodule_nested() {
199199 local repoB=$TEST_ROOT /submodule_nested/b
200200 local repoC=$TEST_ROOT /submodule_nested/c
201201
202- rm -rf $repoA $repoB $repoC $TEST_HOME /.cache/nix
202+ rm -rf " $repoA " " $repoB " " $repoC " " $TEST_HOME " /.cache/nix
203203
204- initGitRepo $repoC
205- touch $repoC /inside-c
206- git -C $repoC add inside-c
207- addGitContent $repoC
204+ initGitRepo " $repoC "
205+ touch " $repoC " /inside-c
206+ git -C " $repoC " add inside-c
207+ addGitContent " $repoC "
208208
209- initGitRepo $repoB
210- git -C $repoB submodule add $repoC c
211- git -C $repoB add c
212- addGitContent $repoB
209+ initGitRepo " $repoB "
210+ git -C " $repoB " submodule add " $repoC " c
211+ git -C " $repoB " add c
212+ addGitContent " $repoB "
213213
214- initGitRepo $repoA
215- git -C $repoA submodule add $repoB b
216- git -C $repoA add b
217- addGitContent $repoA
214+ initGitRepo " $repoA "
215+ git -C " $repoA " submodule add " $repoB " b
216+ git -C " $repoA " add b
217+ addGitContent " $repoA "
218218
219219
220220 # Check non-worktree fetch
221- local rev=$( git -C $repoA rev-parse HEAD)
221+ local rev
222+ rev=$( git -C " $repoA " rev-parse HEAD)
222223 out=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repoA \" ; rev = \" $rev \" ; submodules = true; }).outPath" )
223- test -e $out /b/c/inside-c
224- test -e $out /content
225- test -e $out /b/content
226- test -e $out /b/c/content
224+ test -e " $out " /b/c/inside-c
225+ test -e " $out " /content
226+ test -e " $out " /b/content
227+ test -e " $out " /b/c/content
227228 local nonWorktree=$out
228229
229230 # Check worktree based fetch
230231 # TODO: make it work without git submodule update
231- git -C $repoA submodule update --init --recursive
232+ git -C " $repoA " submodule update --init --recursive
232233 out=$( nix eval --impure --raw --expr " (builtins.fetchGit { url = \" file://$repoA \" ; submodules = true; }).outPath" )
233- find $out
234- [[ $out == $nonWorktree ]] || { find $out ; false ; }
234+ find " $out "
235+ [[ $out == " $nonWorktree " ]] || { find " $out " ; false ; }
235236
236237}
237238test_submodule_nested
0 commit comments