t / t6022-merge-rename.shon commit Merge branch 'jc/apply' into next (b312cc8)
   1#!/bin/sh
   2
   3test_description='Merge-recursive merging renames'
   4. ./test-lib.sh
   5
   6if test "$no_python"; then
   7        echo "Skipping: no python => no recursive merge"
   8        test_done
   9        exit 0
  10fi
  11
  12test_expect_success setup \
  13'
  14cat >A <<\EOF &&
  15a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  16b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
  17c cccccccccccccccccccccccccccccccccccccccccccccccc
  18d dddddddddddddddddddddddddddddddddddddddddddddddd
  19e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
  20f ffffffffffffffffffffffffffffffffffffffffffffffff
  21g gggggggggggggggggggggggggggggggggggggggggggggggg
  22h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
  23i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
  24j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
  25k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
  26l llllllllllllllllllllllllllllllllllllllllllllllll
  27m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  28n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
  29o oooooooooooooooooooooooooooooooooooooooooooooooo
  30EOF
  31
  32cat >M <<\EOF &&
  33A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  34B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
  35C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  36D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
  37E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
  38F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  39G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
  40H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
  41I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  42J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
  43K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  44L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  45M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  46N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
  47O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
  48EOF
  49
  50git add A M &&
  51git commit -m initial &&
  52git branch white &&
  53git branch red &&
  54git branch blue &&
  55
  56sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
  57mv A+ A &&
  58git commit -a -m "master updates A" &&
  59
  60git checkout white &&
  61sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
  62sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
  63rm -f A M &&
  64git update-index --add --remove A B M N &&
  65git commit -m "white renames A->B, M->N" &&
  66
  67git checkout red &&
  68sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
  69sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
  70rm -f A M &&
  71git update-index --add --remove A B M N &&
  72git commit -m "red renames A->B, M->N" &&
  73
  74git checkout blue &&
  75sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
  76sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
  77rm -f A M &&
  78git update-index --add --remove A C M N &&
  79git commit -m "blue renames A->C, M->N" &&
  80
  81git checkout master'
  82
  83test_expect_success 'pull renaming branch into unrenaming one' \
  84'
  85        git show-branch
  86        git pull . white && {
  87                echo "BAD: should have conflicted"
  88                exit 1
  89        }
  90        git ls-files -s
  91        test "$(git ls-files -u B | wc -l)" -eq 3 || {
  92                echo "BAD: should have left stages for B"
  93                exit 1  
  94        }
  95        test "$(git ls-files -s N | wc -l)" -eq 1 || {
  96                echo "BAD: should have merged N"
  97                exit 1  
  98        }
  99        sed -ne "/^g/{
 100        p
 101        q
 102        }" B | grep master || {
 103                echo "BAD: should have listed our change first"
 104                exit 1
 105        }
 106        test "$(git diff white N | wc -l)" -eq 0 || {
 107                echo "BAD: should have taken colored branch"
 108                exit 1
 109        }
 110'
 111
 112test_expect_success 'pull renaming branch into another renaming one' \
 113'
 114        rm -f B
 115        git reset --hard
 116        git checkout red
 117        git pull . white && {
 118                echo "BAD: should have conflicted"
 119                exit 1
 120        }
 121        test "$(git ls-files -u B | wc -l)" -eq 3 || {
 122                echo "BAD: should have left stages"
 123                exit 1  
 124        }
 125        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 126                echo "BAD: should have merged N"
 127                exit 1  
 128        }
 129        sed -ne "/^g/{
 130        p
 131        q
 132        }" B | grep red || {
 133                echo "BAD: should have listed our change first"
 134                exit 1
 135        }
 136        test "$(git diff white N | wc -l)" -eq 0 || {
 137                echo "BAD: should have taken colored branch"
 138                exit 1
 139        }
 140'
 141
 142test_expect_success 'pull unrenaming branch into renaming one' \
 143'
 144        git reset --hard
 145        git show-branch
 146        git pull . master && {
 147                echo "BAD: should have conflicted"
 148                exit 1
 149        }
 150        test "$(git ls-files -u B | wc -l)" -eq 3 || {
 151                echo "BAD: should have left stages"
 152                exit 1  
 153        }
 154        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 155                echo "BAD: should have merged N"
 156                exit 1  
 157        }
 158        sed -ne "/^g/{
 159        p
 160        q
 161        }" B | grep red || {
 162                echo "BAD: should have listed our change first"
 163                exit 1
 164        }
 165        test "$(git diff white N | wc -l)" -eq 0 || {
 166                echo "BAD: should have taken colored branch"
 167                exit 1
 168        }
 169'
 170
 171test_expect_success 'pull conflicting renames' \
 172'
 173        git reset --hard
 174        git show-branch
 175        git pull . blue && {
 176                echo "BAD: should have conflicted"
 177                exit 1
 178        }
 179        test "$(git ls-files -u A | wc -l)" -eq 1 || {
 180                echo "BAD: should have left a stage"
 181                exit 1  
 182        }
 183        test "$(git ls-files -u B | wc -l)" -eq 1 || {
 184                echo "BAD: should have left a stage"
 185                exit 1  
 186        }
 187        test "$(git ls-files -u C | wc -l)" -eq 1 || {
 188                echo "BAD: should have left a stage"
 189                exit 1  
 190        }
 191        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 192                echo "BAD: should have merged N"
 193                exit 1  
 194        }
 195        sed -ne "/^g/{
 196        p
 197        q
 198        }" B | grep red || {
 199                echo "BAD: should have listed our change first"
 200                exit 1
 201        }
 202        test "$(git diff white N | wc -l)" -eq 0 || {
 203                echo "BAD: should have taken colored branch"
 204                exit 1
 205        }
 206'
 207
 208test_done