Skip to content

Commit 217e4a2

Browse files
peffgitster
authored andcommitted
t5510: make confusing config cleanup more explicit
Several tests set a config variable in a sub-repo we chdir into via a subshell, like this: ( cd "$D" && cd two && git config foo.bar baz ) But they also clean up the variable with a when_finished directive outside of the subshell, like this: test_when_finished "git config unset foo.bar" At first glance, this shouldn't work! The cleanup clause cannot be run from the subshell (since environment changes there are lost by the time the test snippet finishes). But since the cleanup command runs outside the subshell, our working directory will not have been switched into "two". But it does work. Why? The answer is that an earlier test does a "cd two" that moves the whole test's working directory out of $TRASH_DIRECTORY and into "two". So the subshell is a bit of a red herring; we are already in the right directory! That's why we need the "cd $D" at the top of the shell, to put us back to a known spot. Let's make this cleanup code more explicitly specify where we expect the config command to run. That makes the script more robust against running a subset of the tests, and ultimately will make it easier to refactor the script to avoid these top-level chdirs. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 465eff8 commit 217e4a2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

t/t5510-fetch.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ test_expect_success "fetch test remote HEAD change" '
119119
test "z$head" = "z$branch"'
120120

121121
test_expect_success "fetch test followRemoteHEAD never" '
122-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
122+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
123123
(
124124
cd "$D" &&
125125
cd two &&
@@ -134,7 +134,7 @@ test_expect_success "fetch test followRemoteHEAD never" '
134134
'
135135

136136
test_expect_success "fetch test followRemoteHEAD warn no change" '
137-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
137+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
138138
(
139139
cd "$D" &&
140140
cd two &&
@@ -154,7 +154,7 @@ test_expect_success "fetch test followRemoteHEAD warn no change" '
154154
'
155155

156156
test_expect_success "fetch test followRemoteHEAD warn create" '
157-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
157+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
158158
(
159159
cd "$D" &&
160160
cd two &&
@@ -170,7 +170,7 @@ test_expect_success "fetch test followRemoteHEAD warn create" '
170170
'
171171

172172
test_expect_success "fetch test followRemoteHEAD warn detached" '
173-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
173+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
174174
(
175175
cd "$D" &&
176176
cd two &&
@@ -187,7 +187,7 @@ test_expect_success "fetch test followRemoteHEAD warn detached" '
187187
'
188188

189189
test_expect_success "fetch test followRemoteHEAD warn quiet" '
190-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
190+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
191191
(
192192
cd "$D" &&
193193
cd two &&
@@ -205,7 +205,7 @@ test_expect_success "fetch test followRemoteHEAD warn quiet" '
205205
'
206206

207207
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is same" '
208-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
208+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
209209
(
210210
cd "$D" &&
211211
cd two &&
@@ -223,7 +223,7 @@ test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is sa
223223
'
224224

225225
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is different" '
226-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
226+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
227227
(
228228
cd "$D" &&
229229
cd two &&
@@ -243,7 +243,7 @@ test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is di
243243
'
244244

245245
test_expect_success "fetch test followRemoteHEAD always" '
246-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
246+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
247247
(
248248
cd "$D" &&
249249
cd two &&
@@ -260,7 +260,7 @@ test_expect_success "fetch test followRemoteHEAD always" '
260260
'
261261

262262
test_expect_success 'followRemoteHEAD does not kick in with refspecs' '
263-
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
263+
test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
264264
(
265265
cd "$D" &&
266266
cd two &&

0 commit comments

Comments
 (0)