Merge branch 'jx/pack-redundant-on-single-pack'
[git/debian.git] / t / t6406-merge-attr.sh
blob76a55f838c4ac03cfba678c0f188f67d4f724e6a
1 #!/bin/sh
3 # Copyright (c) 2007 Junio C Hamano
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
14 echo Initial >$f && git add $f || return 1
15 done &&
16 test_tick &&
17 git commit -m Initial &&
19 git branch side &&
20 for f in text binary union
22 echo Master >>$f && git add $f || return 1
23 done &&
24 test_tick &&
25 git commit -m Master &&
27 git checkout side &&
28 for f in text binary union
30 echo Side >>$f && git add $f || return 1
31 done &&
32 test_tick &&
33 git commit -m Side &&
35 git tag anchor &&
37 cat >./custom-merge <<-\EOF &&
38 #!/bin/sh
40 orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
42 echo "orig is $orig"
43 echo "ours is $ours"
44 echo "theirs is $theirs"
45 echo "path is $path"
46 echo "=== orig ==="
47 cat "$orig"
48 echo "=== ours ==="
49 cat "$ours"
50 echo "=== theirs ==="
51 cat "$theirs"
52 ) >"$ours+"
53 cat "$ours+" >"$ours"
54 rm -f "$ours+"
55 exit "$exit"
56 EOF
57 chmod +x ./custom-merge
60 test_expect_success merge '
63 echo "binary -merge"
64 echo "union merge=union"
65 } >.gitattributes &&
67 if git merge master
68 then
69 echo Gaah, should have conflicted
70 false
71 else
72 echo Ok, conflicted.
76 test_expect_success 'check merge result in index' '
78 git ls-files -u | grep binary &&
79 git ls-files -u | grep text &&
80 ! (git ls-files -u | grep union)
84 test_expect_success 'check merge result in working tree' '
86 git cat-file -p HEAD:binary >binary-orig &&
87 grep "<<<<<<<" text &&
88 cmp binary-orig binary &&
89 ! grep "<<<<<<<" union &&
90 grep Master union &&
91 grep Side union
95 test_expect_success 'retry the merge with longer context' '
96 echo text conflict-marker-size=32 >>.gitattributes &&
97 git checkout -m text &&
98 sed -ne "/^\([<=>]\)\1\1\1*/{
99 s/ .*$//
101 }" >actual text &&
102 grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
103 grep "================================" actual &&
104 grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
107 test_expect_success 'custom merge backend' '
109 echo "* merge=union" >.gitattributes &&
110 echo "text merge=custom" >>.gitattributes &&
112 git reset --hard anchor &&
113 git config --replace-all \
114 merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
115 git config --replace-all \
116 merge.custom.name "custom merge driver for testing" &&
118 git merge master &&
120 cmp binary union &&
121 sed -e 1,3d text >check-1 &&
122 o=$(git unpack-file master^:text) &&
123 a=$(git unpack-file side^:text) &&
124 b=$(git unpack-file master:text) &&
125 sh -c "./custom-merge $o $a $b 0 text" &&
126 sed -e 1,3d $a >check-2 &&
127 cmp check-1 check-2 &&
128 rm -f $o $a $b
131 test_expect_success 'custom merge backend' '
133 git reset --hard anchor &&
134 git config --replace-all \
135 merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
136 git config --replace-all \
137 merge.custom.name "custom merge driver for testing" &&
139 if git merge master
140 then
141 echo "Eh? should have conflicted"
142 false
143 else
144 echo "Ok, conflicted"
145 fi &&
147 cmp binary union &&
148 sed -e 1,3d text >check-1 &&
149 o=$(git unpack-file master^:text) &&
150 a=$(git unpack-file anchor:text) &&
151 b=$(git unpack-file master:text) &&
152 sh -c "./custom-merge $o $a $b 0 text" &&
153 sed -e 1,3d $a >check-2 &&
154 cmp check-1 check-2 &&
155 sed -e 1,3d -e 4q $a >check-3 &&
156 echo "path is text" >expect &&
157 cmp expect check-3 &&
158 rm -f $o $a $b
161 test_expect_success 'up-to-date merge without common ancestor' '
162 test_create_repo repo1 &&
163 test_create_repo repo2 &&
164 test_tick &&
166 cd repo1 &&
167 >a &&
168 git add a &&
169 git commit -m initial
170 ) &&
171 test_tick &&
173 cd repo2 &&
174 git commit --allow-empty -m initial
175 ) &&
176 test_tick &&
178 cd repo1 &&
179 git fetch ../repo2 master &&
180 git merge --allow-unrelated-histories FETCH_HEAD
184 test_expect_success 'custom merge does not lock index' '
185 git reset --hard anchor &&
186 write_script sleep-an-hour.sh <<-\EOF &&
187 sleep 3600 &
188 echo $! >sleep.pid
191 test_write_lines >.gitattributes \
192 "* merge=ours" "text merge=sleep-an-hour" &&
193 test_config merge.ours.driver true &&
194 test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh &&
196 # We are testing that the custom merge driver does not block
197 # index.lock on Windows due to an inherited file handle.
198 # To ensure that the backgrounded process ran sufficiently
199 # long (and has been started in the first place), we do not
200 # ignore the result of the kill command.
201 # By packaging the command in test_when_finished, we get both
202 # the correctness check and the clean-up.
203 test_when_finished "kill \$(cat sleep.pid)" &&
204 git merge master
207 test_done