Skip to content

Commit 24e099f

Browse files
drafnelgitster
authored andcommitted
t7502: perform commits using alternate editor in a subshell
These tests call test_set_editor to set an alternate editor script, but they appear to presume that the assignment is of a temporary nature and will not have any effect outside of each individual test. That is not the case. All of the test functions within a test script share a single environment, so any variables modified in one, are visible in the ones that follow. So, let's protect the test functions that follow these, which set an alternate editor, by performing the test_set_editor and 'git commit' in a subshell. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 51fb3a3 commit 24e099f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

t/t7502-commit.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,32 +255,40 @@ test_expect_success 'cleanup commit message (fail on invalid cleanup mode config
255255
test_expect_success 'cleanup commit message (no config and no option uses default)' '
256256
echo content >>file &&
257257
git add file &&
258-
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
259-
git commit --no-status &&
258+
(
259+
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
260+
git commit --no-status
261+
) &&
260262
commit_msg_is "commit message"
261263
'
262264

263265
test_expect_success 'cleanup commit message (option overrides default)' '
264266
echo content >>file &&
265267
git add file &&
266-
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
267-
git commit --cleanup=whitespace --no-status &&
268+
(
269+
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
270+
git commit --cleanup=whitespace --no-status
271+
) &&
268272
commit_msg_is "commit message # comment"
269273
'
270274

271275
test_expect_success 'cleanup commit message (config overrides default)' '
272276
echo content >>file &&
273277
git add file &&
274-
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
275-
git -c commit.cleanup=whitespace commit --no-status &&
278+
(
279+
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
280+
git -c commit.cleanup=whitespace commit --no-status
281+
) &&
276282
commit_msg_is "commit message # comment"
277283
'
278284

279285
test_expect_success 'cleanup commit message (option overrides config)' '
280286
echo content >>file &&
281287
git add file &&
282-
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
283-
git -c commit.cleanup=whitespace commit --cleanup=default &&
288+
(
289+
test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
290+
git -c commit.cleanup=whitespace commit --cleanup=default
291+
) &&
284292
commit_msg_is "commit message"
285293
'
286294

0 commit comments

Comments
 (0)