t / t6031-merge-filemode.shon commit remote: add a macro for "refs/tags/*:refs/tags/*" (750d0da)
   1#!/bin/sh
   2
   3test_description='merge: handle file mode'
   4. ./test-lib.sh
   5
   6test_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
  20do_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
  35do_one_mode recursive a1 b1
  36do_one_mode recursive b1 a1
  37do_one_mode resolve a1 b1
  38do_one_mode resolve b1 a1
  39
  40test_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
  57do_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
  74do_both_modes recursive
  75do_both_modes resolve
  76
  77test_expect_success 'set up delete/modechange scenario' '
  78        git reset --hard &&
  79        git checkout -b deletion master &&
  80        git rm file1 &&
  81        git commit -m deletion
  82'
  83
  84do_delete_modechange () {
  85        strategy=$1
  86        us=$2
  87        them=$3
  88        test_expect_success "detect delete/modechange conflict ($strategy, $us)" '
  89                git reset --hard &&
  90                git checkout $us &&
  91                test_must_fail git merge -s $strategy $them
  92        '
  93}
  94
  95do_delete_modechange recursive b1 deletion
  96do_delete_modechange recursive deletion b1
  97do_delete_modechange resolve b1 deletion
  98do_delete_modechange resolve deletion b1
  99
 100test_done