Side-step line-ending corruption leading to t3032 failures.
[git/dscho.git] / t / t3032-merge-recursive-options.sh
blobc96599a6bb45620274dabfa412fce04a881a2380
1 #!/bin/sh
3 test_description='merge-recursive options
5 * [master] Clarify
6 ! [remote] Remove cruft
7 --
8 + [remote] Remove cruft
9 * [master] Clarify
10 *+ [remote^] Initial revision
11 * ok 1: setup
14 . ./test-lib.sh
16 if test_have_prereq MINGW; then
17 export GREP_OPTIONS=-U
18 SED_OPTIONS=-b
21 test_expect_success 'setup' '
22 conflict_hunks () {
23 sed $SED_OPTIONS -n -e "
24 /^<<<</ b conflict
26 : conflict
28 /^>>>>/ b
30 b conflict
31 " "$@"
32 } &&
34 cat <<-\EOF >text.txt &&
35 Hope, he says, cherishes the soul of him who lives in
36 justice and holiness and is the nurse of his age and the
37 companion of his journey;--hope which is mightiest to sway
38 the restless soul of man.
40 How admirable are his words! And the great blessing of riches, I do
41 not say to every man, but to a good man, is, that he has had no
42 occasion to deceive or to defraud others, either intentionally or
43 unintentionally; and when he departs to the world below he is not in
44 any apprehension about offerings due to the gods or debts which he owes
45 to men. Now to this peace of mind the possession of wealth greatly
46 contributes; and therefore I say, that, setting one thing against
47 another, of the many advantages which wealth has to give, to a man of
48 sense this is in my opinion the greatest.
50 Well said, Cephalus, I replied; but as concerning justice, what is
51 it?--to speak the truth and to pay your debts--no more than this? And
52 even to this are there not exceptions? Suppose that a friend when in
53 his right mind has deposited arms with me and he asks for them when he
54 is not in his right mind, ought I to give them back to him? No one
55 would say that I ought or that I should be right in doing so, any more
56 than they would say that I ought always to speak the truth to one who
57 is in his condition.
59 You are quite right, he replied.
61 But then, I said, speaking the truth and paying your debts is not a
62 correct definition of justice.
64 CEPHALUS - SOCRATES - POLEMARCHUS
66 Quite correct, Socrates, if Simonides is to be believed, said
67 Polemarchus interposing.
69 I fear, said Cephalus, that I must go now, for I have to look after the
70 sacrifices, and I hand over the argument to Polemarchus and the company.
71 EOF
72 git add text.txt &&
73 test_tick &&
74 git commit -m "Initial revision" &&
76 git checkout -b remote &&
77 sed $SED_OPTIONS -e "
78 s/\. /\. /g
79 s/[?] /? /g
80 s/ / /g
81 s/--/---/g
82 s/but as concerning/but as con cerning/
83 /CEPHALUS - SOCRATES - POLEMARCHUS/ d
84 " text.txt >text.txt+ &&
85 mv text.txt+ text.txt &&
86 git commit -a -m "Remove cruft" &&
88 git checkout master &&
89 sed $SED_OPTIONS -e "
90 s/\(not in his right mind\),\(.*\)/\1;\2Q/
91 s/Quite correct\(.*\)/It is too correct\1Q/
92 s/unintentionally/un intentionally/
93 /un intentionally/ s/$/Q/
94 s/Polemarchus interposing./Polemarchus, interposing.Q/
95 /justice and holiness/ s/$/Q/
96 /pay your debts/ s/$/Q/
97 " text.txt | q_to_cr >text.txt+ &&
98 mv text.txt+ text.txt &&
99 git commit -a -m "Clarify" &&
100 git show-branch --all
103 test_expect_success 'naive merge fails' '
104 git read-tree --reset -u HEAD &&
105 test_must_fail git merge-recursive HEAD^ -- HEAD remote &&
106 test_must_fail git update-index --refresh &&
107 grep "<<<<<<" text.txt
110 test_expect_success '--ignore-space-change makes merge succeed' '
111 git read-tree --reset -u HEAD &&
112 git merge-recursive --ignore-space-change HEAD^ -- HEAD remote
115 test_expect_success 'naive cherry-pick fails' '
116 git read-tree --reset -u HEAD &&
117 test_must_fail git cherry-pick --no-commit remote &&
118 git read-tree --reset -u HEAD &&
119 test_must_fail git cherry-pick remote &&
120 test_must_fail git update-index --refresh &&
121 grep "<<<<<<" text.txt
124 test_expect_success '-Xignore-space-change makes cherry-pick succeed' '
125 git read-tree --reset -u HEAD &&
126 git cherry-pick --no-commit -Xignore-space-change remote
129 test_expect_success '--ignore-space-change: our w/s-only change wins' '
130 q_to_cr <<-\EOF >expected &&
131 justice and holiness and is the nurse of his age and theQ
134 git read-tree --reset -u HEAD &&
135 git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
136 grep "justice and holiness" text.txt >actual &&
137 test_cmp expected actual
140 test_expect_success '--ignore-space-change: their real change wins over w/s' '
141 cat <<-\EOF >expected &&
142 it?---to speak the truth and to pay your debts---no more than this? And
145 git read-tree --reset -u HEAD &&
146 git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
147 grep "pay your debts" text.txt >actual &&
148 test_cmp expected actual
151 test_expect_success '--ignore-space-change: does not ignore new spaces' '
152 cat <<-\EOF >expected1 &&
153 Well said, Cephalus, I replied; but as con cerning justice, what is
155 q_to_cr <<-\EOF >expected2 &&
156 un intentionally; and when he departs to the world below he is not inQ
159 git read-tree --reset -u HEAD &&
160 git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
161 grep "Well said" text.txt >actual1 &&
162 grep "when he departs" text.txt >actual2 &&
163 test_cmp expected1 actual1 &&
164 test_cmp expected2 actual2
167 test_expect_success '--ignore-all-space drops their new spaces' '
168 cat <<-\EOF >expected &&
169 Well said, Cephalus, I replied; but as concerning justice, what is
172 git read-tree --reset -u HEAD &&
173 git merge-recursive --ignore-all-space HEAD^ -- HEAD remote &&
174 grep "Well said" text.txt >actual &&
175 test_cmp expected actual
178 test_expect_success '--ignore-all-space keeps our new spaces' '
179 q_to_cr <<-\EOF >expected &&
180 un intentionally; and when he departs to the world below he is not inQ
183 git read-tree --reset -u HEAD &&
184 git merge-recursive --ignore-all-space HEAD^ -- HEAD remote &&
185 grep "when he departs" text.txt >actual &&
186 test_cmp expected actual
189 test_expect_success '--ignore-space-at-eol' '
190 q_to_cr <<-\EOF >expected &&
191 <<<<<<< HEAD
192 is not in his right mind; ought I to give them back to him? No oneQ
193 =======
194 is not in his right mind, ought I to give them back to him? No one
195 >>>>>>> remote
198 git read-tree --reset -u HEAD &&
199 test_must_fail git merge-recursive --ignore-space-at-eol \
200 HEAD^ -- HEAD remote &&
201 conflict_hunks text.txt >actual &&
202 test_cmp expected actual
205 test_done