Skip to content

Commit f78d1fe

Browse files
peffgitster
authored andcommitted
t6031: generalize for recursive and resolve strategies
This script tests the filemode handling of merge-recursive, but we do not test the same thing for merge-resolve. Let's generalize the script a little: 1. Break out the setup steps for each test into a separate snippet. 2. For each test, run it twice; once with "-s recursive" and once with "-s resolve". We can avoid repeating ourselves by adding a function. 3. Since we have a nice abstracted function, we can make our tests more thorough by testing both directions (change on "ours" versus "theirs"). This improves our test coverage, and will make this the place to add more tests related to merging mode changes. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f50833 commit f78d1fe

File tree

2 files changed

+77
-56
lines changed

2 files changed

+77
-56
lines changed

t/t6031-merge-filemode.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
test_description='merge: handle file mode'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'set up mode change in one branch' '
7+
: >file1 &&
8+
git add file1 &&
9+
git commit -m initial &&
10+
git checkout -b a1 master &&
11+
: >dummy &&
12+
git add dummy &&
13+
git commit -m a &&
14+
git checkout -b b1 master &&
15+
test_chmod +x file1 &&
16+
git add file1 &&
17+
git commit -m b1
18+
'
19+
20+
do_one_mode () {
21+
strategy=$1
22+
us=$2
23+
them=$3
24+
test_expect_success "resolve single mode change ($strategy, $us)" '
25+
git checkout -f $us &&
26+
git merge -s $strategy $them &&
27+
git ls-files -s file1 | grep ^100755
28+
'
29+
30+
test_expect_success FILEMODE "verify executable bit on file ($strategy, $us)" '
31+
test -x file1
32+
'
33+
}
34+
35+
do_one_mode recursive a1 b1
36+
do_one_mode recursive b1 a1
37+
do_one_mode resolve a1 b1
38+
do_one_mode resolve b1 a1
39+
40+
test_expect_success 'set up mode change in both branches' '
41+
git reset --hard HEAD &&
42+
git checkout -b a2 master &&
43+
: >file2 &&
44+
H=$(git hash-object file2) &&
45+
test_chmod +x file2 &&
46+
git commit -m a2 &&
47+
git checkout -b b2 master &&
48+
: >file2 &&
49+
git add file2 &&
50+
git commit -m b2 &&
51+
{
52+
echo "100755 $H 2 file2"
53+
echo "100644 $H 3 file2"
54+
} >expect
55+
'
56+
57+
do_both_modes () {
58+
strategy=$1
59+
test_expect_success "detect conflict on double mode change ($strategy)" '
60+
git reset --hard &&
61+
git checkout -f a2 &&
62+
test_must_fail git merge -s $strategy b2 &&
63+
git ls-files -u >actual &&
64+
test_cmp actual expect &&
65+
git ls-files -s file2 | grep ^100755
66+
'
67+
68+
test_expect_success FILEMODE "verify executable bit on file ($strategy)" '
69+
test -x file2
70+
'
71+
}
72+
73+
# both sides are equivalent, so no need to run both ways
74+
do_both_modes recursive
75+
do_both_modes resolve
76+
77+
test_done

t/t6031-merge-recursive.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)