t / t3412-rebase-root.shon commit receive-pack: explain what to do when push updates the current branch (3d95d92)
   1#!/bin/sh
   2
   3test_description='git rebase --root
   4
   5Tests if git rebase --root --onto <newparent> can rebase the root commit.
   6'
   7. ./test-lib.sh
   8
   9test_expect_success 'prepare repository' '
  10        test_commit 1 A &&
  11        test_commit 2 A &&
  12        git symbolic-ref HEAD refs/heads/other &&
  13        rm .git/index &&
  14        test_commit 3 B &&
  15        test_commit 1b A 1 &&
  16        test_commit 4 B
  17'
  18
  19test_expect_success 'rebase --root expects --onto' '
  20        test_must_fail git rebase --root
  21'
  22
  23test_expect_success 'setup pre-rebase hook' '
  24        mkdir -p .git/hooks &&
  25        cat >.git/hooks/pre-rebase <<EOF &&
  26#!$SHELL_PATH
  27echo "\$1,\$2" >.git/PRE-REBASE-INPUT
  28EOF
  29        chmod +x .git/hooks/pre-rebase
  30'
  31cat > expect <<EOF
  324
  333
  342
  351
  36EOF
  37
  38test_expect_success 'rebase --root --onto <newbase>' '
  39        git checkout -b work &&
  40        git rebase --root --onto master &&
  41        git log --pretty=tformat:"%s" > rebased &&
  42        test_cmp expect rebased
  43'
  44
  45test_expect_success 'pre-rebase got correct input (1)' '
  46        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  47'
  48
  49test_expect_success 'rebase --root --onto <newbase> <branch>' '
  50        git branch work2 other &&
  51        git rebase --root --onto master work2 &&
  52        git log --pretty=tformat:"%s" > rebased2 &&
  53        test_cmp expect rebased2
  54'
  55
  56test_expect_success 'pre-rebase got correct input (2)' '
  57        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
  58'
  59
  60test_expect_success 'rebase -i --root --onto <newbase>' '
  61        git checkout -b work3 other &&
  62        GIT_EDITOR=: git rebase -i --root --onto master &&
  63        git log --pretty=tformat:"%s" > rebased3 &&
  64        test_cmp expect rebased3
  65'
  66
  67test_expect_success 'pre-rebase got correct input (3)' '
  68        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  69'
  70
  71test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
  72        git branch work4 other &&
  73        GIT_EDITOR=: git rebase -i --root --onto master work4 &&
  74        git log --pretty=tformat:"%s" > rebased4 &&
  75        test_cmp expect rebased4
  76'
  77
  78test_expect_success 'pre-rebase got correct input (4)' '
  79        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
  80'
  81
  82test_expect_success 'rebase -i -p with linear history' '
  83        git checkout -b work5 other &&
  84        GIT_EDITOR=: git rebase -i -p --root --onto master &&
  85        git log --pretty=tformat:"%s" > rebased5 &&
  86        test_cmp expect rebased5
  87'
  88
  89test_expect_success 'pre-rebase got correct input (5)' '
  90        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  91'
  92
  93test_expect_success 'set up merge history' '
  94        git checkout other^ &&
  95        git checkout -b side &&
  96        test_commit 5 C &&
  97        git checkout other &&
  98        git merge side
  99'
 100
 101sed 's/#/ /g' > expect-side <<'EOF'
 102*   Merge branch 'side' into other
 103|\##
 104| * 5
 105* | 4
 106|/##
 107* 3
 108* 2
 109* 1
 110EOF
 111
 112test_expect_success 'rebase -i -p with merge' '
 113        git checkout -b work6 other &&
 114        GIT_EDITOR=: git rebase -i -p --root --onto master &&
 115        git log --graph --topo-order --pretty=tformat:"%s" > rebased6 &&
 116        test_cmp expect-side rebased6
 117'
 118
 119test_expect_success 'set up second root and merge' '
 120        git symbolic-ref HEAD refs/heads/third &&
 121        rm .git/index &&
 122        rm A B C &&
 123        test_commit 6 D &&
 124        git checkout other &&
 125        git merge third
 126'
 127
 128sed 's/#/ /g' > expect-third <<'EOF'
 129*   Merge branch 'third' into other
 130|\##
 131| * 6
 132* |   Merge branch 'side' into other
 133|\ \##
 134| * | 5
 135* | | 4
 136|/ /##
 137* | 3
 138|/##
 139* 2
 140* 1
 141EOF
 142
 143test_expect_success 'rebase -i -p with two roots' '
 144        git checkout -b work7 other &&
 145        GIT_EDITOR=: git rebase -i -p --root --onto master &&
 146        git log --graph --topo-order --pretty=tformat:"%s" > rebased7 &&
 147        test_cmp expect-third rebased7
 148'
 149
 150test_expect_success 'setup pre-rebase hook that fails' '
 151        mkdir -p .git/hooks &&
 152        cat >.git/hooks/pre-rebase <<EOF &&
 153#!$SHELL_PATH
 154false
 155EOF
 156        chmod +x .git/hooks/pre-rebase
 157'
 158
 159test_expect_success 'pre-rebase hook stops rebase' '
 160        git checkout -b stops1 other &&
 161        (
 162                GIT_EDITOR=:
 163                export GIT_EDITOR
 164                test_must_fail git rebase --root --onto master
 165        ) &&
 166        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
 167        test 0 = $(git rev-list other...stops1 | wc -l)
 168'
 169
 170test_expect_success 'pre-rebase hook stops rebase -i' '
 171        git checkout -b stops2 other &&
 172        (
 173                GIT_EDITOR=:
 174                export GIT_EDITOR
 175                test_must_fail git rebase --root --onto master
 176        ) &&
 177        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
 178        test 0 = $(git rev-list other...stops2 | wc -l)
 179'
 180
 181test_expect_success 'remove pre-rebase hook' '
 182        rm -f .git/hooks/pre-rebase
 183'
 184
 185test_expect_success 'set up a conflict' '
 186        git checkout master &&
 187        echo conflict > B &&
 188        git add B &&
 189        git commit -m conflict
 190'
 191
 192test_expect_success 'rebase --root with conflict (first part)' '
 193        git checkout -b conflict1 other &&
 194        test_must_fail git rebase --root --onto master &&
 195        git ls-files -u | grep "B$"
 196'
 197
 198test_expect_success 'fix the conflict' '
 199        echo 3 > B &&
 200        git add B
 201'
 202
 203cat > expect-conflict <<EOF
 2046
 2055
 2064
 2073
 208conflict
 2092
 2101
 211EOF
 212
 213test_expect_success 'rebase --root with conflict (second part)' '
 214        git rebase --continue &&
 215        git log --pretty=tformat:"%s" > conflict1 &&
 216        test_cmp expect-conflict conflict1
 217'
 218
 219test_expect_success 'rebase -i --root with conflict (first part)' '
 220        git checkout -b conflict2 other &&
 221        (
 222                GIT_EDITOR=:
 223                export GIT_EDITOR
 224                test_must_fail git rebase -i --root --onto master
 225        ) &&
 226        git ls-files -u | grep "B$"
 227'
 228
 229test_expect_success 'fix the conflict' '
 230        echo 3 > B &&
 231        git add B
 232'
 233
 234test_expect_success 'rebase -i --root with conflict (second part)' '
 235        git rebase --continue &&
 236        git log --pretty=tformat:"%s" > conflict2 &&
 237        test_cmp expect-conflict conflict2
 238'
 239
 240cat >expect-conflict-p <<\EOF
 241commit conflict3 conflict3~1 conflict3^2
 242Merge branch 'third' into other
 243commit conflict3^2 conflict3~4
 2446
 245commit conflict3~1 conflict3~2 conflict3~1^2
 246Merge branch 'side' into other
 247commit conflict3~1^2 conflict3~3
 2485
 249commit conflict3~2 conflict3~3
 2504
 251commit conflict3~3 conflict3~4
 2523
 253commit conflict3~4 conflict3~5
 254conflict
 255commit conflict3~5 conflict3~6
 2562
 257commit conflict3~6
 2581
 259EOF
 260
 261test_expect_success 'rebase -i -p --root with conflict (first part)' '
 262        git checkout -b conflict3 other &&
 263        (
 264                GIT_EDITOR=:
 265                export GIT_EDITOR
 266                test_must_fail git rebase -i -p --root --onto master
 267        ) &&
 268        git ls-files -u | grep "B$"
 269'
 270
 271test_expect_success 'fix the conflict' '
 272        echo 3 > B &&
 273        git add B
 274'
 275
 276test_expect_success 'rebase -i -p --root with conflict (second part)' '
 277        git rebase --continue &&
 278        git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
 279        git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
 280        test_cmp expect-conflict-p out
 281'
 282
 283test_done