Skip to content

Commit be92b18

Browse files
authored
Merge pull request #14083 from fzakaria/fzakaria/shellcheck-multiple-2
shellcheck fixes
2 parents b5f765b + 2a67242 commit be92b18

File tree

14 files changed

+295
-292
lines changed

14 files changed

+295
-292
lines changed

maintainers/flake-module.nix

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@
106106
enable = true;
107107
excludes = [
108108
# We haven't linted these files yet
109-
''^tests/functional/dump-db\.sh$''
110-
''^tests/functional/fetchGitSubmodules\.sh$''
111-
''^tests/functional/fetchGitVerification\.sh$''
112-
''^tests/functional/fetchMercurial\.sh$''
113-
''^tests/functional/fixed\.builder1\.sh$''
114-
''^tests/functional/fixed\.builder2\.sh$''
115-
''^tests/functional/fixed\.sh$''
116-
''^tests/functional/flakes/absolute-paths\.sh$''
117-
''^tests/functional/flakes/check\.sh$''
118-
''^tests/functional/flakes/config\.sh$''
119-
''^tests/functional/flakes/flakes\.sh$''
120-
''^tests/functional/flakes/follow-paths\.sh$''
121109
''^tests/functional/flakes/prefetch\.sh$''
122110
''^tests/functional/flakes/run\.sh$''
123111
''^tests/functional/flakes/show\.sh$''
@@ -204,10 +192,6 @@
204192
''^tests/functional/user-envs\.sh$''
205193
''^tests/functional/why-depends\.sh$''
206194

207-
# Shellcheck doesn't support fish or zsh shell syntax
208-
''^misc/fish/completion\.fish$''
209-
''^misc/zsh/completion\.zsh$''
210-
211195
# Content-addressed test files that use recursive-*looking* sourcing
212196
# (cd .. && source <self>), causing shellcheck to loop
213197
# They're small wrapper scripts with not a lot going on

misc/fish/completion.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=all
12
function _nix_complete
23
# Get the current command up to a cursor.
34
# - Behaves correctly even with pipes and nested in commands like env.

misc/zsh/completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=all
12
#compdef nix
23

34
function _nix() {

tests/functional/fetchGitSubmodules.sh

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ clearStoreIfPossible
1111
rootRepo=$TEST_ROOT/gitSubmodulesRoot
1212
subRepo=$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
2323
git config --global protocol.file.allow always
2424

2525
initGitRepo() {
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

3131
addGitContent() {
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

4949
r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath")
5050
r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath")
5151
r3=$(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

5656
r4=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; }).outPath")
5757
r5=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = false; }).outPath")
5858
r6=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath")
5959
r7=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath")
6060
r8=$(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

6868
have_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
8080
pathWithSubmodulesAgainWithRef=$(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
9898
test "$(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)
102102
noSubmoduleRepoBaseline=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$subRepo; rev = \"$subRev\"; }).outPath")
103103
noSubmoduleRepo=$(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
116116
EOF
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

123123
r=$(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)
135135
pathWithRelative=$(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*
140140
cloneRepo=$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"
142142
pathIndirect=$(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
}
237238
test_submodule_nested

tests/functional/fetchGitVerification.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ ssh-keygen -f "$keysDir/testkey2" -t rsa -P "" -C "test key 2"
2121
key2File="$keysDir/testkey2.pub"
2222
publicKey2=$(awk '{print $2}' "$key2File")
2323

24-
git init $repo
25-
git -C $repo config user.email "[email protected]"
26-
git -C $repo config user.name "Foobar"
27-
git -C $repo config gpg.format ssh
24+
git init "$repo"
25+
git -C "$repo" config user.email "[email protected]"
26+
git -C "$repo" config user.name "Foobar"
27+
git -C "$repo" config gpg.format ssh
2828

29-
echo 'hello' > $repo/text
30-
git -C $repo add text
31-
git -C $repo -c "user.signingkey=$key1File" commit -S -m 'initial commit'
29+
echo 'hello' > "$repo"/text
30+
git -C "$repo" add text
31+
git -C "$repo" -c "user.signingkey=$key1File" commit -S -m 'initial commit'
3232

3333
out=$(nix eval --impure --raw --expr "builtins.fetchGit { url = \"file://$repo\"; keytype = \"ssh-rsa\"; publicKey = \"$publicKey2\"; }" 2>&1) || status=$?
3434
[[ $status == 1 ]]
35-
[[ $out =~ 'No principal matched.' ]]
35+
[[ $out == *'No principal matched.'* ]]
3636
[[ $(nix eval --impure --raw --expr "builtins.readFile (builtins.fetchGit { url = \"file://$repo\"; publicKey = \"$publicKey1\"; } + \"/text\")") = 'hello' ]]
3737

38-
echo 'hello world' > $repo/text
38+
echo 'hello world' > "$repo"/text
3939

4040
# Verification on a dirty repo should fail.
4141
out=$(nix eval --impure --raw --expr "builtins.fetchGit { url = \"file://$repo\"; keytype = \"ssh-rsa\"; publicKey = \"$publicKey2\"; }" 2>&1) || status=$?
4242
[[ $status == 1 ]]
4343
[[ $out =~ 'dirty' ]]
4444

45-
git -C $repo add text
46-
git -C $repo -c "user.signingkey=$key2File" commit -S -m 'second commit'
45+
git -C "$repo" add text
46+
git -C "$repo" -c "user.signingkey=$key2File" commit -S -m 'second commit'
4747

4848
[[ $(nix eval --impure --raw --expr "builtins.readFile (builtins.fetchGit { url = \"file://$repo\"; publicKeys = [{key = \"$publicKey1\";} {type = \"ssh-rsa\"; key = \"$publicKey2\";}]; } + \"/text\")") = 'hello world' ]]
4949

@@ -80,5 +80,6 @@ cat > "$flakeDir/flake.nix" <<EOF
8080
}
8181
EOF
8282
out=$(nix build "$flakeDir#test" 2>&1) || status=$?
83+
8384
[[ $status == 1 ]]
84-
[[ $out =~ 'No principal matched.' ]]
85+
[[ $out == *'No principal matched.'* ]]

0 commit comments

Comments
 (0)