t / t3412-rebase-root.shon commit diff --stat: add a test for output with COLUMNS=40 (c4432d5)
   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        test_must_fail git rebase --root
  27'
  28
  29test_expect_success 'setup pre-rebase hook' '
  30        mkdir -p .git/hooks &&
  31        cat >.git/hooks/pre-rebase <<EOF &&
  32#!$SHELL_PATH
  33echo "\$1,\$2" >.git/PRE-REBASE-INPUT
  34EOF
  35        chmod +x .git/hooks/pre-rebase
  36'
  37cat > expect <<EOF
  384
  393
  402
  411
  42EOF
  43
  44test_expect_success 'rebase --root --onto <newbase>' '
  45        git checkout -b work &&
  46        git rebase --root --onto master &&
  47        git log --pretty=tformat:"%s" > rebased &&
  48        test_cmp expect rebased
  49'
  50
  51test_expect_success 'pre-rebase got correct input (1)' '
  52        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  53'
  54
  55test_expect_success 'rebase --root --onto <newbase> <branch>' '
  56        git branch work2 other &&
  57        git rebase --root --onto master work2 &&
  58        git log --pretty=tformat:"%s" > rebased2 &&
  59        test_cmp expect rebased2
  60'
  61
  62test_expect_success 'pre-rebase got correct input (2)' '
  63        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
  64'
  65
  66test_expect_success 'rebase -i --root --onto <newbase>' '
  67        git checkout -b work3 other &&
  68        git rebase -i --root --onto master &&
  69        git log --pretty=tformat:"%s" > rebased3 &&
  70        test_cmp expect rebased3
  71'
  72
  73test_expect_success 'pre-rebase got correct input (3)' '
  74        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  75'
  76
  77test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
  78        git branch work4 other &&
  79        git rebase -i --root --onto master work4 &&
  80        git log --pretty=tformat:"%s" > rebased4 &&
  81        test_cmp expect rebased4
  82'
  83
  84test_expect_success 'pre-rebase got correct input (4)' '
  85        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
  86'
  87
  88test_expect_success 'rebase -i -p with linear history' '
  89        git checkout -b work5 other &&
  90        git rebase -i -p --root --onto master &&
  91        git log --pretty=tformat:"%s" > rebased5 &&
  92        test_cmp expect rebased5
  93'
  94
  95test_expect_success 'pre-rebase got correct input (5)' '
  96        test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
  97'
  98
  99test_expect_success 'set up merge history' '
 100        git checkout other^ &&
 101        git checkout -b side &&
 102        test_commit 5 C &&
 103        git checkout other &&
 104        git merge side
 105'
 106
 107cat > expect-side <<'EOF'
 108commit work6 work6~1 work6^2
 109Merge branch 'side' into other
 110commit work6^2 work6~2
 1115
 112commit work6~1 work6~2
 1134
 114commit work6~2 work6~3
 1153
 116commit work6~3 work6~4
 1172
 118commit work6~4
 1191
 120EOF
 121
 122test_expect_success 'rebase -i -p with merge' '
 123        git checkout -b work6 other &&
 124        git rebase -i -p --root --onto master &&
 125        log_with_names work6 > rebased6 &&
 126        test_cmp expect-side rebased6
 127'
 128
 129test_expect_success 'set up second root and merge' '
 130        git symbolic-ref HEAD refs/heads/third &&
 131        rm .git/index &&
 132        rm A B C &&
 133        test_commit 6 D &&
 134        git checkout other &&
 135        git merge third
 136'
 137
 138cat > expect-third <<'EOF'
 139commit work7 work7~1 work7^2
 140Merge branch 'third' into other
 141commit work7^2 work7~4
 1426
 143commit work7~1 work7~2 work7~1^2
 144Merge branch 'side' into other
 145commit work7~1^2 work7~3
 1465
 147commit work7~2 work7~3
 1484
 149commit work7~3 work7~4
 1503
 151commit work7~4 work7~5
 1522
 153commit work7~5
 1541
 155EOF
 156
 157test_expect_success 'rebase -i -p with two roots' '
 158        git checkout -b work7 other &&
 159        git rebase -i -p --root --onto master &&
 160        log_with_names work7 > rebased7 &&
 161        test_cmp expect-third rebased7
 162'
 163
 164test_expect_success 'setup pre-rebase hook that fails' '
 165        mkdir -p .git/hooks &&
 166        cat >.git/hooks/pre-rebase <<EOF &&
 167#!$SHELL_PATH
 168false
 169EOF
 170        chmod +x .git/hooks/pre-rebase
 171'
 172
 173test_expect_success 'pre-rebase hook stops rebase' '
 174        git checkout -b stops1 other &&
 175        test_must_fail git rebase --root --onto master &&
 176        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
 177        test 0 = $(git rev-list other...stops1 | wc -l)
 178'
 179
 180test_expect_success 'pre-rebase hook stops rebase -i' '
 181        git checkout -b stops2 other &&
 182        test_must_fail git rebase --root --onto master &&
 183        test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
 184        test 0 = $(git rev-list other...stops2 | wc -l)
 185'
 186
 187test_expect_success 'remove pre-rebase hook' '
 188        rm -f .git/hooks/pre-rebase
 189'
 190
 191test_expect_success 'set up a conflict' '
 192        git checkout master &&
 193        echo conflict > B &&
 194        git add B &&
 195        git commit -m conflict
 196'
 197
 198test_expect_success 'rebase --root with conflict (first part)' '
 199        git checkout -b conflict1 other &&
 200        test_must_fail git rebase --root --onto master &&
 201        git ls-files -u | grep "B$"
 202'
 203
 204test_expect_success 'fix the conflict' '
 205        echo 3 > B &&
 206        git add B
 207'
 208
 209cat > expect-conflict <<EOF
 2106
 2115
 2124
 2133
 214conflict
 2152
 2161
 217EOF
 218
 219test_expect_success 'rebase --root with conflict (second part)' '
 220        git rebase --continue &&
 221        git log --pretty=tformat:"%s" > conflict1 &&
 222        test_cmp expect-conflict conflict1
 223'
 224
 225test_expect_success 'rebase -i --root with conflict (first part)' '
 226        git checkout -b conflict2 other &&
 227        test_must_fail git rebase -i --root --onto master &&
 228        git ls-files -u | grep "B$"
 229'
 230
 231test_expect_success 'fix the conflict' '
 232        echo 3 > B &&
 233        git add B
 234'
 235
 236test_expect_success 'rebase -i --root with conflict (second part)' '
 237        git rebase --continue &&
 238        git log --pretty=tformat:"%s" > conflict2 &&
 239        test_cmp expect-conflict conflict2
 240'
 241
 242cat >expect-conflict-p <<\EOF
 243commit conflict3 conflict3~1 conflict3^2
 244Merge branch 'third' into other
 245commit conflict3^2 conflict3~4
 2466
 247commit conflict3~1 conflict3~2 conflict3~1^2
 248Merge branch 'side' into other
 249commit conflict3~1^2 conflict3~3
 2505
 251commit conflict3~2 conflict3~3
 2524
 253commit conflict3~3 conflict3~4
 2543
 255commit conflict3~4 conflict3~5
 256conflict
 257commit conflict3~5 conflict3~6
 2582
 259commit conflict3~6
 2601
 261EOF
 262
 263test_expect_success 'rebase -i -p --root with conflict (first part)' '
 264        git checkout -b conflict3 other &&
 265        test_must_fail git rebase -i -p --root --onto master &&
 266        git ls-files -u | grep "B$"
 267'
 268
 269test_expect_success 'fix the conflict' '
 270        echo 3 > B &&
 271        git add B
 272'
 273
 274test_expect_success 'rebase -i -p --root with conflict (second part)' '
 275        git rebase --continue &&
 276        log_with_names conflict3 >out &&
 277        test_cmp expect-conflict-p out
 278'
 279
 280test_done