Fix commit_tree() buffer leak
[git/vmiklos.git] / t / t6023-merge-file.sh
blobf674c48cab3e80d63b5a5831c667b8e08b542905
1 #!/bin/sh
3 test_description='RCS merge replacement: merge-file'
4 . ./test-lib.sh
6 cat > orig.txt << EOF
7 Dominus regit me,
8 et nihil mihi deerit.
9 In loco pascuae ibi me collocavit,
10 super aquam refectionis educavit me;
11 animam meam convertit,
12 deduxit me super semitas jusitiae,
13 propter nomen suum.
14 EOF
16 cat > new1.txt << EOF
17 Dominus regit me,
18 et nihil mihi deerit.
19 In loco pascuae ibi me collocavit,
20 super aquam refectionis educavit me;
21 animam meam convertit,
22 deduxit me super semitas jusitiae,
23 propter nomen suum.
24 Nam et si ambulavero in medio umbrae mortis,
25 non timebo mala, quoniam tu mecum es:
26 virga tua et baculus tuus ipsa me consolata sunt.
27 EOF
29 cat > new2.txt << EOF
30 Dominus regit me, et nihil mihi deerit.
31 In loco pascuae ibi me collocavit,
32 super aquam refectionis educavit me;
33 animam meam convertit,
34 deduxit me super semitas jusitiae,
35 propter nomen suum.
36 EOF
38 cat > new3.txt << EOF
39 DOMINUS regit me,
40 et nihil mihi deerit.
41 In loco pascuae ibi me collocavit,
42 super aquam refectionis educavit me;
43 animam meam convertit,
44 deduxit me super semitas jusitiae,
45 propter nomen suum.
46 EOF
48 cat > new4.txt << EOF
49 Dominus regit me, et nihil mihi deerit.
50 In loco pascuae ibi me collocavit,
51 super aquam refectionis educavit me;
52 animam meam convertit,
53 deduxit me super semitas jusitiae,
54 EOF
55 printf "propter nomen suum." >> new4.txt
57 cp new1.txt test.txt
58 test_expect_success "merge without conflict" \
59 "git merge-file test.txt orig.txt new2.txt"
61 cp new1.txt test2.txt
62 test_expect_success "merge without conflict (missing LF at EOF)" \
63 "git merge-file test2.txt orig.txt new2.txt"
65 test_expect_success "merge result added missing LF" \
66 "test_cmp test.txt test2.txt"
68 cp test.txt backup.txt
69 test_expect_success "merge with conflicts" \
70 "test_must_fail git merge-file test.txt orig.txt new3.txt"
72 cat > expect.txt << EOF
73 <<<<<<< test.txt
74 Dominus regit me, et nihil mihi deerit.
75 =======
76 DOMINUS regit me,
77 et nihil mihi deerit.
78 >>>>>>> new3.txt
79 In loco pascuae ibi me collocavit,
80 super aquam refectionis educavit me;
81 animam meam convertit,
82 deduxit me super semitas jusitiae,
83 propter nomen suum.
84 Nam et si ambulavero in medio umbrae mortis,
85 non timebo mala, quoniam tu mecum es:
86 virga tua et baculus tuus ipsa me consolata sunt.
87 EOF
89 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
91 cp backup.txt test.txt
92 test_expect_success "merge with conflicts, using -L" \
93 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
95 cat > expect.txt << EOF
96 <<<<<<< 1
97 Dominus regit me, et nihil mihi deerit.
98 =======
99 DOMINUS regit me,
100 et nihil mihi deerit.
101 >>>>>>> new3.txt
102 In loco pascuae ibi me collocavit,
103 super aquam refectionis educavit me;
104 animam meam convertit,
105 deduxit me super semitas jusitiae,
106 propter nomen suum.
107 Nam et si ambulavero in medio umbrae mortis,
108 non timebo mala, quoniam tu mecum es:
109 virga tua et baculus tuus ipsa me consolata sunt.
112 test_expect_success "expected conflict markers, with -L" \
113 "test_cmp test.txt expect.txt"
115 sed "s/ tu / TU /" < new1.txt > new5.txt
116 test_expect_success "conflict in removed tail" \
117 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
119 cat > expect << EOF
120 Dominus regit me,
121 et nihil mihi deerit.
122 In loco pascuae ibi me collocavit,
123 super aquam refectionis educavit me;
124 animam meam convertit,
125 deduxit me super semitas jusitiae,
126 propter nomen suum.
127 <<<<<<< orig.txt
128 =======
129 Nam et si ambulavero in medio umbrae mortis,
130 non timebo mala, quoniam TU mecum es:
131 virga tua et baculus tuus ipsa me consolata sunt.
132 >>>>>>> new5.txt
135 test_expect_success "expected conflict markers" "test_cmp expect out"
137 test_expect_success 'binary files cannot be merged' '
138 test_must_fail git merge-file -p \
139 orig.txt ../test4012.png new1.txt 2> merge.err &&
140 grep "Cannot merge binary files" merge.err
143 sed -e "s/deerit.$/deerit;/" -e "s/me;$/me./" < new5.txt > new6.txt
144 sed -e "s/deerit.$/deerit,/" -e "s/me;$/me,/" < new5.txt > new7.txt
146 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
148 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
149 test 1 = $(grep ======= < output | wc -l)
153 sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
154 sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit --/" < new7.txt > new9.txt
156 test_expect_success 'ZEALOUS_ALNUM' '
158 test_must_fail git merge-file -p \
159 new8.txt new5.txt new9.txt > merge.out &&
160 test 1 = $(grep ======= < merge.out | wc -l)
164 test_done