t / t6026-merge-attr.shon commit Merge branch 'ap/trackinfo' (93310a4)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Junio C Hamano
   4#
   5
   6test_description='per path merge controlled by merge attribute'
   7
   8. ./test-lib.sh
   9
  10test_expect_success setup '
  11
  12        for f in text binary union
  13        do
  14                echo Initial >$f && git add $f || break
  15        done &&
  16        test_tick &&
  17        git commit -m Initial &&
  18
  19        git branch side &&
  20        for f in text binary union
  21        do
  22                echo Master >>$f && git add $f || break
  23        done &&
  24        test_tick &&
  25        git commit -m Master &&
  26
  27        git checkout side &&
  28        for f in text binary union
  29        do
  30                echo Side >>$f && git add $f || break
  31        done &&
  32        test_tick &&
  33        git commit -m Side &&
  34
  35        git tag anchor
  36'
  37
  38test_expect_success merge '
  39
  40        {
  41                echo "binary -merge"
  42                echo "union merge=union"
  43        } >.gitattributes &&
  44
  45        if git merge master
  46        then
  47                echo Gaah, should have conflicted
  48                false
  49        else
  50                echo Ok, conflicted.
  51        fi
  52'
  53
  54test_expect_success 'check merge result in index' '
  55
  56        git ls-files -u | grep binary &&
  57        git ls-files -u | grep text &&
  58        ! (git ls-files -u | grep union)
  59
  60'
  61
  62test_expect_success 'check merge result in working tree' '
  63
  64        git cat-file -p HEAD:binary >binary-orig &&
  65        grep "<<<<<<<" text &&
  66        cmp binary-orig binary &&
  67        ! grep "<<<<<<<" union &&
  68        grep Master union &&
  69        grep Side union
  70
  71'
  72
  73cat >./custom-merge <<\EOF
  74#!/bin/sh
  75
  76orig="$1" ours="$2" theirs="$3" exit="$4"
  77(
  78        echo "orig is $orig"
  79        echo "ours is $ours"
  80        echo "theirs is $theirs"
  81        echo "=== orig ==="
  82        cat "$orig"
  83        echo "=== ours ==="
  84        cat "$ours"
  85        echo "=== theirs ==="
  86        cat "$theirs"
  87) >"$ours+"
  88cat "$ours+" >"$ours"
  89rm -f "$ours+"
  90exit "$exit"
  91EOF
  92chmod +x ./custom-merge
  93
  94test_expect_success 'custom merge backend' '
  95
  96        echo "* merge=union" >.gitattributes &&
  97        echo "text merge=custom" >>.gitattributes &&
  98
  99        git reset --hard anchor &&
 100        git config --replace-all \
 101        merge.custom.driver "./custom-merge %O %A %B 0" &&
 102        git config --replace-all \
 103        merge.custom.name "custom merge driver for testing" &&
 104
 105        git merge master &&
 106
 107        cmp binary union &&
 108        sed -e 1,3d text >check-1 &&
 109        o=$(git-unpack-file master^:text) &&
 110        a=$(git-unpack-file side^:text) &&
 111        b=$(git-unpack-file master:text) &&
 112        sh -c "./custom-merge $o $a $b 0" &&
 113        sed -e 1,3d $a >check-2 &&
 114        cmp check-1 check-2 &&
 115        rm -f $o $a $b
 116'
 117
 118test_expect_success 'custom merge backend' '
 119
 120        git reset --hard anchor &&
 121        git config --replace-all \
 122        merge.custom.driver "./custom-merge %O %A %B 1" &&
 123        git config --replace-all \
 124        merge.custom.name "custom merge driver for testing" &&
 125
 126        if git merge master
 127        then
 128                echo "Eh? should have conflicted"
 129                false
 130        else
 131                echo "Ok, conflicted"
 132        fi &&
 133
 134        cmp binary union &&
 135        sed -e 1,3d text >check-1 &&
 136        o=$(git-unpack-file master^:text) &&
 137        a=$(git-unpack-file anchor:text) &&
 138        b=$(git-unpack-file master:text) &&
 139        sh -c "./custom-merge $o $a $b 0" &&
 140        sed -e 1,3d $a >check-2 &&
 141        cmp check-1 check-2 &&
 142        rm -f $o $a $b
 143'
 144
 145test_done