t / t3404-rebase-interactive.shon commit Fix core.sharedRepository = 2 (8352522)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='git rebase interactive
   7
   8This test runs git rebase "interactively", by faking an edit, and verifies
   9that the result still makes sense.
  10'
  11. ./test-lib.sh
  12
  13# set up two branches like this:
  14#
  15# A - B - C - D - E
  16#   \
  17#     F - G - H
  18#       \
  19#         I
  20#
  21# where B, D and G touch the same file.
  22
  23test_expect_success 'setup' '
  24        : > file1 &&
  25        git add file1 &&
  26        test_tick &&
  27        git commit -m A &&
  28        git tag A &&
  29        echo 1 > file1 &&
  30        test_tick &&
  31        git commit -m B file1 &&
  32        : > file2 &&
  33        git add file2 &&
  34        test_tick &&
  35        git commit -m C &&
  36        echo 2 > file1 &&
  37        test_tick &&
  38        git commit -m D file1 &&
  39        : > file3 &&
  40        git add file3 &&
  41        test_tick &&
  42        git commit -m E &&
  43        git checkout -b branch1 A &&
  44        : > file4 &&
  45        git add file4 &&
  46        test_tick &&
  47        git commit -m F &&
  48        git tag F &&
  49        echo 3 > file1 &&
  50        test_tick &&
  51        git commit -m G file1 &&
  52        : > file5 &&
  53        git add file5 &&
  54        test_tick &&
  55        git commit -m H &&
  56        git checkout -b branch2 F &&
  57        : > file6 &&
  58        git add file6 &&
  59        test_tick &&
  60        git commit -m I &&
  61        git tag I
  62'
  63
  64cat > fake-editor.sh << EOF
  65#!/bin/sh
  66test "\$1" = .git/COMMIT_EDITMSG && {
  67        test -z "\$FAKE_COMMIT_MESSAGE" || echo "\$FAKE_COMMIT_MESSAGE" > "\$1"
  68        exit
  69}
  70test -z "\$FAKE_LINES" && exit
  71grep -v "^#" < "\$1" > "\$1".tmp
  72rm "\$1"
  73cat "\$1".tmp
  74action=pick
  75for line in \$FAKE_LINES; do
  76        case \$line in
  77        squash)
  78                action="\$line";;
  79        *)
  80                echo sed -n "\${line}s/^pick/\$action/p"
  81                sed -n "\${line}p" < "\$1".tmp
  82                sed -n "\${line}s/^pick/\$action/p" < "\$1".tmp >> "\$1"
  83                action=pick;;
  84        esac
  85done
  86EOF
  87
  88chmod a+x fake-editor.sh
  89VISUAL="$(pwd)/fake-editor.sh"
  90export VISUAL
  91
  92test_expect_success 'no changes are a nop' '
  93        git rebase -i F &&
  94        test $(git rev-parse I) = $(git rev-parse HEAD)
  95'
  96
  97test_expect_success 'rebase on top of a non-conflicting commit' '
  98        git checkout branch1 &&
  99        git tag original-branch1 &&
 100        git rebase -i branch2 &&
 101        test file6 = $(git diff --name-only original-branch1) &&
 102        test $(git rev-parse I) = $(git rev-parse HEAD~2)
 103'
 104
 105test_expect_success 'reflog for the branch shows state before rebase' '
 106        test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
 107'
 108
 109test_expect_success 'exchange two commits' '
 110        FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 111        test H = $(git cat-file commit HEAD^ | tail -n 1) &&
 112        test G = $(git cat-file commit HEAD | tail -n 1)
 113'
 114
 115cat > expect << EOF
 116diff --git a/file1 b/file1
 117index e69de29..00750ed 100644
 118--- a/file1
 119+++ b/file1
 120@@ -0,0 +1 @@
 121+3
 122EOF
 123
 124cat > expect2 << EOF
 125<<<<<<< HEAD:file1
 1262
 127=======
 1283
 129>>>>>>> b7ca976... G:file1
 130EOF
 131
 132test_expect_success 'stop on conflicting pick' '
 133        git tag new-branch1 &&
 134        ! git rebase -i master &&
 135        diff -u expect .git/.dotest-merge/patch &&
 136        diff -u expect2 file1 &&
 137        test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
 138        test 0 = $(grep -v "^#" < .git/.dotest-merge/todo | wc -l)
 139'
 140
 141test_expect_success 'abort' '
 142        git rebase --abort &&
 143        test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
 144        ! test -d .git/.dotest-merge
 145'
 146
 147test_expect_success 'retain authorship' '
 148        echo A > file7 &&
 149        git add file7 &&
 150        test_tick &&
 151        GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
 152        git tag twerp &&
 153        git rebase -i --onto master HEAD^ &&
 154        git show HEAD | grep "^Author: Twerp Snog"
 155'
 156
 157test_expect_success 'squash' '
 158        git reset --hard twerp &&
 159        echo B > file7 &&
 160        test_tick &&
 161        GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
 162        echo "******************************" &&
 163        FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&
 164        test B = $(cat file7) &&
 165        test $(git rev-parse HEAD^) = $(git rev-parse master)
 166'
 167
 168test_expect_success 'retain authorship when squashing' '
 169        git show HEAD | grep "^Author: Nitfol"
 170'
 171
 172test_expect_success 'preserve merges with -p' '
 173        git checkout -b to-be-preserved master^ &&
 174        : > unrelated-file &&
 175        git add unrelated-file &&
 176        test_tick &&
 177        git commit -m "unrelated" &&
 178        git checkout -b to-be-rebased master &&
 179        echo B > file1 &&
 180        test_tick &&
 181        git commit -m J file1 &&
 182        test_tick &&
 183        git merge to-be-preserved &&
 184        echo C > file1 &&
 185        test_tick &&
 186        git commit -m K file1 &&
 187        test_tick &&
 188        git rebase -i -p --onto branch1 master &&
 189        test $(git rev-parse HEAD^^2) = $(git rev-parse to-be-preserved) &&
 190        test $(git rev-parse HEAD~3) = $(git rev-parse branch1) &&
 191        test $(git show HEAD:file1) = C &&
 192        test $(git show HEAD~2:file1) = B
 193'
 194
 195test_expect_success '--continue tries to commit' '
 196        test_tick &&
 197        ! git rebase -i --onto new-branch1 HEAD^ &&
 198        echo resolved > file1 &&
 199        git add file1 &&
 200        FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
 201        test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
 202        git show HEAD | grep chouette
 203'
 204
 205test_expect_success 'verbose flag is heeded, even after --continue' '
 206        git reset --hard HEAD@{1} &&
 207        test_tick &&
 208        ! git rebase -v -i --onto new-branch1 HEAD^ &&
 209        echo resolved > file1 &&
 210        git add file1 &&
 211        git rebase --continue > output &&
 212        grep "^ file1 |    2 +-$" output
 213'
 214
 215test_done