Code

1732b60ed8be3c8bd8ea39afc62205db4fccc228
[git.git] / t / t6026-merge-attr.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Junio C Hamano
4 #
6 test_description='per path merge controlled by merge attribute'
8 . ./test-lib.sh
10 test_expect_success setup '
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 &&
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 &&
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 &&
35         git tag anchor
36 '
38 test_expect_success merge '
40         {
41                 echo "binary -merge"
42                 echo "union merge=union"
43         } >.gitattributes &&
45         if git merge master
46         then
47                 echo Gaah, should have conflicted
48                 false
49         else
50                 echo Ok, conflicted.
51         fi
52 '
54 test_expect_success 'check merge result in index' '
56         git ls-files -u | grep binary &&
57         git ls-files -u | grep text &&
58         ! (git ls-files -u | grep union)
60 '
62 test_expect_success 'check merge result in working tree' '
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
71 '
73 cat >./custom-merge <<\EOF
74 #!/bin/sh
76 orig="$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+"
88 cat "$ours+" >"$ours"
89 rm -f "$ours+"
90 exit "$exit"
91 EOF
92 chmod +x ./custom-merge
94 test_expect_success 'custom merge backend' '
96         echo "* merge=union" >.gitattributes &&
97         echo "text merge=custom" >>.gitattributes &&
99         git reset --hard anchor &&
100         git config --replace-all \
101         merge.driver "custom ./custom-merge %O %A %B 0" &&
103         git merge master &&
105         cmp binary union &&
106         sed -e 1,3d text >check-1 &&
107         o=$(git-unpack-file master^:text) &&
108         a=$(git-unpack-file side^:text) &&
109         b=$(git-unpack-file master:text) &&
110         sh -c "./custom-merge $o $a $b 0" &&
111         sed -e 1,3d $a >check-2 &&
112         cmp check-1 check-2 &&
113         rm -f $o $a $b
116 test_expect_success 'custom merge backend' '
118         git reset --hard anchor &&
119         git config --replace-all \
120         merge.driver "custom ./custom-merge %O %A %B 1" &&
122         if git merge master
123         then
124                 echo "Eh? should have conflicted"
125                 false
126         else
127                 echo "Ok, conflicted"
128         fi &&
130         cmp binary union &&
131         sed -e 1,3d text >check-1 &&
132         o=$(git-unpack-file master^:text) &&
133         a=$(git-unpack-file anchor:text) &&
134         b=$(git-unpack-file master:text) &&
135         sh -c "./custom-merge $o $a $b 0" &&
136         sed -e 1,3d $a >check-2 &&
137         cmp check-1 check-2 &&
138         rm -f $o $a $b
141 test_done