Skip to content

Commit 6209036

Browse files
jrngitster
authored andcommitted
t7606 (merge-theirs): modernize style
Guard setup commands with test_expect_success, so they are easier to visually skip over and get to the good part. While at it: - use test_commit for brevity and reproducible object names; - use test_cmp instead of using the test builtin to compare the result of command substitution, for better output with -v on failure. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 64fdc08 commit 6209036

1 file changed

Lines changed: 40 additions & 26 deletions

File tree

t/t7606-merge-custom.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
#!/bin/sh
22

3-
test_description='git merge
3+
test_description="git merge
44
5-
Testing a custom strategy.'
5+
Testing a custom strategy.
6+
7+
* (HEAD, master) Merge commit 'c2'
8+
|\
9+
| * (tag: c2) c2
10+
* | (tag: c1) c1
11+
|/
12+
* (tag: c0) c0
13+
"
614

715
. ./test-lib.sh
816

9-
cat >git-merge-theirs <<EOF
10-
#!$SHELL_PATH
11-
eval git read-tree --reset -u \\\$\$#
12-
EOF
13-
chmod +x git-merge-theirs
14-
PATH=.:$PATH
15-
export PATH
17+
test_expect_success 'set up custom strategy' '
18+
cat >git-merge-theirs <<-EOF &&
19+
#!$SHELL_PATH
20+
eval git read-tree --reset -u \\\$\$#
21+
EOF
22+
23+
chmod +x git-merge-theirs &&
24+
PATH=.:$PATH &&
25+
export PATH
26+
'
1627

1728
test_expect_success 'setup' '
18-
echo c0 >c0.c &&
19-
git add c0.c &&
20-
git commit -m c0 &&
21-
git tag c0 &&
22-
echo c1 >c1.c &&
23-
git add c1.c &&
24-
git commit -m c1 &&
25-
git tag c1 &&
26-
git reset --hard c0 &&
29+
test_commit c0 c0.c &&
30+
test_commit c1 c1.c &&
31+
git reset --keep c0 &&
2732
echo c1c1 >c1.c &&
28-
echo c2 >c2.c &&
29-
git add c1.c c2.c &&
30-
git commit -m c2 &&
31-
git tag c2
33+
git add c1.c &&
34+
test_commit c2 c2.c
3235
'
3336

3437
test_expect_success 'merge c2 with a custom strategy' '
3538
git reset --hard c1 &&
39+
40+
git rev-parse c1 >head.old &&
41+
git rev-parse c2 >second-parent.expected &&
42+
git rev-parse c2^{tree} >tree.expected &&
3643
git merge -s theirs c2 &&
37-
test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
38-
test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
39-
test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
40-
test "$(git rev-parse c2^{tree})" = "$(git rev-parse HEAD^{tree})" &&
44+
45+
git rev-parse HEAD >head &&
46+
git rev-parse HEAD^1 >first-parent &&
47+
git rev-parse HEAD^2 >second-parent &&
48+
git rev-parse HEAD^{tree} >tree &&
49+
git update-index --refresh &&
4150
git diff --exit-code &&
4251
git diff --exit-code c2 HEAD &&
4352
git diff --exit-code c2 &&
53+
54+
! test_cmp head.old head &&
55+
test_cmp head.old first-parent &&
56+
test_cmp second-parent.expected second-parent &&
57+
test_cmp tree.expected tree &&
4458
test -f c0.c &&
4559
grep c1c1 c1.c &&
4660
test -f c2.c

0 commit comments

Comments
 (0)