Skip to content

Commit f7f43af

Browse files
committed
Merge branch 'dl/test-must-fail-fixes-2'
Test updates. * dl/test-must-fail-fixes-2: t4124: only mark git command with test_must_fail t3507: use test_path_is_missing() t3507: fix indentation t3504: do check for conflict marker after failed cherry-pick t3419: stop losing return code of git command t3415: increase granularity of test_auto_{fixup,squash}() t3415: stop losing return codes of git commands t3310: extract common notes_merge_files_gone() t3030: use test_path_is_missing() t2018: replace "sha" with "oid" t2018: don't lose return code of git commands t2018: teach do_checkout() to accept `!` arg t2018: be more discerning when checking for expected exit codes t2018: improve style of if-statement t2018: add space between function name and () t2018: remove trailing space from test description
2 parents d8b8d59 + 37a63fa commit f7f43af

8 files changed

+204
-95
lines changed

t/t2018-checkout-branch.sh

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,76 @@
11
#!/bin/sh
22

3-
test_description='checkout '
3+
test_description='checkout'
44

55
. ./test-lib.sh
66

7-
# Arguments: <branch> <sha> [<checkout options>]
7+
# Arguments: [!] <branch> <oid> [<checkout options>]
88
#
99
# Runs "git checkout" to switch to <branch>, testing that
1010
#
1111
# 1) we are on the specified branch, <branch>;
12-
# 2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.
12+
# 2) HEAD is <oid>; if <oid> is not specified, the old HEAD is used.
1313
#
1414
# If <checkout options> is not specified, "git checkout" is run with -b.
15-
do_checkout() {
15+
#
16+
# If the first argument is `!`, "git checkout" is expected to fail when
17+
# it is run.
18+
do_checkout () {
19+
should_fail= &&
20+
if test "x$1" = "x!"
21+
then
22+
should_fail=yes &&
23+
shift
24+
fi &&
1625
exp_branch=$1 &&
1726
exp_ref="refs/heads/$exp_branch" &&
1827

19-
# if <sha> is not specified, use HEAD.
20-
exp_sha=${2:-$(git rev-parse --verify HEAD)} &&
28+
# if <oid> is not specified, use HEAD.
29+
exp_oid=${2:-$(git rev-parse --verify HEAD)} &&
2130

2231
# default options for git checkout: -b
23-
if [ -z "$3" ]; then
32+
if test -z "$3"
33+
then
2434
opts="-b"
2535
else
2636
opts="$3"
2737
fi
2838

29-
git checkout $opts $exp_branch $exp_sha &&
39+
if test -n "$should_fail"
40+
then
41+
test_must_fail git checkout $opts $exp_branch $exp_oid
42+
else
43+
git checkout $opts $exp_branch $exp_oid &&
44+
echo "$exp_ref" >ref.expect &&
45+
git rev-parse --symbolic-full-name HEAD >ref.actual &&
46+
test_cmp ref.expect ref.actual &&
47+
echo "$exp_oid" >oid.expect &&
48+
git rev-parse --verify HEAD >oid.actual &&
49+
test_cmp oid.expect oid.actual
50+
fi
51+
}
3052

31-
test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
32-
test $exp_sha = $(git rev-parse --verify HEAD)
53+
test_dirty_unmergeable () {
54+
test_expect_code 1 git diff --exit-code
3355
}
3456

35-
test_dirty_unmergeable() {
36-
! git diff --exit-code >/dev/null
57+
test_dirty_unmergeable_discards_changes () {
58+
git diff --exit-code
3759
}
3860

39-
setup_dirty_unmergeable() {
61+
setup_dirty_unmergeable () {
4062
echo >>file1 change2
4163
}
4264

43-
test_dirty_mergeable() {
44-
! git diff --cached --exit-code >/dev/null
65+
test_dirty_mergeable () {
66+
test_expect_code 1 git diff --cached --exit-code
67+
}
68+
69+
test_dirty_mergeable_discards_changes () {
70+
git diff --cached --exit-code
4571
}
4672

47-
setup_dirty_mergeable() {
73+
setup_dirty_mergeable () {
4874
echo >file2 file2 &&
4975
git add file2
5076
}
@@ -82,7 +108,7 @@ test_expect_success 'checkout -b to a new branch, set to an explicit ref' '
82108

83109
test_expect_success 'checkout -b to a new branch with unmergeable changes fails' '
84110
setup_dirty_unmergeable &&
85-
test_must_fail do_checkout branch2 $HEAD1 &&
111+
do_checkout ! branch2 $HEAD1 &&
86112
test_dirty_unmergeable
87113
'
88114

@@ -93,7 +119,7 @@ test_expect_success 'checkout -f -b to a new branch with unmergeable changes dis
93119
94120
# still dirty and on branch1
95121
do_checkout branch2 $HEAD1 "-f -b" &&
96-
test_must_fail test_dirty_unmergeable
122+
test_dirty_unmergeable_discards_changes
97123
'
98124

99125
test_expect_success 'checkout -b to a new branch preserves mergeable changes' '
@@ -111,12 +137,12 @@ test_expect_success 'checkout -f -b to a new branch with mergeable changes disca
111137
test_when_finished git reset --hard HEAD &&
112138
setup_dirty_mergeable &&
113139
do_checkout branch2 $HEAD1 "-f -b" &&
114-
test_must_fail test_dirty_mergeable
140+
test_dirty_mergeable_discards_changes
115141
'
116142

117143
test_expect_success 'checkout -b to an existing branch fails' '
118144
test_when_finished git reset --hard HEAD &&
119-
test_must_fail do_checkout branch2 $HEAD2
145+
do_checkout ! branch2 $HEAD2
120146
'
121147

122148
test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
@@ -140,7 +166,8 @@ test_expect_success 'checkout -B to a merge base' '
140166
'
141167

142168
test_expect_success 'checkout -B to an existing branch from detached HEAD resets branch to HEAD' '
143-
git checkout $(git rev-parse --verify HEAD) &&
169+
head=$(git rev-parse --verify HEAD) &&
170+
git checkout "$head" &&
144171
145172
do_checkout branch2 "" -B
146173
'
@@ -155,14 +182,14 @@ test_expect_success 'checkout -B to an existing branch with unmergeable changes
155182
git checkout branch1 &&
156183
157184
setup_dirty_unmergeable &&
158-
test_must_fail do_checkout branch2 $HEAD1 -B &&
185+
do_checkout ! branch2 $HEAD1 -B &&
159186
test_dirty_unmergeable
160187
'
161188

162189
test_expect_success 'checkout -f -B to an existing branch with unmergeable changes discards changes' '
163190
# still dirty and on branch1
164191
do_checkout branch2 $HEAD1 "-f -B" &&
165-
test_must_fail test_dirty_unmergeable
192+
test_dirty_unmergeable_discards_changes
166193
'
167194

168195
test_expect_success 'checkout -B to an existing branch preserves mergeable changes' '
@@ -179,7 +206,7 @@ test_expect_success 'checkout -f -B to an existing branch with mergeable changes
179206
180207
setup_dirty_mergeable &&
181208
do_checkout branch2 $HEAD1 "-f -B" &&
182-
test_must_fail test_dirty_mergeable
209+
test_dirty_mergeable_discards_changes
183210
'
184211

185212
test_expect_success 'checkout -b <describe>' '

t/t3030-merge-recursive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ test_expect_success 'merge removes empty directories' '
604604
git commit -mremoved-d/e &&
605605
git checkout master &&
606606
git merge -s recursive rm &&
607-
test_must_fail test -d d
607+
test_path_is_missing d
608608
'
609609

610610
test_expect_success 'merge-recursive simple w/submodule' '

t/t3310-notes-merge-manual-resolve.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ verify_notes () {
3232
test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
3333
}
3434

35+
notes_merge_files_gone () {
36+
# No .git/NOTES_MERGE_* files left
37+
{ ls .git/NOTES_MERGE_* >output || :; } &&
38+
test_must_be_empty output
39+
}
40+
3541
cat <<EOF | sort >expect_notes_x
3642
6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
3743
e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
@@ -335,9 +341,7 @@ EOF
335341
y and z notes on 4th commit
336342
EOF
337343
git notes merge --commit &&
338-
# No .git/NOTES_MERGE_* files left
339-
test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
340-
test_must_be_empty output &&
344+
notes_merge_files_gone &&
341345
# Merge commit has pre-merge y and pre-merge z as parents
342346
test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
343347
test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
@@ -397,9 +401,7 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol
397401

398402
test_expect_success 'abort notes merge' '
399403
git notes merge --abort &&
400-
# No .git/NOTES_MERGE_* files left
401-
test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
402-
test_must_be_empty output &&
404+
notes_merge_files_gone &&
403405
# m has not moved (still == y)
404406
test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" &&
405407
# Verify that other notes refs has not changed (w, x, y and z)
@@ -464,9 +466,7 @@ EOF
464466
echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 &&
465467
# Finalize merge
466468
git notes merge --commit &&
467-
# No .git/NOTES_MERGE_* files left
468-
test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
469-
test_must_be_empty output &&
469+
notes_merge_files_gone &&
470470
# Merge commit has pre-merge y and pre-merge z as parents
471471
test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
472472
test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
@@ -553,9 +553,7 @@ EOF
553553

554554
test_expect_success 'resolve situation by aborting the notes merge' '
555555
git notes merge --abort &&
556-
# No .git/NOTES_MERGE_* files left
557-
test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
558-
test_must_be_empty output &&
556+
notes_merge_files_gone &&
559557
# m has not moved (still == w)
560558
test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
561559
# Verify that other notes refs has not changed (w, x, y and z)

0 commit comments

Comments
 (0)