t / t6026-merge-attr.shon commit Merge branch 'jk/oi-delta-base' (b213206)
   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
  73test_expect_success 'retry the merge with longer context' '
  74        echo text conflict-marker-size=32 >>.gitattributes &&
  75        git checkout -m text &&
  76        sed -ne "/^\([<=>]\)\1\1\1*/{
  77                s/ .*$//
  78                p
  79        }" >actual text &&
  80        grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
  81        grep "================================" actual &&
  82        grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
  83'
  84
  85cat >./custom-merge <<\EOF
  86#!/bin/sh
  87
  88orig="$1" ours="$2" theirs="$3" exit="$4"
  89(
  90        echo "orig is $orig"
  91        echo "ours is $ours"
  92        echo "theirs is $theirs"
  93        echo "=== orig ==="
  94        cat "$orig"
  95        echo "=== ours ==="
  96        cat "$ours"
  97        echo "=== theirs ==="
  98        cat "$theirs"
  99) >"$ours+"
 100cat "$ours+" >"$ours"
 101rm -f "$ours+"
 102exit "$exit"
 103EOF
 104chmod +x ./custom-merge
 105
 106test_expect_success 'custom merge backend' '
 107
 108        echo "* merge=union" >.gitattributes &&
 109        echo "text merge=custom" >>.gitattributes &&
 110
 111        git reset --hard anchor &&
 112        git config --replace-all \
 113        merge.custom.driver "./custom-merge %O %A %B 0" &&
 114        git config --replace-all \
 115        merge.custom.name "custom merge driver for testing" &&
 116
 117        git merge master &&
 118
 119        cmp binary union &&
 120        sed -e 1,3d text >check-1 &&
 121        o=$(git unpack-file master^:text) &&
 122        a=$(git unpack-file side^:text) &&
 123        b=$(git unpack-file master:text) &&
 124        sh -c "./custom-merge $o $a $b 0" &&
 125        sed -e 1,3d $a >check-2 &&
 126        cmp check-1 check-2 &&
 127        rm -f $o $a $b
 128'
 129
 130test_expect_success 'custom merge backend' '
 131
 132        git reset --hard anchor &&
 133        git config --replace-all \
 134        merge.custom.driver "./custom-merge %O %A %B 1" &&
 135        git config --replace-all \
 136        merge.custom.name "custom merge driver for testing" &&
 137
 138        if git merge master
 139        then
 140                echo "Eh? should have conflicted"
 141                false
 142        else
 143                echo "Ok, conflicted"
 144        fi &&
 145
 146        cmp binary union &&
 147        sed -e 1,3d text >check-1 &&
 148        o=$(git unpack-file master^:text) &&
 149        a=$(git unpack-file anchor:text) &&
 150        b=$(git unpack-file master:text) &&
 151        sh -c "./custom-merge $o $a $b 0" &&
 152        sed -e 1,3d $a >check-2 &&
 153        cmp check-1 check-2 &&
 154        rm -f $o $a $b
 155'
 156
 157test_expect_success 'up-to-date merge without common ancestor' '
 158        test_create_repo repo1 &&
 159        test_create_repo repo2 &&
 160        test_tick &&
 161        (
 162                cd repo1 &&
 163                >a &&
 164                git add a &&
 165                git commit -m initial
 166        ) &&
 167        test_tick &&
 168        (
 169                cd repo2 &&
 170                git commit --allow-empty -m initial
 171        ) &&
 172        test_tick &&
 173        (
 174                cd repo1 &&
 175                git pull ../repo2 master
 176        )
 177'
 178
 179test_done