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