Skip to content

Commit 44a59ff

Browse files
mehul2029gitster
authored andcommitted
t5520: factor out common "failing autostash" code
Three tests contains repetitive lines of code. Factor out common code into test_pull_autostash_fail() and then call it in these tests. Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Mehul Jain <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c82bcd commit 44a59ff

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

t/t5520-pull.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ test_pull_autostash () {
1919
test "$(cat file)" = "modified again"
2020
}
2121

22+
test_pull_autostash_fail () {
23+
git reset --hard before-rebase &&
24+
echo dirty >new_file &&
25+
git add new_file &&
26+
test_must_fail git pull "$@" . copy 2>err &&
27+
test_i18ngrep "uncommitted changes." err
28+
}
29+
2230
test_expect_success setup '
2331
echo file >file &&
2432
git add file &&
@@ -277,29 +285,17 @@ test_expect_success 'pull --rebase --autostash & rebase.autostash unset' '
277285

278286
test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' '
279287
test_config rebase.autostash true &&
280-
git reset --hard before-rebase &&
281-
echo dirty >new_file &&
282-
git add new_file &&
283-
test_must_fail git pull --rebase --no-autostash . copy 2>err &&
284-
test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
288+
test_pull_autostash_fail --rebase --no-autostash
285289
'
286290

287291
test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' '
288292
test_config rebase.autostash false &&
289-
git reset --hard before-rebase &&
290-
echo dirty >new_file &&
291-
git add new_file &&
292-
test_must_fail git pull --rebase --no-autostash . copy 2>err &&
293-
test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
293+
test_pull_autostash_fail --rebase --no-autostash
294294
'
295295

296296
test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
297297
test_unconfig rebase.autostash &&
298-
git reset --hard before-rebase &&
299-
echo dirty >new_file &&
300-
git add new_file &&
301-
test_must_fail git pull --rebase --no-autostash . copy 2>err &&
302-
test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
298+
test_pull_autostash_fail --rebase --no-autostash
303299
'
304300

305301
test_expect_success 'pull --autostash (without --rebase) should error out' '

0 commit comments

Comments
 (0)