t / t3412-rebase-root.shon commit Add tests for rebase -i --root without --onto (b64b7fe)
   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
   9log_with_names () {
  10        git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
  11        git name-rev --stdin --name-only --refs=refs/heads/$1
  12}
  13
  14
  15test_expect_success 'prepare repository' '
  16        test_commit 1 A &&
  17        test_commit 2 A &&
  18        git symbolic-ref HEAD refs/heads/other &&
  19        rm .git/index &&
  20        test_commit 3 B &&
  21        test_commit 1b A 1 &&
  22        test_commit 4 B
  23'
  24
  25test_expect_success 'setup pre-rebase hook' '
  26        mkdir -p .git/hooks &&
  27        cat >.git/hooks/pre-rebase <<EOF &&
  28#!$SHELL_PATH
  29echo "\$1,\$2" >.git/PRE-REBASE-INPUT
  30EOF
  31        chmod +x .git/hooks/pre-rebase
  32'
  33cat > expect <<EOF
  344
  353
  362
  371
  38EOF
  39
  40test_expect_success 'rebase --root --onto <newbase>' '
  41        git checkout -b work &&
  42        git rebase --root --onto master &&
  43        git log --pretty=tformat:"%s" > rebased &&
  44        test_cmp expect rebased
  45'
  46
  47test_expect_success 'pre-rebase got correct input (1)' '
  48        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  49'
  50
  51test_expect_success 'rebase --root --onto <newbase> <branch>' '
  52        git branch work2 other &&
  53        git rebase --root --onto master work2 &&
  54        git log --pretty=tformat:"%s" > rebased2 &&
  55        test_cmp expect rebased2
  56'
  57
  58test_expect_success 'pre-rebase got correct input (2)' '
  59        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
  60'
  61
  62test_expect_success 'rebase -i --root --onto <newbase>' '
  63        git checkout -b work3 other &&
  64        git rebase -i --root --onto master &&
  65        git log --pretty=tformat:"%s" > rebased3 &&
  66        test_cmp expect rebased3
  67'
  68
  69test_expect_success 'pre-rebase got correct input (3)' '
  70        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  71'
  72
  73test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
  74        git branch work4 other &&
  75        git rebase -i --root --onto master work4 &&
  76        git log --pretty=tformat:"%s" > rebased4 &&
  77        test_cmp expect rebased4
  78'
  79
  80test_expect_success 'pre-rebase got correct input (4)' '
  81        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
  82'
  83
  84test_expect_success 'rebase -i -p with linear history' '
  85        git checkout -b work5 other &&
  86        git rebase -i -p --root --onto master &&
  87        git log --pretty=tformat:"%s" > rebased5 &&
  88        test_cmp expect rebased5
  89'
  90
  91test_expect_success 'pre-rebase got correct input (5)' '
  92        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  93'
  94
  95test_expect_success 'set up merge history' '
  96        git checkout other^ &&
  97        git checkout -b side &&
  98        test_commit 5 C &&
  99        git checkout other &&
 100        git merge side
 101'
 102
 103cat > expect-side <<'EOF'
 104commit work6 work6~1 work6^2
 105Merge branch 'side' into other
 106commit work6^2 work6~2
 1075
 108commit work6~1 work6~2
 1094
 110commit work6~2 work6~3
 1113
 112commit work6~3 work6~4
 1132
 114commit work6~4
 1151
 116EOF
 117
 118test_expect_success 'rebase -i -p with merge' '
 119        git checkout -b work6 other &&
 120        git rebase -i -p --root --onto master &&
 121        log_with_names work6 > rebased6 &&
 122        test_cmp expect-side rebased6
 123'
 124
 125test_expect_success 'set up second root and merge' '
 126        git symbolic-ref HEAD refs/heads/third &&
 127        rm .git/index &&
 128        rm A B C &&
 129        test_commit 6 D &&
 130        git checkout other &&
 131        git merge third
 132'
 133
 134cat > expect-third <<'EOF'
 135commit work7 work7~1 work7^2
 136Merge branch 'third' into other
 137commit work7^2 work7~4
 1386
 139commit work7~1 work7~2 work7~1^2
 140Merge branch 'side' into other
 141commit work7~1^2 work7~3
 1425
 143commit work7~2 work7~3
 1444
 145commit work7~3 work7~4
 1463
 147commit work7~4 work7~5
 1482
 149commit work7~5
 1501
 151EOF
 152
 153test_expect_success 'rebase -i -p with two roots' '
 154        git checkout -b work7 other &&
 155        git rebase -i -p --root --onto master &&
 156        log_with_names work7 > rebased7 &&
 157        test_cmp expect-third rebased7
 158'
 159
 160test_expect_success 'setup pre-rebase hook that fails' '
 161        mkdir -p .git/hooks &&
 162        cat >.git/hooks/pre-rebase <<EOF &&
 163#!$SHELL_PATH
 164false
 165EOF
 166        chmod +x .git/hooks/pre-rebase
 167'
 168
 169test_expect_success 'pre-rebase hook stops rebase' '
 170        git checkout -b stops1 other &&
 171        test_must_fail git rebase --root --onto master &&
 172        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
 173        test 0 = $(git rev-list other...stops1 | wc -l)
 174'
 175
 176test_expect_success 'pre-rebase hook stops rebase -i' '
 177        git checkout -b stops2 other &&
 178        test_must_fail git rebase --root --onto master &&
 179        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
 180        test 0 = $(git rev-list other...stops2 | wc -l)
 181'
 182
 183test_expect_success 'remove pre-rebase hook' '
 184        rm -f .git/hooks/pre-rebase
 185'
 186
 187test_expect_success 'set up a conflict' '
 188        git checkout master &&
 189        echo conflict > B &&
 190        git add B &&
 191        git commit -m conflict
 192'
 193
 194test_expect_success 'rebase --root with conflict (first part)' '
 195        git checkout -b conflict1 other &&
 196        test_must_fail git rebase --root --onto master &&
 197        git ls-files -u | grep "B$"
 198'
 199
 200test_expect_success 'fix the conflict' '
 201        echo 3 > B &&
 202        git add B
 203'
 204
 205cat > expect-conflict <<EOF
 2066
 2075
 2084
 2093
 210conflict
 2112
 2121
 213EOF
 214
 215test_expect_success 'rebase --root with conflict (second part)' '
 216        git rebase --continue &&
 217        git log --pretty=tformat:"%s" > conflict1 &&
 218        test_cmp expect-conflict conflict1
 219'
 220
 221test_expect_success 'rebase -i --root with conflict (first part)' '
 222        git checkout -b conflict2 other &&
 223        test_must_fail git rebase -i --root --onto master &&
 224        git ls-files -u | grep "B$"
 225'
 226
 227test_expect_success 'fix the conflict' '
 228        echo 3 > B &&
 229        git add B
 230'
 231
 232test_expect_success 'rebase -i --root with conflict (second part)' '
 233        git rebase --continue &&
 234        git log --pretty=tformat:"%s" > conflict2 &&
 235        test_cmp expect-conflict conflict2
 236'
 237
 238cat >expect-conflict-p <<\EOF
 239commit conflict3 conflict3~1 conflict3^2
 240Merge branch 'third' into other
 241commit conflict3^2 conflict3~4
 2426
 243commit conflict3~1 conflict3~2 conflict3~1^2
 244Merge branch 'side' into other
 245commit conflict3~1^2 conflict3~3
 2465
 247commit conflict3~2 conflict3~3
 2484
 249commit conflict3~3 conflict3~4
 2503
 251commit conflict3~4 conflict3~5
 252conflict
 253commit conflict3~5 conflict3~6
 2542
 255commit conflict3~6
 2561
 257EOF
 258
 259test_expect_success 'rebase -i -p --root with conflict (first part)' '
 260        git checkout -b conflict3 other &&
 261        test_must_fail git rebase -i -p --root --onto master &&
 262        git ls-files -u | grep "B$"
 263'
 264
 265test_expect_success 'fix the conflict' '
 266        echo 3 > B &&
 267        git add B
 268'
 269
 270test_expect_success 'rebase -i -p --root with conflict (second part)' '
 271        git rebase --continue &&
 272        log_with_names conflict3 >out &&
 273        test_cmp expect-conflict-p out
 274'
 275
 276test_done