Skip to content

Commit c998b38

Browse files
pyokagangitster
authored andcommitted
t5520: prevent field splitting in content comparisons
Many tests in t5520 used the following to test the contents of files: test `cat file` = expected or test $(cat file) = expected These 2 forms, however, will be affected by field splitting and, depending on the value of $IFS, may be split into multiple arguments, making the test fail in mysterious ways. Replace the above 2 forms with: test "$(cat file)" = expected as quoting the command substitution will prevent field splitting. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d45366e commit c998b38

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

t/t5520-pull.sh

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ test_expect_success 'test . as a remote' '
9393
echo updated >file &&
9494
git commit -a -m updated &&
9595
git checkout copy &&
96-
test `cat file` = file &&
96+
test "$(cat file)" = file &&
9797
git pull &&
98-
test `cat file` = updated
98+
test "$(cat file)" = updated
9999
'
100100

101101
test_expect_success 'the default remote . should not break explicit pull' '
@@ -104,9 +104,9 @@ test_expect_success 'the default remote . should not break explicit pull' '
104104
git commit -a -m modified &&
105105
git checkout copy &&
106106
git reset --hard HEAD^ &&
107-
test `cat file` = file &&
107+
test "$(cat file)" = file &&
108108
git pull . second &&
109-
test `cat file` = modified
109+
test "$(cat file)" = modified
110110
'
111111

112112
test_expect_success '--rebase' '
@@ -119,32 +119,32 @@ test_expect_success '--rebase' '
119119
git commit -m "new file" &&
120120
git tag before-rebase &&
121121
git pull --rebase . copy &&
122-
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
123-
test new = $(git show HEAD:file2)
122+
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
123+
test new = "$(git show HEAD:file2)"
124124
'
125125
test_expect_success 'pull.rebase' '
126126
git reset --hard before-rebase &&
127127
test_config pull.rebase true &&
128128
git pull . copy &&
129-
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
130-
test new = $(git show HEAD:file2)
129+
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
130+
test new = "$(git show HEAD:file2)"
131131
'
132132

133133
test_expect_success 'branch.to-rebase.rebase' '
134134
git reset --hard before-rebase &&
135135
test_config branch.to-rebase.rebase true &&
136136
git pull . copy &&
137-
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
138-
test new = $(git show HEAD:file2)
137+
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
138+
test new = "$(git show HEAD:file2)"
139139
'
140140

141141
test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
142142
git reset --hard before-rebase &&
143143
test_config pull.rebase true &&
144144
test_config branch.to-rebase.rebase false &&
145145
git pull . copy &&
146-
test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
147-
test new = $(git show HEAD:file2)
146+
test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
147+
test new = "$(git show HEAD:file2)"
148148
'
149149

150150
# add a feature branch, keep-merge, that is merged into master, so the
@@ -163,33 +163,33 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
163163
git reset --hard before-preserve-rebase &&
164164
test_config pull.rebase false &&
165165
git pull . copy &&
166-
test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
167-
test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
168-
test file3 = $(git show HEAD:file3.t)
166+
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
167+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
168+
test file3 = "$(git show HEAD:file3.t)"
169169
'
170170

171171
test_expect_success 'pull.rebase=true flattens keep-merge' '
172172
git reset --hard before-preserve-rebase &&
173173
test_config pull.rebase true &&
174174
git pull . copy &&
175-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
176-
test file3 = $(git show HEAD:file3.t)
175+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
176+
test file3 = "$(git show HEAD:file3.t)"
177177
'
178178

179179
test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
180180
git reset --hard before-preserve-rebase &&
181181
test_config pull.rebase 1 &&
182182
git pull . copy &&
183-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
184-
test file3 = $(git show HEAD:file3.t)
183+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
184+
test file3 = "$(git show HEAD:file3.t)"
185185
'
186186

187187
test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
188188
git reset --hard before-preserve-rebase &&
189189
test_config pull.rebase preserve &&
190190
git pull . copy &&
191-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
192-
test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
191+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
192+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
193193
'
194194

195195
test_expect_success 'pull.rebase=invalid fails' '
@@ -202,25 +202,25 @@ test_expect_success '--rebase=false create a new merge commit' '
202202
git reset --hard before-preserve-rebase &&
203203
test_config pull.rebase true &&
204204
git pull --rebase=false . copy &&
205-
test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
206-
test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
207-
test file3 = $(git show HEAD:file3.t)
205+
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
206+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
207+
test file3 = "$(git show HEAD:file3.t)"
208208
'
209209

210210
test_expect_success '--rebase=true rebases and flattens keep-merge' '
211211
git reset --hard before-preserve-rebase &&
212212
test_config pull.rebase preserve &&
213213
git pull --rebase=true . copy &&
214-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
215-
test file3 = $(git show HEAD:file3.t)
214+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
215+
test file3 = "$(git show HEAD:file3.t)"
216216
'
217217

218218
test_expect_success '--rebase=preserve rebases and merges keep-merge' '
219219
git reset --hard before-preserve-rebase &&
220220
test_config pull.rebase true &&
221221
git pull --rebase=preserve . copy &&
222-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
223-
test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
222+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
223+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
224224
'
225225

226226
test_expect_success '--rebase=invalid fails' '
@@ -232,8 +232,8 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
232232
git reset --hard before-preserve-rebase &&
233233
test_config pull.rebase preserve &&
234234
git pull --rebase . copy &&
235-
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
236-
test file3 = $(git show HEAD:file3.t)
235+
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
236+
test file3 = "$(git show HEAD:file3.t)"
237237
'
238238

239239
test_expect_success '--rebase with rebased upstream' '
@@ -250,7 +250,7 @@ test_expect_success '--rebase with rebased upstream' '
250250
git tag to-rebase-orig &&
251251
git pull --rebase me copy &&
252252
test "conflicting modification" = "$(cat file)" &&
253-
test file = $(cat file2)
253+
test file = "$(cat file2)"
254254
255255
'
256256

@@ -261,7 +261,7 @@ test_expect_success '--rebase with rebased default upstream' '
261261
git reset --hard to-rebase-orig &&
262262
git pull --rebase &&
263263
test "conflicting modification" = "$(cat file)" &&
264-
test file = $(cat file2)
264+
test file = "$(cat file2)"
265265
266266
'
267267

@@ -282,18 +282,18 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
282282
283283
git checkout to-rebase &&
284284
git update-ref refs/remotes/me/copy copy^ &&
285-
COPY=$(git rev-parse --verify me/copy) &&
285+
COPY="$(git rev-parse --verify me/copy)" &&
286286
git rebase --onto $COPY copy &&
287287
test_config branch.to-rebase.remote me &&
288288
test_config branch.to-rebase.merge refs/heads/copy &&
289289
test_config branch.to-rebase.rebase true &&
290290
echo dirty >> file &&
291291
git add file &&
292292
test_must_fail git pull &&
293-
test $COPY = $(git rev-parse --verify me/copy) &&
293+
test "$COPY" = "$(git rev-parse --verify me/copy)" &&
294294
git checkout HEAD -- file &&
295295
git pull &&
296-
test $COPY != $(git rev-parse --verify me/copy)
296+
test "$COPY" != "$(git rev-parse --verify me/copy)"
297297
298298
'
299299

0 commit comments

Comments
 (0)