Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rebase --root |
| 4 | |
| 5 | Tests if git rebase --root --onto <newparent> can rebase the root commit. |
| 6 | ' |
| 7 | . ./test-lib.sh |
| 8 | |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 9 | log_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 | |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 15 | test_expect_success 'prepare repository' ' |
Johannes Schindelin | f7951e1 | 2009-01-27 23:35:09 +0100 | [diff] [blame] | 16 | test_commit 1 A && |
| 17 | test_commit 2 A && |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 18 | git symbolic-ref HEAD refs/heads/other && |
| 19 | rm .git/index && |
Johannes Schindelin | f7951e1 | 2009-01-27 23:35:09 +0100 | [diff] [blame] | 20 | test_commit 3 B && |
| 21 | test_commit 1b A 1 && |
| 22 | test_commit 4 B |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 23 | ' |
| 24 | |
Martin von Zweigbergk | f2b6a19 | 2012-06-26 07:51:55 -0700 | [diff] [blame] | 25 | test_expect_success 'rebase --root fails with too many args' ' |
| 26 | git checkout -B fail other && |
| 27 | test_must_fail git rebase --onto master --root fail fail |
| 28 | ' |
| 29 | |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 30 | test_expect_success 'setup pre-rebase hook' ' |
| 31 | mkdir -p .git/hooks && |
| 32 | cat >.git/hooks/pre-rebase <<EOF && |
| 33 | #!$SHELL_PATH |
| 34 | echo "\$1,\$2" >.git/PRE-REBASE-INPUT |
| 35 | EOF |
| 36 | chmod +x .git/hooks/pre-rebase |
| 37 | ' |
| 38 | cat > expect <<EOF |
| 39 | 4 |
| 40 | 3 |
| 41 | 2 |
| 42 | 1 |
| 43 | EOF |
| 44 | |
| 45 | test_expect_success 'rebase --root --onto <newbase>' ' |
Martin von Zweigbergk | f2b6a19 | 2012-06-26 07:51:55 -0700 | [diff] [blame] | 46 | git checkout -b work other && |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 47 | git rebase --root --onto master && |
| 48 | git log --pretty=tformat:"%s" > rebased && |
| 49 | test_cmp expect rebased |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'pre-rebase got correct input (1)' ' |
| 53 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'rebase --root --onto <newbase> <branch>' ' |
| 57 | git branch work2 other && |
| 58 | git rebase --root --onto master work2 && |
| 59 | git log --pretty=tformat:"%s" > rebased2 && |
| 60 | test_cmp expect rebased2 |
| 61 | ' |
| 62 | |
| 63 | test_expect_success 'pre-rebase got correct input (2)' ' |
| 64 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2 |
| 65 | ' |
| 66 | |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 67 | test_expect_success 'rebase -i --root --onto <newbase>' ' |
| 68 | git checkout -b work3 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 69 | git rebase -i --root --onto master && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 70 | git log --pretty=tformat:"%s" > rebased3 && |
| 71 | test_cmp expect rebased3 |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'pre-rebase got correct input (3)' ' |
| 75 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, |
| 76 | ' |
| 77 | |
| 78 | test_expect_success 'rebase -i --root --onto <newbase> <branch>' ' |
| 79 | git branch work4 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 80 | git rebase -i --root --onto master work4 && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 81 | git log --pretty=tformat:"%s" > rebased4 && |
| 82 | test_cmp expect rebased4 |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'pre-rebase got correct input (4)' ' |
| 86 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4 |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'rebase -i -p with linear history' ' |
| 90 | git checkout -b work5 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 91 | git rebase -i -p --root --onto master && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 92 | git log --pretty=tformat:"%s" > rebased5 && |
| 93 | test_cmp expect rebased5 |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'pre-rebase got correct input (5)' ' |
| 97 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, |
| 98 | ' |
| 99 | |
| 100 | test_expect_success 'set up merge history' ' |
| 101 | git checkout other^ && |
| 102 | git checkout -b side && |
Johannes Schindelin | f7951e1 | 2009-01-27 23:35:09 +0100 | [diff] [blame] | 103 | test_commit 5 C && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 104 | git checkout other && |
| 105 | git merge side |
| 106 | ' |
| 107 | |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 108 | cat > expect-side <<'EOF' |
| 109 | commit work6 work6~1 work6^2 |
| 110 | Merge branch 'side' into other |
| 111 | commit work6^2 work6~2 |
| 112 | 5 |
| 113 | commit work6~1 work6~2 |
| 114 | 4 |
| 115 | commit work6~2 work6~3 |
| 116 | 3 |
| 117 | commit work6~3 work6~4 |
| 118 | 2 |
| 119 | commit work6~4 |
| 120 | 1 |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 121 | EOF |
| 122 | |
| 123 | test_expect_success 'rebase -i -p with merge' ' |
| 124 | git checkout -b work6 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 125 | git rebase -i -p --root --onto master && |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 126 | log_with_names work6 > rebased6 && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 127 | test_cmp expect-side rebased6 |
| 128 | ' |
| 129 | |
| 130 | test_expect_success 'set up second root and merge' ' |
| 131 | git symbolic-ref HEAD refs/heads/third && |
| 132 | rm .git/index && |
| 133 | rm A B C && |
Johannes Schindelin | f7951e1 | 2009-01-27 23:35:09 +0100 | [diff] [blame] | 134 | test_commit 6 D && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 135 | git checkout other && |
| 136 | git merge third |
| 137 | ' |
| 138 | |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 139 | cat > expect-third <<'EOF' |
| 140 | commit work7 work7~1 work7^2 |
| 141 | Merge branch 'third' into other |
| 142 | commit work7^2 work7~4 |
| 143 | 6 |
| 144 | commit work7~1 work7~2 work7~1^2 |
| 145 | Merge branch 'side' into other |
| 146 | commit work7~1^2 work7~3 |
| 147 | 5 |
| 148 | commit work7~2 work7~3 |
| 149 | 4 |
| 150 | commit work7~3 work7~4 |
| 151 | 3 |
| 152 | commit work7~4 work7~5 |
| 153 | 2 |
| 154 | commit work7~5 |
| 155 | 1 |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 156 | EOF |
| 157 | |
| 158 | test_expect_success 'rebase -i -p with two roots' ' |
| 159 | git checkout -b work7 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 160 | git rebase -i -p --root --onto master && |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 161 | log_with_names work7 > rebased7 && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 162 | test_cmp expect-third rebased7 |
| 163 | ' |
| 164 | |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 165 | test_expect_success 'setup pre-rebase hook that fails' ' |
| 166 | mkdir -p .git/hooks && |
| 167 | cat >.git/hooks/pre-rebase <<EOF && |
| 168 | #!$SHELL_PATH |
| 169 | false |
| 170 | EOF |
| 171 | chmod +x .git/hooks/pre-rebase |
| 172 | ' |
| 173 | |
| 174 | test_expect_success 'pre-rebase hook stops rebase' ' |
| 175 | git checkout -b stops1 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 176 | test_must_fail git rebase --root --onto master && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 177 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 && |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 178 | test 0 = $(git rev-list other...stops1 | wc -l) |
| 179 | ' |
| 180 | |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 181 | test_expect_success 'pre-rebase hook stops rebase -i' ' |
| 182 | git checkout -b stops2 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 183 | test_must_fail git rebase --root --onto master && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 184 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 && |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 185 | test 0 = $(git rev-list other...stops2 | wc -l) |
| 186 | ' |
| 187 | |
Junio C Hamano | a6c7a27 | 2009-01-26 10:05:22 +0100 | [diff] [blame] | 188 | test_expect_success 'remove pre-rebase hook' ' |
| 189 | rm -f .git/hooks/pre-rebase |
| 190 | ' |
| 191 | |
| 192 | test_expect_success 'set up a conflict' ' |
| 193 | git checkout master && |
| 194 | echo conflict > B && |
| 195 | git add B && |
| 196 | git commit -m conflict |
| 197 | ' |
| 198 | |
| 199 | test_expect_success 'rebase --root with conflict (first part)' ' |
| 200 | git checkout -b conflict1 other && |
| 201 | test_must_fail git rebase --root --onto master && |
| 202 | git ls-files -u | grep "B$" |
| 203 | ' |
| 204 | |
| 205 | test_expect_success 'fix the conflict' ' |
| 206 | echo 3 > B && |
| 207 | git add B |
| 208 | ' |
| 209 | |
| 210 | cat > expect-conflict <<EOF |
| 211 | 6 |
| 212 | 5 |
| 213 | 4 |
| 214 | 3 |
| 215 | conflict |
| 216 | 2 |
| 217 | 1 |
| 218 | EOF |
| 219 | |
| 220 | test_expect_success 'rebase --root with conflict (second part)' ' |
| 221 | git rebase --continue && |
| 222 | git log --pretty=tformat:"%s" > conflict1 && |
| 223 | test_cmp expect-conflict conflict1 |
| 224 | ' |
| 225 | |
| 226 | test_expect_success 'rebase -i --root with conflict (first part)' ' |
| 227 | git checkout -b conflict2 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 228 | test_must_fail git rebase -i --root --onto master && |
Junio C Hamano | a6c7a27 | 2009-01-26 10:05:22 +0100 | [diff] [blame] | 229 | git ls-files -u | grep "B$" |
| 230 | ' |
| 231 | |
| 232 | test_expect_success 'fix the conflict' ' |
| 233 | echo 3 > B && |
| 234 | git add B |
| 235 | ' |
| 236 | |
| 237 | test_expect_success 'rebase -i --root with conflict (second part)' ' |
| 238 | git rebase --continue && |
| 239 | git log --pretty=tformat:"%s" > conflict2 && |
| 240 | test_cmp expect-conflict conflict2 |
| 241 | ' |
| 242 | |
| 243 | cat >expect-conflict-p <<\EOF |
| 244 | commit conflict3 conflict3~1 conflict3^2 |
| 245 | Merge branch 'third' into other |
| 246 | commit conflict3^2 conflict3~4 |
| 247 | 6 |
| 248 | commit conflict3~1 conflict3~2 conflict3~1^2 |
| 249 | Merge branch 'side' into other |
| 250 | commit conflict3~1^2 conflict3~3 |
| 251 | 5 |
| 252 | commit conflict3~2 conflict3~3 |
| 253 | 4 |
| 254 | commit conflict3~3 conflict3~4 |
| 255 | 3 |
| 256 | commit conflict3~4 conflict3~5 |
| 257 | conflict |
| 258 | commit conflict3~5 conflict3~6 |
| 259 | 2 |
| 260 | commit conflict3~6 |
| 261 | 1 |
| 262 | EOF |
| 263 | |
| 264 | test_expect_success 'rebase -i -p --root with conflict (first part)' ' |
| 265 | git checkout -b conflict3 other && |
Thomas Rast | 2182896 | 2009-01-30 23:47:00 +0100 | [diff] [blame] | 266 | test_must_fail git rebase -i -p --root --onto master && |
Junio C Hamano | a6c7a27 | 2009-01-26 10:05:22 +0100 | [diff] [blame] | 267 | git ls-files -u | grep "B$" |
| 268 | ' |
| 269 | |
| 270 | test_expect_success 'fix the conflict' ' |
| 271 | echo 3 > B && |
| 272 | git add B |
| 273 | ' |
| 274 | |
| 275 | test_expect_success 'rebase -i -p --root with conflict (second part)' ' |
| 276 | git rebase --continue && |
Thomas Rast | 2ea3c17 | 2009-01-30 23:47:01 +0100 | [diff] [blame] | 277 | log_with_names conflict3 >out && |
Junio C Hamano | a6c7a27 | 2009-01-26 10:05:22 +0100 | [diff] [blame] | 278 | test_cmp expect-conflict-p out |
| 279 | ' |
| 280 | |
Thomas Rast | 190f532 | 2009-01-05 18:35:16 +0100 | [diff] [blame] | 281 | test_done |