Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t6411-merge-filemode.sh
blobf54c915d6a540719329277e7c9e77a8ed4536a93
1 #!/bin/sh
3 test_description='merge: handle file mode'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
9 test_expect_success 'set up mode change in one branch' '
10 : >file1 &&
11 git add file1 &&
12 git commit -m initial &&
13 git checkout -b a1 main &&
14 : >dummy &&
15 git add dummy &&
16 git commit -m a &&
17 git checkout -b b1 main &&
18 test_chmod +x file1 &&
19 git add file1 &&
20 git commit -m b1
23 do_one_mode () {
24 strategy=$1
25 us=$2
26 them=$3
27 test_expect_success "resolve single mode change ($strategy, $us)" '
28 git checkout -f $us &&
29 git merge -s $strategy $them &&
30 git ls-files -s file1 | grep ^100755
33 test_expect_success FILEMODE "verify executable bit on file ($strategy, $us)" '
34 test -x file1
38 do_one_mode recursive a1 b1
39 do_one_mode recursive b1 a1
40 do_one_mode resolve a1 b1
41 do_one_mode resolve b1 a1
43 test_expect_success 'set up mode change in both branches' '
44 git reset --hard HEAD &&
45 git checkout -b a2 main &&
46 : >file2 &&
47 H=$(git hash-object file2) &&
48 test_chmod +x file2 &&
49 git commit -m a2 &&
50 git checkout -b b2 main &&
51 : >file2 &&
52 git add file2 &&
53 git commit -m b2 &&
55 echo "100755 $H 2 file2"
56 echo "100644 $H 3 file2"
57 } >expect
60 do_both_modes () {
61 strategy=$1
62 test_expect_success "detect conflict on double mode change ($strategy)" '
63 git reset --hard &&
64 git checkout -f a2 &&
65 test_must_fail git merge -s $strategy b2 &&
66 git ls-files -u >actual &&
67 test_cmp expect actual &&
68 git ls-files -s file2 | grep ^100755
71 test_expect_success FILEMODE "verify executable bit on file ($strategy)" '
72 test -x file2
76 # both sides are equivalent, so no need to run both ways
77 do_both_modes recursive
78 do_both_modes resolve
80 test_expect_success 'set up delete/modechange scenario' '
81 git reset --hard &&
82 git checkout -b deletion main &&
83 git rm file1 &&
84 git commit -m deletion
87 do_delete_modechange () {
88 strategy=$1
89 us=$2
90 them=$3
91 test_expect_success "detect delete/modechange conflict ($strategy, $us)" '
92 git reset --hard &&
93 git checkout $us &&
94 test_must_fail git merge -s $strategy $them
98 do_delete_modechange recursive b1 deletion
99 do_delete_modechange recursive deletion b1
100 do_delete_modechange resolve b1 deletion
101 do_delete_modechange resolve deletion b1
103 test_done