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