t / t6022-merge-rename.shon commit Merge git://git.kernel.org/pub/scm/gitk/gitk (3d990f1)
   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        git reset --hard
 115        git checkout red
 116        git pull . white && {
 117                echo "BAD: should have conflicted"
 118                exit 1
 119        }
 120        test "$(git ls-files -u B | wc -l)" -eq 3 || {
 121                echo "BAD: should have left stages"
 122                exit 1  
 123        }
 124        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 125                echo "BAD: should have merged N"
 126                exit 1  
 127        }
 128        sed -ne "/^g/{
 129        p
 130        q
 131        }" B | grep red || {
 132                echo "BAD: should have listed our change first"
 133                exit 1
 134        }
 135        test "$(git diff white N | wc -l)" -eq 0 || {
 136                echo "BAD: should have taken colored branch"
 137                exit 1
 138        }
 139'
 140
 141test_expect_success 'pull unrenaming branch into renaming one' \
 142'
 143        git reset --hard
 144        git show-branch
 145        git pull . master && {
 146                echo "BAD: should have conflicted"
 147                exit 1
 148        }
 149        test "$(git ls-files -u B | wc -l)" -eq 3 || {
 150                echo "BAD: should have left stages"
 151                exit 1  
 152        }
 153        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 154                echo "BAD: should have merged N"
 155                exit 1  
 156        }
 157        sed -ne "/^g/{
 158        p
 159        q
 160        }" B | grep red || {
 161                echo "BAD: should have listed our change first"
 162                exit 1
 163        }
 164        test "$(git diff white N | wc -l)" -eq 0 || {
 165                echo "BAD: should have taken colored branch"
 166                exit 1
 167        }
 168'
 169
 170test_expect_success 'pull conflicting renames' \
 171'
 172        git reset --hard
 173        git show-branch
 174        git pull . blue && {
 175                echo "BAD: should have conflicted"
 176                exit 1
 177        }
 178        test "$(git ls-files -u A | wc -l)" -eq 1 || {
 179                echo "BAD: should have left a stage"
 180                exit 1  
 181        }
 182        test "$(git ls-files -u B | wc -l)" -eq 1 || {
 183                echo "BAD: should have left a stage"
 184                exit 1  
 185        }
 186        test "$(git ls-files -u C | wc -l)" -eq 1 || {
 187                echo "BAD: should have left a stage"
 188                exit 1  
 189        }
 190        test "$(git ls-files -s N | wc -l)" -eq 1 || {
 191                echo "BAD: should have merged N"
 192                exit 1  
 193        }
 194        sed -ne "/^g/{
 195        p
 196        q
 197        }" B | grep red || {
 198                echo "BAD: should have listed our change first"
 199                exit 1
 200        }
 201        test "$(git diff white N | wc -l)" -eq 0 || {
 202                echo "BAD: should have taken colored branch"
 203                exit 1
 204        }
 205'
 206
 207test_done