| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='merge: handle file mode' |
| 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
| 7 | . ./test-lib.sh |
| 8 | |
| 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 |
| 21 | ' |
| 22 | |
| 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 |
| 31 | ' |
| 32 | |
| 33 | test_expect_success FILEMODE "verify executable bit on file ($strategy, $us)" ' |
| 34 | test -x file1 |
| 35 | ' |
| 36 | } |
| 37 | |
| 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 |
| 42 | |
| 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 && |
| 54 | cat >expect <<-EOF |
| 55 | 100755 $H 2 file2 |
| 56 | 100644 $H 3 file2 |
| 57 | EOF |
| 58 | ' |
| 59 | |
| 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 |
| 69 | ' |
| 70 | |
| 71 | test_expect_success FILEMODE "verify executable bit on file ($strategy)" ' |
| 72 | test -x file2 |
| 73 | ' |
| 74 | } |
| 75 | |
| 76 | # both sides are equivalent, so no need to run both ways |
| 77 | do_both_modes recursive |
| 78 | do_both_modes resolve |
| 79 | |
| 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 |
| 85 | ' |
| 86 | |
| 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 |
| 95 | ' |
| 96 | } |
| 97 | |
| 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 |
| 102 | |
| 103 | test_done |