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