t / t3412-rebase-root.shon commit Merge branch 'pw/git-p4-jobs' (7bdb748)
   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 'rebase --root expects --onto' '
  26        git checkout -B fail other &&
  27        test_must_fail git rebase --root
  28'
  29
  30test_expect_success 'rebase --root fails with too many args' '
  31        git checkout -B fail other &&
  32        test_must_fail git rebase --onto master --root fail fail
  33'
  34
  35test_expect_success 'setup pre-rebase hook' '
  36        mkdir -p .git/hooks &&
  37        cat >.git/hooks/pre-rebase <<EOF &&
  38#!$SHELL_PATH
  39echo "\$1,\$2" >.git/PRE-REBASE-INPUT
  40EOF
  41        chmod +x .git/hooks/pre-rebase
  42'
  43cat > expect <<EOF
  444
  453
  462
  471
  48EOF
  49
  50test_expect_success 'rebase --root --onto <newbase>' '
  51        git checkout -b work other &&
  52        git rebase --root --onto master &&
  53        git log --pretty=tformat:"%s" > rebased &&
  54        test_cmp expect rebased
  55'
  56
  57test_expect_success 'pre-rebase got correct input (1)' '
  58        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  59'
  60
  61test_expect_success 'rebase --root --onto <newbase> <branch>' '
  62        git branch work2 other &&
  63        git rebase --root --onto master work2 &&
  64        git log --pretty=tformat:"%s" > rebased2 &&
  65        test_cmp expect rebased2
  66'
  67
  68test_expect_success 'pre-rebase got correct input (2)' '
  69        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
  70'
  71
  72test_expect_success 'rebase -i --root --onto <newbase>' '
  73        git checkout -b work3 other &&
  74        git rebase -i --root --onto master &&
  75        git log --pretty=tformat:"%s" > rebased3 &&
  76        test_cmp expect rebased3
  77'
  78
  79test_expect_success 'pre-rebase got correct input (3)' '
  80        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  81'
  82
  83test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
  84        git branch work4 other &&
  85        git rebase -i --root --onto master work4 &&
  86        git log --pretty=tformat:"%s" > rebased4 &&
  87        test_cmp expect rebased4
  88'
  89
  90test_expect_success 'pre-rebase got correct input (4)' '
  91        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
  92'
  93
  94test_expect_success 'rebase -i -p with linear history' '
  95        git checkout -b work5 other &&
  96        git rebase -i -p --root --onto master &&
  97        git log --pretty=tformat:"%s" > rebased5 &&
  98        test_cmp expect rebased5
  99'
 100
 101test_expect_success 'pre-rebase got correct input (5)' '
 102        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
 103'
 104
 105test_expect_success 'set up merge history' '
 106        git checkout other^ &&
 107        git checkout -b side &&
 108        test_commit 5 C &&
 109        git checkout other &&
 110        git merge side
 111'
 112
 113cat > expect-side <<'EOF'
 114commit work6 work6~1 work6^2
 115Merge branch 'side' into other
 116commit work6^2 work6~2
 1175
 118commit work6~1 work6~2
 1194
 120commit work6~2 work6~3
 1213
 122commit work6~3 work6~4
 1232
 124commit work6~4
 1251
 126EOF
 127
 128test_expect_success 'rebase -i -p with merge' '
 129        git checkout -b work6 other &&
 130        git rebase -i -p --root --onto master &&
 131        log_with_names work6 > rebased6 &&
 132        test_cmp expect-side rebased6
 133'
 134
 135test_expect_success 'set up second root and merge' '
 136        git symbolic-ref HEAD refs/heads/third &&
 137        rm .git/index &&
 138        rm A B C &&
 139        test_commit 6 D &&
 140        git checkout other &&
 141        git merge third
 142'
 143
 144cat > expect-third <<'EOF'
 145commit work7 work7~1 work7^2
 146Merge branch 'third' into other
 147commit work7^2 work7~4
 1486
 149commit work7~1 work7~2 work7~1^2
 150Merge branch 'side' into other
 151commit work7~1^2 work7~3
 1525
 153commit work7~2 work7~3
 1544
 155commit work7~3 work7~4
 1563
 157commit work7~4 work7~5
 1582
 159commit work7~5
 1601
 161EOF
 162
 163test_expect_success 'rebase -i -p with two roots' '
 164        git checkout -b work7 other &&
 165        git rebase -i -p --root --onto master &&
 166        log_with_names work7 > rebased7 &&
 167        test_cmp expect-third rebased7
 168'
 169
 170test_expect_success 'setup pre-rebase hook that fails' '
 171        mkdir -p .git/hooks &&
 172        cat >.git/hooks/pre-rebase <<EOF &&
 173#!$SHELL_PATH
 174false
 175EOF
 176        chmod +x .git/hooks/pre-rebase
 177'
 178
 179test_expect_success 'pre-rebase hook stops rebase' '
 180        git checkout -b stops1 other &&
 181        test_must_fail git rebase --root --onto master &&
 182        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
 183        test 0 = $(git rev-list other...stops1 | wc -l)
 184'
 185
 186test_expect_success 'pre-rebase hook stops rebase -i' '
 187        git checkout -b stops2 other &&
 188        test_must_fail git rebase --root --onto master &&
 189        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
 190        test 0 = $(git rev-list other...stops2 | wc -l)
 191'
 192
 193test_expect_success 'remove pre-rebase hook' '
 194        rm -f .git/hooks/pre-rebase
 195'
 196
 197test_expect_success 'set up a conflict' '
 198        git checkout master &&
 199        echo conflict > B &&
 200        git add B &&
 201        git commit -m conflict
 202'
 203
 204test_expect_success 'rebase --root with conflict (first part)' '
 205        git checkout -b conflict1 other &&
 206        test_must_fail git rebase --root --onto master &&
 207        git ls-files -u | grep "B$"
 208'
 209
 210test_expect_success 'fix the conflict' '
 211        echo 3 > B &&
 212        git add B
 213'
 214
 215cat > expect-conflict <<EOF
 2166
 2175
 2184
 2193
 220conflict
 2212
 2221
 223EOF
 224
 225test_expect_success 'rebase --root with conflict (second part)' '
 226        git rebase --continue &&
 227        git log --pretty=tformat:"%s" > conflict1 &&
 228        test_cmp expect-conflict conflict1
 229'
 230
 231test_expect_success 'rebase -i --root with conflict (first part)' '
 232        git checkout -b conflict2 other &&
 233        test_must_fail git rebase -i --root --onto master &&
 234        git ls-files -u | grep "B$"
 235'
 236
 237test_expect_success 'fix the conflict' '
 238        echo 3 > B &&
 239        git add B
 240'
 241
 242test_expect_success 'rebase -i --root with conflict (second part)' '
 243        git rebase --continue &&
 244        git log --pretty=tformat:"%s" > conflict2 &&
 245        test_cmp expect-conflict conflict2
 246'
 247
 248cat >expect-conflict-p <<\EOF
 249commit conflict3 conflict3~1 conflict3^2
 250Merge branch 'third' into other
 251commit conflict3^2 conflict3~4
 2526
 253commit conflict3~1 conflict3~2 conflict3~1^2
 254Merge branch 'side' into other
 255commit conflict3~1^2 conflict3~3
 2565
 257commit conflict3~2 conflict3~3
 2584
 259commit conflict3~3 conflict3~4
 2603
 261commit conflict3~4 conflict3~5
 262conflict
 263commit conflict3~5 conflict3~6
 2642
 265commit conflict3~6
 2661
 267EOF
 268
 269test_expect_success 'rebase -i -p --root with conflict (first part)' '
 270        git checkout -b conflict3 other &&
 271        test_must_fail git rebase -i -p --root --onto master &&
 272        git ls-files -u | grep "B$"
 273'
 274
 275test_expect_success 'fix the conflict' '
 276        echo 3 > B &&
 277        git add B
 278'
 279
 280test_expect_success 'rebase -i -p --root with conflict (second part)' '
 281        git rebase --continue &&
 282        log_with_names conflict3 >out &&
 283        test_cmp expect-conflict-p out
 284'
 285
 286test_done