Merge branch 'kz/merge-fail-early-upon-refresh-failure'
[git.git] / t / t6411-merge-filemode.sh
blobb6182723aae158acb4e56ab9018c9b30f4f86cd6
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_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success 'set up mode change in one branch' '
11 : >file1 &&
12 git add file1 &&
13 git commit -m initial &&
14 git checkout -b a1 main &&
15 : >dummy &&
16 git add dummy &&
17 git commit -m a &&
18 git checkout -b b1 main &&
19 test_chmod +x file1 &&
20 git add file1 &&
21 git commit -m b1
24 do_one_mode () {
25 strategy=$1
26 us=$2
27 them=$3
28 test_expect_success "resolve single mode change ($strategy, $us)" '
29 git checkout -f $us &&
30 git merge -s $strategy $them &&
31 git ls-files -s file1 | grep ^100755
34 test_expect_success FILEMODE "verify executable bit on file ($strategy, $us)" '
35 test -x file1
39 do_one_mode recursive a1 b1
40 do_one_mode recursive b1 a1
41 do_one_mode resolve a1 b1
42 do_one_mode resolve b1 a1
44 test_expect_success 'set up mode change in both branches' '
45 git reset --hard HEAD &&
46 git checkout -b a2 main &&
47 : >file2 &&
48 H=$(git hash-object file2) &&
49 test_chmod +x file2 &&
50 git commit -m a2 &&
51 git checkout -b b2 main &&
52 : >file2 &&
53 git add file2 &&
54 git commit -m b2 &&
55 cat >expect <<-EOF
56 100755 $H 2 file2
57 100644 $H 3 file2
58 EOF
61 do_both_modes () {
62 strategy=$1
63 test_expect_success "detect conflict on double mode change ($strategy)" '
64 git reset --hard &&
65 git checkout -f a2 &&
66 test_must_fail git merge -s $strategy b2 &&
67 git ls-files -u >actual &&
68 test_cmp expect actual &&
69 git ls-files -s file2 | grep ^100755
72 test_expect_success FILEMODE "verify executable bit on file ($strategy)" '
73 test -x file2
77 # both sides are equivalent, so no need to run both ways
78 do_both_modes recursive
79 do_both_modes resolve
81 test_expect_success 'set up delete/modechange scenario' '
82 git reset --hard &&
83 git checkout -b deletion main &&
84 git rm file1 &&
85 git commit -m deletion
88 do_delete_modechange () {
89 strategy=$1
90 us=$2
91 them=$3
92 test_expect_success "detect delete/modechange conflict ($strategy, $us)" '
93 git reset --hard &&
94 git checkout $us &&
95 test_must_fail git merge -s $strategy $them
99 do_delete_modechange recursive b1 deletion
100 do_delete_modechange recursive deletion b1
101 do_delete_modechange resolve b1 deletion
102 do_delete_modechange resolve deletion b1
104 test_done