Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Johannes E. Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='git rebase interactive |
| 7 | |
| 8 | This test runs git rebase "interactively", by faking an edit, and verifies |
| 9 | that the result still makes sense. |
Jonathan Nieder | 99b028e | 2010-10-31 02:39:51 -0500 | [diff] [blame] | 10 | |
| 11 | Initial setup: |
| 12 | |
| 13 | one - two - three - four (conflict-branch) |
| 14 | / |
| 15 | A - B - C - D - E (master) |
| 16 | | \ |
| 17 | | F - G - H (branch1) |
| 18 | | \ |
| 19 | |\ I (branch2) |
| 20 | | \ |
| 21 | | J - K - L - M (no-conflict-branch) |
| 22 | \ |
| 23 | N - O - P (no-ff-branch) |
| 24 | |
| 25 | where A, B, D and G all touch file1, and one, two, three, four all |
| 26 | touch file "conflict". |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 27 | ' |
| 28 | . ./test-lib.sh |
| 29 | |
Jeff King | eaf0551 | 2009-08-09 04:37:52 -0400 | [diff] [blame] | 30 | . "$TEST_DIRECTORY"/lib-rebase.sh |
Johannes Schindelin | 29a0334 | 2009-01-27 23:34:29 +0100 | [diff] [blame] | 31 | |
Jonathan Nieder | 5c947e2 | 2010-10-31 02:40:30 -0500 | [diff] [blame] | 32 | test_cmp_rev () { |
Junio C Hamano | 56641f1 | 2010-11-09 15:20:20 -0800 | [diff] [blame] | 33 | git rev-parse --verify "$1" >expect.rev && |
| 34 | git rev-parse --verify "$2" >actual.rev && |
Jonathan Nieder | 5c947e2 | 2010-10-31 02:40:30 -0500 | [diff] [blame] | 35 | test_cmp expect.rev actual.rev |
| 36 | } |
| 37 | |
Johannes Schindelin | 29a0334 | 2009-01-27 23:34:29 +0100 | [diff] [blame] | 38 | set_fake_editor |
| 39 | |
Marc Branchaud | b499549 | 2010-03-24 16:34:04 -0400 | [diff] [blame] | 40 | # WARNING: Modifications to the initial repository can change the SHA ID used |
| 41 | # in the expect2 file for the 'stop on conflicting pick' test. |
| 42 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 43 | test_expect_success 'setup' ' |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 44 | test_commit A file1 && |
| 45 | test_commit B file1 && |
| 46 | test_commit C file2 && |
| 47 | test_commit D file1 && |
| 48 | test_commit E file3 && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 49 | git checkout -b branch1 A && |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 50 | test_commit F file4 && |
| 51 | test_commit G file1 && |
| 52 | test_commit H file5 && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 53 | git checkout -b branch2 F && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 54 | test_commit I file6 && |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 55 | git checkout -b conflict-branch A && |
Jonathan Nieder | 391a825 | 2010-10-31 02:38:25 -0500 | [diff] [blame] | 56 | test_commit one conflict && |
| 57 | test_commit two conflict && |
| 58 | test_commit three conflict && |
| 59 | test_commit four conflict && |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 60 | git checkout -b no-conflict-branch A && |
Jonathan Nieder | 391a825 | 2010-10-31 02:38:25 -0500 | [diff] [blame] | 61 | test_commit J fileJ && |
| 62 | test_commit K fileK && |
| 63 | test_commit L fileL && |
| 64 | test_commit M fileM && |
Marc Branchaud | b499549 | 2010-03-24 16:34:04 -0400 | [diff] [blame] | 65 | git checkout -b no-ff-branch A && |
Jonathan Nieder | 391a825 | 2010-10-31 02:38:25 -0500 | [diff] [blame] | 66 | test_commit N fileN && |
| 67 | test_commit O fileO && |
| 68 | test_commit P fileP |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 69 | ' |
| 70 | |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 71 | # "exec" commands are ran with the user shell by default, but this may |
| 72 | # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work |
| 73 | # to create a file. Unseting SHELL avoids such non-portable behavior |
Robin H. Johnson | 5cd3e10 | 2010-12-27 08:03:43 +0000 | [diff] [blame] | 74 | # in tests. It must be exported for it to take effect where needed. |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 75 | SHELL= |
Robin H. Johnson | 5cd3e10 | 2010-12-27 08:03:43 +0000 | [diff] [blame] | 76 | export SHELL |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 77 | |
| 78 | test_expect_success 'rebase -i with the exec command' ' |
| 79 | git checkout master && |
| 80 | ( |
| 81 | FAKE_LINES="1 exec_>touch-one |
| 82 | 2 exec_>touch-two exec_false exec_>touch-three |
| 83 | 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && |
| 84 | export FAKE_LINES && |
| 85 | test_must_fail git rebase -i A |
| 86 | ) && |
Matthieu Moy | 2caf20c | 2010-08-10 17:17:52 +0200 | [diff] [blame] | 87 | test_path_is_file touch-one && |
| 88 | test_path_is_file touch-two && |
| 89 | test_path_is_missing touch-three " (should have stopped before)" && |
Jonathan Nieder | 5c947e2 | 2010-10-31 02:40:30 -0500 | [diff] [blame] | 90 | test_cmp_rev C HEAD && |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 91 | git rebase --continue && |
Matthieu Moy | 2caf20c | 2010-08-10 17:17:52 +0200 | [diff] [blame] | 92 | test_path_is_file touch-three && |
| 93 | test_path_is_file "touch-file name with spaces" && |
| 94 | test_path_is_file touch-after-semicolon && |
Jonathan Nieder | 5c947e2 | 2010-10-31 02:40:30 -0500 | [diff] [blame] | 95 | test_cmp_rev master HEAD && |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 96 | rm -f touch-* |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'rebase -i with the exec command runs from tree root' ' |
| 100 | git checkout master && |
Jens Lehmann | c2e0940 | 2010-09-06 20:41:06 +0200 | [diff] [blame] | 101 | mkdir subdir && (cd subdir && |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 102 | FAKE_LINES="1 exec_>touch-subdir" \ |
Jens Lehmann | c2e0940 | 2010-09-06 20:41:06 +0200 | [diff] [blame] | 103 | git rebase -i HEAD^ |
| 104 | ) && |
Matthieu Moy | 2caf20c | 2010-08-10 17:17:52 +0200 | [diff] [blame] | 105 | test_path_is_file touch-subdir && |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 106 | rm -fr subdir |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'rebase -i with the exec command checks tree cleanness' ' |
| 110 | git checkout master && |
| 111 | ( |
| 112 | FAKE_LINES="exec_echo_foo_>file1 1" && |
| 113 | export FAKE_LINES && |
| 114 | test_must_fail git rebase -i HEAD^ |
| 115 | ) && |
Jonathan Nieder | 5c947e2 | 2010-10-31 02:40:30 -0500 | [diff] [blame] | 116 | test_cmp_rev master^ HEAD && |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 117 | git reset --hard && |
| 118 | git rebase --continue |
| 119 | ' |
| 120 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 121 | test_expect_success 'no changes are a nop' ' |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 122 | git checkout branch2 && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 123 | git rebase -i F && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 124 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 125 | test $(git rev-parse I) = $(git rev-parse HEAD) |
| 126 | ' |
| 127 | |
Johannes Schindelin | c9e6589 | 2007-08-01 23:31:03 +0100 | [diff] [blame] | 128 | test_expect_success 'test the [branch] option' ' |
| 129 | git checkout -b dead-end && |
| 130 | git rm file6 && |
| 131 | git commit -m "stop here" && |
| 132 | git rebase -i F branch2 && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 133 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && |
| 134 | test $(git rev-parse I) = $(git rev-parse branch2) && |
Johannes Schindelin | c9e6589 | 2007-08-01 23:31:03 +0100 | [diff] [blame] | 135 | test $(git rev-parse I) = $(git rev-parse HEAD) |
| 136 | ' |
| 137 | |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 138 | test_expect_success 'test --onto <branch>' ' |
| 139 | git checkout -b test-onto branch2 && |
| 140 | git rebase -i --onto branch1 F && |
| 141 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && |
| 142 | test $(git rev-parse HEAD^) = $(git rev-parse branch1) && |
| 143 | test $(git rev-parse I) = $(git rev-parse branch2) |
| 144 | ' |
| 145 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 146 | test_expect_success 'rebase on top of a non-conflicting commit' ' |
| 147 | git checkout branch1 && |
| 148 | git tag original-branch1 && |
| 149 | git rebase -i branch2 && |
| 150 | test file6 = $(git diff --name-only original-branch1) && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 151 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
| 152 | test $(git rev-parse I) = $(git rev-parse branch2) && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 153 | test $(git rev-parse I) = $(git rev-parse HEAD~2) |
| 154 | ' |
| 155 | |
Johannes Schindelin | 68a163c | 2007-06-25 18:58:28 +0100 | [diff] [blame] | 156 | test_expect_success 'reflog for the branch shows state before rebase' ' |
| 157 | test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1) |
| 158 | ' |
| 159 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 160 | test_expect_success 'exchange two commits' ' |
| 161 | FAKE_LINES="2 1" git rebase -i HEAD~2 && |
Jeff King | b4ce54f | 2008-03-12 17:34:34 -0400 | [diff] [blame] | 162 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 163 | test G = $(git cat-file commit HEAD | sed -ne \$p) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 164 | ' |
| 165 | |
| 166 | cat > expect << EOF |
| 167 | diff --git a/file1 b/file1 |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 168 | index f70f10e..fd79235 100644 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 169 | --- a/file1 |
| 170 | +++ b/file1 |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 171 | @@ -1 +1 @@ |
| 172 | -A |
| 173 | +G |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 174 | EOF |
| 175 | |
| 176 | cat > expect2 << EOF |
Martin Renold | 606475f | 2009-07-01 22:18:04 +0200 | [diff] [blame] | 177 | <<<<<<< HEAD |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 178 | D |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 179 | ======= |
Michael Haggerty | 163f392 | 2009-12-07 05:22:58 +0100 | [diff] [blame] | 180 | G |
Marc Branchaud | b499549 | 2010-03-24 16:34:04 -0400 | [diff] [blame] | 181 | >>>>>>> 5d18e54... G |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 182 | EOF |
| 183 | |
| 184 | test_expect_success 'stop on conflicting pick' ' |
| 185 | git tag new-branch1 && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 186 | test_must_fail git rebase -i master && |
| 187 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && |
Johannes Schindelin | 28ed6e7 | 2008-07-16 03:33:44 +0200 | [diff] [blame] | 188 | test_cmp expect .git/rebase-merge/patch && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 189 | test_cmp expect2 file1 && |
Nanako Shiraishi | 0cb0e14 | 2008-09-03 17:59:27 +0900 | [diff] [blame] | 190 | test "$(git diff --name-status | |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 191 | sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 && |
Johannes Schindelin | 28ed6e7 | 2008-07-16 03:33:44 +0200 | [diff] [blame] | 192 | test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) && |
| 193 | test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 194 | ' |
| 195 | |
| 196 | test_expect_success 'abort' ' |
| 197 | git rebase --abort && |
| 198 | test $(git rev-parse new-branch1) = $(git rev-parse HEAD) && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 199 | test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && |
Matthieu Moy | 2caf20c | 2010-08-10 17:17:52 +0200 | [diff] [blame] | 200 | test_path_is_missing .git/rebase-merge |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 201 | ' |
| 202 | |
Ian Ward Comfort | b096374 | 2010-06-08 01:16:11 -0700 | [diff] [blame] | 203 | test_expect_success 'abort with error when new base cannot be checked out' ' |
| 204 | git rm --cached file1 && |
| 205 | git commit -m "remove file in base" && |
| 206 | test_must_fail git rebase -i master > output 2>&1 && |
Matthieu Moy | e6c111b | 2010-08-11 10:38:07 +0200 | [diff] [blame] | 207 | grep "The following untracked working tree files would be overwritten by checkout:" \ |
Ian Ward Comfort | b096374 | 2010-06-08 01:16:11 -0700 | [diff] [blame] | 208 | output && |
Matthieu Moy | e6c111b | 2010-08-11 10:38:07 +0200 | [diff] [blame] | 209 | grep "file1" output && |
Matthieu Moy | 2caf20c | 2010-08-10 17:17:52 +0200 | [diff] [blame] | 210 | test_path_is_missing .git/rebase-merge && |
Ian Ward Comfort | b096374 | 2010-06-08 01:16:11 -0700 | [diff] [blame] | 211 | git reset --hard HEAD^ |
| 212 | ' |
| 213 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 214 | test_expect_success 'retain authorship' ' |
| 215 | echo A > file7 && |
| 216 | git add file7 && |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 217 | test_tick && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 218 | GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && |
| 219 | git tag twerp && |
| 220 | git rebase -i --onto master HEAD^ && |
| 221 | git show HEAD | grep "^Author: Twerp Snog" |
| 222 | ' |
| 223 | |
| 224 | test_expect_success 'squash' ' |
| 225 | git reset --hard twerp && |
| 226 | echo B > file7 && |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 227 | test_tick && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 228 | GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && |
| 229 | echo "******************************" && |
Michael Haggerty | 5065ed2 | 2010-01-14 06:54:49 +0100 | [diff] [blame] | 230 | FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ |
Michael Haggerty | 959c0d0 | 2010-01-14 06:54:48 +0100 | [diff] [blame] | 231 | git rebase -i --onto master HEAD~2 && |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 232 | test B = $(cat file7) && |
| 233 | test $(git rev-parse HEAD^) = $(git rev-parse master) |
| 234 | ' |
| 235 | |
| 236 | test_expect_success 'retain authorship when squashing' ' |
Johannes Schindelin | 81ab1cb | 2007-09-30 00:34:23 +0100 | [diff] [blame] | 237 | git show HEAD | grep "^Author: Twerp Snog" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 238 | ' |
| 239 | |
Johannes Schindelin | 34454e8 | 2007-12-17 21:01:25 +0000 | [diff] [blame] | 240 | test_expect_success '-p handles "no changes" gracefully' ' |
| 241 | HEAD=$(git rev-parse HEAD) && |
| 242 | git rebase -i -p HEAD^ && |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 243 | git update-index --refresh && |
| 244 | git diff-files --quiet && |
| 245 | git diff-index --quiet --cached HEAD -- && |
Johannes Schindelin | 34454e8 | 2007-12-17 21:01:25 +0000 | [diff] [blame] | 246 | test $HEAD = $(git rev-parse HEAD) |
| 247 | ' |
| 248 | |
Jonathan Nieder | cddb42d | 2010-05-31 20:43:35 -0500 | [diff] [blame] | 249 | test_expect_failure 'exchange two commits with -p' ' |
| 250 | FAKE_LINES="2 1" git rebase -i -p HEAD~2 && |
| 251 | test H = $(git cat-file commit HEAD^ | sed -ne \$p) && |
| 252 | test G = $(git cat-file commit HEAD | sed -ne \$p) |
| 253 | ' |
| 254 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 255 | test_expect_success 'preserve merges with -p' ' |
| 256 | git checkout -b to-be-preserved master^ && |
| 257 | : > unrelated-file && |
| 258 | git add unrelated-file && |
| 259 | test_tick && |
| 260 | git commit -m "unrelated" && |
Stephan Beyer | 5352a82 | 2008-07-12 17:47:31 +0200 | [diff] [blame] | 261 | git checkout -b another-branch master && |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 262 | echo B > file1 && |
| 263 | test_tick && |
| 264 | git commit -m J file1 && |
| 265 | test_tick && |
| 266 | git merge to-be-preserved && |
| 267 | echo C > file1 && |
| 268 | test_tick && |
| 269 | git commit -m K file1 && |
Stephan Beyer | 5352a82 | 2008-07-12 17:47:31 +0200 | [diff] [blame] | 270 | echo D > file1 && |
| 271 | test_tick && |
| 272 | git commit -m L1 file1 && |
| 273 | git checkout HEAD^ && |
| 274 | echo 1 > unrelated-file && |
| 275 | test_tick && |
| 276 | git commit -m L2 unrelated-file && |
| 277 | test_tick && |
| 278 | git merge another-branch && |
| 279 | echo E > file1 && |
| 280 | test_tick && |
| 281 | git commit -m M file1 && |
| 282 | git checkout -b to-be-rebased && |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 283 | test_tick && |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 284 | git rebase -i -p --onto branch1 master && |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 285 | git update-index --refresh && |
| 286 | git diff-files --quiet && |
| 287 | git diff-index --quiet --cached HEAD -- && |
Stephan Beyer | 5352a82 | 2008-07-12 17:47:31 +0200 | [diff] [blame] | 288 | test $(git rev-parse HEAD~6) = $(git rev-parse branch1) && |
| 289 | test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) && |
| 290 | test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) && |
| 291 | test $(git show HEAD~5:file1) = B && |
| 292 | test $(git show HEAD~3:file1) = C && |
| 293 | test $(git show HEAD:file1) = E && |
| 294 | test $(git show HEAD:unrelated-file) = 1 |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 295 | ' |
| 296 | |
Thomas Rast | a96dc01 | 2008-08-13 23:41:24 +0200 | [diff] [blame] | 297 | test_expect_success 'edit ancestor with -p' ' |
Andrew Wong | 12bf828 | 2011-06-18 18:12:01 -0400 | [diff] [blame] | 298 | FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && |
Thomas Rast | a96dc01 | 2008-08-13 23:41:24 +0200 | [diff] [blame] | 299 | echo 2 > unrelated-file && |
| 300 | test_tick && |
| 301 | git commit -m L2-modified --amend unrelated-file && |
| 302 | git rebase --continue && |
| 303 | git update-index --refresh && |
| 304 | git diff-files --quiet && |
| 305 | git diff-index --quiet --cached HEAD -- && |
| 306 | test $(git show HEAD:unrelated-file) = 2 |
| 307 | ' |
| 308 | |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 309 | test_expect_success '--continue tries to commit' ' |
| 310 | test_tick && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 311 | test_must_fail git rebase -i --onto new-branch1 HEAD^ && |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 312 | echo resolved > file1 && |
| 313 | git add file1 && |
| 314 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && |
| 315 | test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) && |
| 316 | git show HEAD | grep chouette |
| 317 | ' |
| 318 | |
Johannes Schindelin | 8e4a91b | 2007-07-08 03:02:47 +0100 | [diff] [blame] | 319 | test_expect_success 'verbose flag is heeded, even after --continue' ' |
Jeff King | 53f2ffa | 2011-05-27 16:16:14 -0400 | [diff] [blame] | 320 | git reset --hard master@{1} && |
Johannes Schindelin | 8e4a91b | 2007-07-08 03:02:47 +0100 | [diff] [blame] | 321 | test_tick && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 322 | test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && |
Johannes Schindelin | 8e4a91b | 2007-07-08 03:02:47 +0100 | [diff] [blame] | 323 | echo resolved > file1 && |
| 324 | git add file1 && |
| 325 | git rebase --continue > output && |
| 326 | grep "^ file1 | 2 +-$" output |
| 327 | ' |
| 328 | |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 329 | test_expect_success 'multi-squash only fires up editor once' ' |
| 330 | base=$(git rev-parse HEAD~4) && |
| 331 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ |
Michael Haggerty | 959c0d0 | 2010-01-14 06:54:48 +0100 | [diff] [blame] | 332 | EXPECT_HEADER_COUNT=4 \ |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 333 | git rebase -i $base && |
| 334 | test $base = $(git rev-parse HEAD^) && |
| 335 | test 1 = $(git show | grep ONCE | wc -l) |
| 336 | ' |
| 337 | |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 338 | test_expect_success 'multi-fixup does not fire up editor' ' |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 339 | git checkout -b multi-fixup E && |
| 340 | base=$(git rev-parse HEAD~4) && |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 341 | FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 342 | git rebase -i $base && |
| 343 | test $base = $(git rev-parse HEAD^) && |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 344 | test 0 = $(git show | grep NEVER | wc -l) && |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 345 | git checkout to-be-rebased && |
| 346 | git branch -D multi-fixup |
| 347 | ' |
| 348 | |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 349 | test_expect_success 'commit message used after conflict' ' |
| 350 | git checkout -b conflict-fixup conflict-branch && |
| 351 | base=$(git rev-parse HEAD~4) && |
| 352 | ( |
| 353 | FAKE_LINES="1 fixup 3 fixup 4" && |
| 354 | export FAKE_LINES && |
| 355 | test_must_fail git rebase -i $base |
| 356 | ) && |
| 357 | echo three > conflict && |
| 358 | git add conflict && |
| 359 | FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ |
| 360 | git rebase --continue && |
| 361 | test $base = $(git rev-parse HEAD^) && |
| 362 | test 1 = $(git show | grep ONCE | wc -l) && |
| 363 | git checkout to-be-rebased && |
| 364 | git branch -D conflict-fixup |
| 365 | ' |
| 366 | |
| 367 | test_expect_success 'commit message retained after conflict' ' |
| 368 | git checkout -b conflict-squash conflict-branch && |
| 369 | base=$(git rev-parse HEAD~4) && |
| 370 | ( |
| 371 | FAKE_LINES="1 fixup 3 squash 4" && |
| 372 | export FAKE_LINES && |
| 373 | test_must_fail git rebase -i $base |
| 374 | ) && |
| 375 | echo three > conflict && |
| 376 | git add conflict && |
| 377 | FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ |
| 378 | git rebase --continue && |
| 379 | test $base = $(git rev-parse HEAD^) && |
| 380 | test 2 = $(git show | grep TWICE | wc -l) && |
| 381 | git checkout to-be-rebased && |
| 382 | git branch -D conflict-squash |
| 383 | ' |
| 384 | |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 385 | cat > expect-squash-fixup << EOF |
| 386 | B |
| 387 | |
| 388 | D |
| 389 | |
| 390 | ONCE |
| 391 | EOF |
| 392 | |
| 393 | test_expect_success 'squash and fixup generate correct log messages' ' |
| 394 | git checkout -b squash-fixup E && |
| 395 | base=$(git rev-parse HEAD~4) && |
| 396 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ |
Michael Haggerty | 959c0d0 | 2010-01-14 06:54:48 +0100 | [diff] [blame] | 397 | EXPECT_HEADER_COUNT=4 \ |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 398 | git rebase -i $base && |
| 399 | git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && |
| 400 | test_cmp expect-squash-fixup actual-squash-fixup && |
| 401 | git checkout to-be-rebased && |
| 402 | git branch -D squash-fixup |
| 403 | ' |
| 404 | |
Michael Haggerty | 234b3da | 2010-01-12 16:38:36 +0100 | [diff] [blame] | 405 | test_expect_success 'squash ignores comments' ' |
| 406 | git checkout -b skip-comments E && |
| 407 | base=$(git rev-parse HEAD~4) && |
| 408 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ |
| 409 | EXPECT_HEADER_COUNT=4 \ |
| 410 | git rebase -i $base && |
| 411 | test $base = $(git rev-parse HEAD^) && |
| 412 | test 1 = $(git show | grep ONCE | wc -l) && |
| 413 | git checkout to-be-rebased && |
| 414 | git branch -D skip-comments |
| 415 | ' |
| 416 | |
| 417 | test_expect_success 'squash ignores blank lines' ' |
| 418 | git checkout -b skip-blank-lines E && |
| 419 | base=$(git rev-parse HEAD~4) && |
| 420 | FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ |
| 421 | EXPECT_HEADER_COUNT=4 \ |
| 422 | git rebase -i $base && |
| 423 | test $base = $(git rev-parse HEAD^) && |
| 424 | test 1 = $(git show | grep ONCE | wc -l) && |
| 425 | git checkout to-be-rebased && |
| 426 | git branch -D skip-blank-lines |
| 427 | ' |
| 428 | |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 429 | test_expect_success 'squash works as expected' ' |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 430 | git checkout -b squash-works no-conflict-branch && |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 431 | one=$(git rev-parse HEAD~3) && |
Michael Haggerty | 5065ed2 | 2010-01-14 06:54:49 +0100 | [diff] [blame] | 432 | FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ |
Michael Haggerty | 959c0d0 | 2010-01-14 06:54:48 +0100 | [diff] [blame] | 433 | git rebase -i HEAD~3 && |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 434 | test $one = $(git rev-parse HEAD~2) |
| 435 | ' |
| 436 | |
| 437 | test_expect_success 'interrupted squash works as expected' ' |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 438 | git checkout -b interrupted-squash conflict-branch && |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 439 | one=$(git rev-parse HEAD~3) && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 440 | ( |
| 441 | FAKE_LINES="1 squash 3 2" && |
| 442 | export FAKE_LINES && |
| 443 | test_must_fail git rebase -i HEAD~3 |
| 444 | ) && |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 445 | (echo one; echo two; echo four) > conflict && |
| 446 | git add conflict && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 447 | test_must_fail git rebase --continue && |
Johannes Schindelin | fb47cfb | 2007-07-24 21:43:09 +0100 | [diff] [blame] | 448 | echo resolved > conflict && |
| 449 | git add conflict && |
| 450 | git rebase --continue && |
| 451 | test $one = $(git rev-parse HEAD~2) |
| 452 | ' |
| 453 | |
Johannes Schindelin | 1d25c8c | 2007-08-23 09:55:41 +0100 | [diff] [blame] | 454 | test_expect_success 'interrupted squash works as expected (case 2)' ' |
Michael Haggerty | 6c4c44c | 2010-01-14 06:54:56 +0100 | [diff] [blame] | 455 | git checkout -b interrupted-squash2 conflict-branch && |
Johannes Schindelin | 1d25c8c | 2007-08-23 09:55:41 +0100 | [diff] [blame] | 456 | one=$(git rev-parse HEAD~3) && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 457 | ( |
| 458 | FAKE_LINES="3 squash 1 2" && |
| 459 | export FAKE_LINES && |
| 460 | test_must_fail git rebase -i HEAD~3 |
| 461 | ) && |
Johannes Schindelin | 1d25c8c | 2007-08-23 09:55:41 +0100 | [diff] [blame] | 462 | (echo one; echo four) > conflict && |
| 463 | git add conflict && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 464 | test_must_fail git rebase --continue && |
Johannes Schindelin | 1d25c8c | 2007-08-23 09:55:41 +0100 | [diff] [blame] | 465 | (echo one; echo two; echo four) > conflict && |
| 466 | git add conflict && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 467 | test_must_fail git rebase --continue && |
Johannes Schindelin | 1d25c8c | 2007-08-23 09:55:41 +0100 | [diff] [blame] | 468 | echo resolved > conflict && |
| 469 | git add conflict && |
| 470 | git rebase --continue && |
| 471 | test $one = $(git rev-parse HEAD~2) |
| 472 | ' |
| 473 | |
Johannes Schindelin | 96ffe89 | 2007-08-01 15:59:35 +0100 | [diff] [blame] | 474 | test_expect_success 'ignore patch if in upstream' ' |
| 475 | HEAD=$(git rev-parse HEAD) && |
| 476 | git checkout -b has-cherry-picked HEAD^ && |
| 477 | echo unrelated > file7 && |
| 478 | git add file7 && |
| 479 | test_tick && |
| 480 | git commit -m "unrelated change" && |
| 481 | git cherry-pick $HEAD && |
| 482 | EXPECT_COUNT=1 git rebase -i $HEAD && |
| 483 | test $HEAD = $(git rev-parse HEAD^) |
| 484 | ' |
| 485 | |
Johannes Schindelin | be6ff20 | 2007-09-25 16:42:36 +0100 | [diff] [blame] | 486 | test_expect_success '--continue tries to commit, even for "edit"' ' |
| 487 | parent=$(git rev-parse HEAD^) && |
| 488 | test_tick && |
| 489 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 490 | echo edited > file7 && |
| 491 | git add file7 && |
| 492 | FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && |
| 493 | test edited = $(git show HEAD:file7) && |
| 494 | git show HEAD | grep chouette && |
| 495 | test $parent = $(git rev-parse HEAD^) |
| 496 | ' |
| 497 | |
Stephan Beyer | dc7f55c | 2009-01-15 13:56:15 +0100 | [diff] [blame] | 498 | test_expect_success 'aborted --continue does not squash commits after "edit"' ' |
| 499 | old=$(git rev-parse HEAD) && |
| 500 | test_tick && |
| 501 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 502 | echo "edited again" > file7 && |
| 503 | git add file7 && |
| 504 | ( |
| 505 | FAKE_COMMIT_MESSAGE=" " && |
| 506 | export FAKE_COMMIT_MESSAGE && |
| 507 | test_must_fail git rebase --continue |
| 508 | ) && |
| 509 | test $old = $(git rev-parse HEAD) && |
| 510 | git rebase --abort |
| 511 | ' |
| 512 | |
Stephan Beyer | f8aa1b6 | 2009-01-15 13:56:16 +0100 | [diff] [blame] | 513 | test_expect_success 'auto-amend only edited commits after "edit"' ' |
| 514 | test_tick && |
| 515 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 516 | echo "edited again" > file7 && |
| 517 | git add file7 && |
| 518 | FAKE_COMMIT_MESSAGE="edited file7 again" git commit && |
| 519 | echo "and again" > file7 && |
| 520 | git add file7 && |
| 521 | test_tick && |
| 522 | ( |
| 523 | FAKE_COMMIT_MESSAGE="and again" && |
| 524 | export FAKE_COMMIT_MESSAGE && |
| 525 | test_must_fail git rebase --continue |
| 526 | ) && |
| 527 | git rebase --abort |
| 528 | ' |
| 529 | |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 530 | test_expect_success 'clean error after failed "exec"' ' |
| 531 | test_tick && |
| 532 | test_when_finished "git rebase --abort || :" && |
| 533 | ( |
| 534 | FAKE_LINES="1 exec_false" && |
| 535 | export FAKE_LINES && |
| 536 | test_must_fail git rebase -i HEAD^ |
| 537 | ) && |
| 538 | echo "edited again" > file7 && |
| 539 | git add file7 && |
| 540 | test_must_fail git rebase --continue 2>error && |
| 541 | grep "You have staged changes in your working tree." error |
| 542 | ' |
| 543 | |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 544 | test_expect_success 'rebase a detached HEAD' ' |
| 545 | grandparent=$(git rev-parse HEAD~2) && |
| 546 | git checkout $(git rev-parse HEAD) && |
| 547 | test_tick && |
| 548 | FAKE_LINES="2 1" git rebase -i HEAD~2 && |
| 549 | test $grandparent = $(git rev-parse HEAD~2) |
| 550 | ' |
| 551 | |
Johannes Schindelin | 752527f | 2008-01-28 16:33:28 +0000 | [diff] [blame] | 552 | test_expect_success 'rebase a commit violating pre-commit' ' |
| 553 | |
| 554 | mkdir -p .git/hooks && |
| 555 | PRE_COMMIT=.git/hooks/pre-commit && |
| 556 | echo "#!/bin/sh" > $PRE_COMMIT && |
| 557 | echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT && |
| 558 | chmod a+x $PRE_COMMIT && |
| 559 | echo "monde! " >> file1 && |
| 560 | test_tick && |
Stephan Beyer | ab73679 | 2008-06-22 01:55:50 +0200 | [diff] [blame] | 561 | test_must_fail git commit -m doesnt-verify file1 && |
Johannes Schindelin | 752527f | 2008-01-28 16:33:28 +0000 | [diff] [blame] | 562 | git commit -m doesnt-verify --no-verify file1 && |
| 563 | test_tick && |
| 564 | FAKE_LINES=2 git rebase -i HEAD~2 |
| 565 | |
| 566 | ' |
| 567 | |
Junio C Hamano | 077b725 | 2008-02-13 13:13:21 -0800 | [diff] [blame] | 568 | test_expect_success 'rebase with a file named HEAD in worktree' ' |
| 569 | |
| 570 | rm -fr .git/hooks && |
| 571 | git reset --hard && |
| 572 | git checkout -b branch3 A && |
| 573 | |
| 574 | ( |
| 575 | GIT_AUTHOR_NAME="Squashed Away" && |
| 576 | export GIT_AUTHOR_NAME && |
| 577 | >HEAD && |
| 578 | git add HEAD && |
| 579 | git commit -m "Add head" && |
| 580 | >BODY && |
| 581 | git add BODY && |
| 582 | git commit -m "Add body" |
| 583 | ) && |
| 584 | |
| 585 | FAKE_LINES="1 squash 2" git rebase -i to-be-rebased && |
| 586 | test "$(git show -s --pretty=format:%an)" = "Squashed Away" |
| 587 | |
| 588 | ' |
| 589 | |
Johannes Schindelin | ff74126 | 2008-10-10 13:42:12 +0200 | [diff] [blame] | 590 | test_expect_success 'do "noop" when there is nothing to cherry-pick' ' |
| 591 | |
| 592 | git checkout -b branch4 HEAD && |
| 593 | GIT_EDITOR=: git commit --amend \ |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 594 | --author="Somebody else <somebody@else.com>" && |
Johannes Schindelin | ff74126 | 2008-10-10 13:42:12 +0200 | [diff] [blame] | 595 | test $(git rev-parse branch3) != $(git rev-parse branch4) && |
| 596 | git rebase -i branch3 && |
| 597 | test $(git rev-parse branch3) = $(git rev-parse branch4) |
| 598 | |
| 599 | ' |
| 600 | |
Junio C Hamano | 9674769 | 2009-01-27 01:07:31 -0800 | [diff] [blame] | 601 | test_expect_success 'submodule rebase setup' ' |
| 602 | git checkout A && |
| 603 | mkdir sub && |
| 604 | ( |
| 605 | cd sub && git init && >elif && |
| 606 | git add elif && git commit -m "submodule initial" |
| 607 | ) && |
| 608 | echo 1 >file1 && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 609 | git add file1 sub && |
Junio C Hamano | 9674769 | 2009-01-27 01:07:31 -0800 | [diff] [blame] | 610 | test_tick && |
| 611 | git commit -m "One" && |
| 612 | echo 2 >file1 && |
| 613 | test_tick && |
| 614 | git commit -a -m "Two" && |
| 615 | ( |
| 616 | cd sub && echo 3 >elif && |
| 617 | git commit -a -m "submodule second" |
| 618 | ) && |
| 619 | test_tick && |
| 620 | git commit -a -m "Three changes submodule" |
| 621 | ' |
| 622 | |
Johannes Schindelin | 94c88ed | 2009-01-27 12:42:31 +0100 | [diff] [blame] | 623 | test_expect_success 'submodule rebase -i' ' |
Junio C Hamano | 9674769 | 2009-01-27 01:07:31 -0800 | [diff] [blame] | 624 | FAKE_LINES="1 squash 2 3" git rebase -i A |
| 625 | ' |
| 626 | |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 627 | test_expect_success 'avoid unnecessary reset' ' |
| 628 | git checkout master && |
| 629 | test-chmtime =123456789 file3 && |
| 630 | git update-index --refresh && |
| 631 | HEAD=$(git rev-parse HEAD) && |
| 632 | git rebase -i HEAD~4 && |
| 633 | test $HEAD = $(git rev-parse HEAD) && |
| 634 | MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && |
| 635 | test 123456789 = $MTIME |
| 636 | ' |
| 637 | |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 638 | test_expect_success 'reword' ' |
| 639 | git checkout -b reword-branch master && |
| 640 | FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && |
| 641 | git show HEAD | grep "E changed" && |
| 642 | test $(git rev-parse master) != $(git rev-parse HEAD) && |
| 643 | test $(git rev-parse master^) = $(git rev-parse HEAD^) && |
| 644 | FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A && |
| 645 | git show HEAD^ | grep "D changed" && |
| 646 | FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A && |
| 647 | git show HEAD~3 | grep "B changed" && |
| 648 | FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A && |
| 649 | git show HEAD~2 | grep "C changed" |
| 650 | ' |
| 651 | |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 652 | test_expect_success 'rebase -i can copy notes' ' |
| 653 | git config notes.rewrite.rebase true && |
| 654 | git config notes.rewriteRef "refs/notes/*" && |
| 655 | test_commit n1 && |
| 656 | test_commit n2 && |
| 657 | test_commit n3 && |
| 658 | git notes add -m"a note" n3 && |
| 659 | git rebase --onto n1 n2 && |
| 660 | test "a note" = "$(git notes show HEAD)" |
| 661 | ' |
| 662 | |
| 663 | cat >expect <<EOF |
| 664 | an earlier note |
Johan Herland | d4990c4 | 2010-11-09 22:49:44 +0100 | [diff] [blame] | 665 | |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 666 | a note |
| 667 | EOF |
| 668 | |
| 669 | test_expect_success 'rebase -i can copy notes over a fixup' ' |
| 670 | git reset --hard n3 && |
| 671 | git notes add -m"an earlier note" n2 && |
| 672 | GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && |
| 673 | git notes show > output && |
| 674 | test_cmp expect output |
| 675 | ' |
| 676 | |
Dave Olszewski | 2ec33cd | 2010-03-14 21:48:22 -0700 | [diff] [blame] | 677 | test_expect_success 'rebase while detaching HEAD' ' |
| 678 | git symbolic-ref HEAD && |
| 679 | grandparent=$(git rev-parse HEAD~2) && |
| 680 | test_tick && |
| 681 | FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && |
| 682 | test $grandparent = $(git rev-parse HEAD~2) && |
| 683 | test_must_fail git symbolic-ref HEAD |
| 684 | ' |
| 685 | |
Marc Branchaud | b499549 | 2010-03-24 16:34:04 -0400 | [diff] [blame] | 686 | test_tick # Ensure that the rebased commits get a different timestamp. |
| 687 | test_expect_success 'always cherry-pick with --no-ff' ' |
| 688 | git checkout no-ff-branch && |
| 689 | git tag original-no-ff-branch && |
| 690 | git rebase -i --no-ff A && |
| 691 | touch empty && |
| 692 | for p in 0 1 2 |
| 693 | do |
| 694 | test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && |
| 695 | git diff HEAD~$p original-no-ff-branch~$p > out && |
| 696 | test_cmp empty out |
| 697 | done && |
| 698 | test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) && |
| 699 | git diff HEAD~3 original-no-ff-branch~3 > out && |
| 700 | test_cmp empty out |
| 701 | ' |
| 702 | |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 703 | test_expect_success 'set up commits with funny messages' ' |
| 704 | git checkout -b funny A && |
| 705 | echo >>file1 && |
| 706 | test_tick && |
| 707 | git commit -a -m "end with slash\\" && |
| 708 | echo >>file1 && |
| 709 | test_tick && |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 710 | git commit -a -m "something (\000) that looks like octal" && |
| 711 | echo >>file1 && |
| 712 | test_tick && |
| 713 | git commit -a -m "something (\n) that looks like a newline" && |
| 714 | echo >>file1 && |
| 715 | test_tick && |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 716 | git commit -a -m "another commit" |
| 717 | ' |
| 718 | |
| 719 | test_expect_success 'rebase-i history with funny messages' ' |
| 720 | git rev-list A..funny >expect && |
| 721 | test_tick && |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 722 | FAKE_LINES="1 2 3 4" git rebase -i A && |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 723 | git rev-list A.. >actual && |
| 724 | test_cmp expect actual |
| 725 | ' |
| 726 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 727 | test_done |