]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6406-merge-attr.sh
unicode: update the width tables to Unicode 15.1
[thirdparty/git.git] / t / t6406-merge-attr.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Junio C Hamano
4 #
5
6 test_description='per path merge controlled by merge attribute'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13
14 test_expect_success setup '
15
16 for f in text binary union
17 do
18 echo Initial >$f && git add $f || return 1
19 done &&
20 test_tick &&
21 git commit -m Initial &&
22
23 git branch side &&
24 for f in text binary union
25 do
26 echo Main >>$f && git add $f || return 1
27 done &&
28 test_tick &&
29 git commit -m Main &&
30
31 git checkout side &&
32 for f in text binary union
33 do
34 echo Side >>$f && git add $f || return 1
35 done &&
36 test_tick &&
37 git commit -m Side &&
38
39 git tag anchor &&
40
41 cat >./custom-merge <<-\EOF &&
42 #!/bin/sh
43
44 orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
45 (
46 echo "orig is $orig"
47 echo "ours is $ours"
48 echo "theirs is $theirs"
49 echo "path is $path"
50 echo "=== orig ==="
51 cat "$orig"
52 echo "=== ours ==="
53 cat "$ours"
54 echo "=== theirs ==="
55 cat "$theirs"
56 ) >"$ours+"
57 cat "$ours+" >"$ours"
58 rm -f "$ours+"
59 exit "$exit"
60 EOF
61 chmod +x ./custom-merge
62 '
63
64 test_expect_success merge '
65
66 cat >.gitattributes <<-\EOF &&
67 binary -merge
68 union merge=union
69 EOF
70
71 if git merge main
72 then
73 echo Gaah, should have conflicted
74 false
75 else
76 echo Ok, conflicted.
77 fi
78 '
79
80 test_expect_success 'check merge result in index' '
81
82 git ls-files -u | grep binary &&
83 git ls-files -u | grep text &&
84 ! (git ls-files -u | grep union)
85
86 '
87
88 test_expect_success 'check merge result in working tree' '
89
90 git cat-file -p HEAD:binary >binary-orig &&
91 grep "<<<<<<<" text &&
92 cmp binary-orig binary &&
93 ! grep "<<<<<<<" union &&
94 grep Main union &&
95 grep Side union
96
97 '
98
99 test_expect_success 'retry the merge with longer context' '
100 echo text conflict-marker-size=32 >>.gitattributes &&
101 git checkout -m text &&
102 sed -ne "/^\([<=>]\)\1\1\1*/{
103 s/ .*$//
104 p
105 }" >actual text &&
106 grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
107 grep "================================" actual &&
108 grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
109 '
110
111 test_expect_success 'custom merge backend' '
112
113 echo "* merge=union" >.gitattributes &&
114 echo "text merge=custom" >>.gitattributes &&
115
116 git reset --hard anchor &&
117 git config --replace-all \
118 merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
119 git config --replace-all \
120 merge.custom.name "custom merge driver for testing" &&
121
122 git merge main &&
123
124 cmp binary union &&
125 sed -e 1,3d text >check-1 &&
126 o=$(git unpack-file main^:text) &&
127 a=$(git unpack-file side^:text) &&
128 b=$(git unpack-file main:text) &&
129 sh -c "./custom-merge $o $a $b 0 text" &&
130 sed -e 1,3d $a >check-2 &&
131 cmp check-1 check-2 &&
132 rm -f $o $a $b
133 '
134
135 test_expect_success 'custom merge backend' '
136
137 git reset --hard anchor &&
138 git config --replace-all \
139 merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
140 git config --replace-all \
141 merge.custom.name "custom merge driver for testing" &&
142
143 if git merge main
144 then
145 echo "Eh? should have conflicted"
146 false
147 else
148 echo "Ok, conflicted"
149 fi &&
150
151 cmp binary union &&
152 sed -e 1,3d text >check-1 &&
153 o=$(git unpack-file main^:text) &&
154 a=$(git unpack-file anchor:text) &&
155 b=$(git unpack-file main:text) &&
156 sh -c "./custom-merge $o $a $b 0 text" &&
157 sed -e 1,3d $a >check-2 &&
158 cmp check-1 check-2 &&
159 sed -e 1,3d -e 4q $a >check-3 &&
160 echo "path is text" >expect &&
161 cmp expect check-3 &&
162 rm -f $o $a $b
163 '
164
165 test_expect_success 'up-to-date merge without common ancestor' '
166 git init repo1 &&
167 git init repo2 &&
168 test_tick &&
169 (
170 cd repo1 &&
171 >a &&
172 git add a &&
173 git commit -m initial
174 ) &&
175 test_tick &&
176 (
177 cd repo2 &&
178 git commit --allow-empty -m initial
179 ) &&
180 test_tick &&
181 (
182 cd repo1 &&
183 git fetch ../repo2 main &&
184 git merge --allow-unrelated-histories FETCH_HEAD
185 )
186 '
187
188 test_expect_success 'custom merge does not lock index' '
189 git reset --hard anchor &&
190 write_script sleep-an-hour.sh <<-\EOF &&
191 sleep 3600 &
192 echo $! >sleep.pid
193 EOF
194
195 test_write_lines >.gitattributes \
196 "* merge=ours" "text merge=sleep-an-hour" &&
197 test_config merge.ours.driver true &&
198 test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh &&
199
200 # We are testing that the custom merge driver does not block
201 # index.lock on Windows due to an inherited file handle.
202 # To ensure that the backgrounded process ran sufficiently
203 # long (and has been started in the first place), we do not
204 # ignore the result of the kill command.
205 # By packaging the command in test_when_finished, we get both
206 # the correctness check and the clean-up.
207 test_when_finished "kill \$(cat sleep.pid)" &&
208 git merge main
209 '
210
211 test_expect_success 'binary files with union attribute' '
212 git checkout -b bin-main &&
213 printf "base\0" >bin.txt &&
214 echo "bin.txt merge=union" >.gitattributes &&
215 git add bin.txt .gitattributes &&
216 git commit -m base &&
217
218 printf "one\0" >bin.txt &&
219 git commit -am one &&
220
221 git checkout -b bin-side HEAD^ &&
222 printf "two\0" >bin.txt &&
223 git commit -am two &&
224
225 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
226 then
227 test_must_fail git merge bin-main >output
228 else
229 test_must_fail git merge bin-main 2>output
230 fi &&
231 grep -i "warning.*cannot merge.*HEAD vs. bin-main" output
232 '
233
234 test_done