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