Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2019 Denton Liu |
| 4 | # |
| 5 | |
| 6 | test_description='ensure rebase fast-forwards commits when possible' |
| 7 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 11 | . ./test-lib.sh |
| 12 | |
| 13 | test_expect_success setup ' |
| 14 | test_commit A && |
| 15 | test_commit B && |
| 16 | test_commit C && |
| 17 | test_commit D && |
| 18 | git checkout -t -b side |
| 19 | ' |
| 20 | |
| 21 | test_rebase_same_head () { |
Ævar Arnfjörð Bjarmason | c9efc21 | 2019-08-27 01:37:53 -0400 | [diff] [blame] | 22 | status_n="$1" && |
| 23 | shift && |
| 24 | what_n="$1" && |
| 25 | shift && |
| 26 | cmp_n="$1" && |
| 27 | shift && |
| 28 | status_f="$1" && |
| 29 | shift && |
| 30 | what_f="$1" && |
| 31 | shift && |
| 32 | cmp_f="$1" && |
| 33 | shift && |
Alban Gruin | de9f1d3 | 2020-03-30 14:42:36 +0200 | [diff] [blame] | 34 | test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --apply" "$*" && |
| 35 | test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --apply --no-ff" "$*" |
| 36 | test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --merge" "$*" && |
| 37 | test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --merge --no-ff" "$*" |
| 38 | test_rebase_same_head_ $status_n $what_n $cmp_n 1 " --merge" "$*" && |
| 39 | test_rebase_same_head_ $status_f $what_f $cmp_f 1 " --merge --no-ff" "$*" |
Ævar Arnfjörð Bjarmason | c9efc21 | 2019-08-27 01:37:53 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | test_rebase_same_head_ () { |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 43 | status="$1" && |
| 44 | shift && |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 45 | what="$1" && |
| 46 | shift && |
| 47 | cmp="$1" && |
| 48 | shift && |
Alban Gruin | de9f1d3 | 2020-03-30 14:42:36 +0200 | [diff] [blame] | 49 | abbreviate="$1" && |
| 50 | shift && |
Ævar Arnfjörð Bjarmason | c9efc21 | 2019-08-27 01:37:53 -0400 | [diff] [blame] | 51 | flag="$1" |
| 52 | shift && |
Alban Gruin | de9f1d3 | 2020-03-30 14:42:36 +0200 | [diff] [blame] | 53 | if test $abbreviate -eq 1 |
| 54 | then |
| 55 | msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD" |
| 56 | else |
| 57 | msg="git rebase$flag $* with $changes is $what with $cmp HEAD" |
| 58 | fi && |
| 59 | test_expect_$status "$msg" " |
| 60 | if test $abbreviate -eq 1 |
| 61 | then |
| 62 | test_config rebase.abbreviateCommands true |
| 63 | fi && |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 64 | oldhead=\$(git rev-parse HEAD) && |
| 65 | test_when_finished 'git reset --hard \$oldhead' && |
Han-Wen Nienhuys | ce57d85 | 2020-07-10 17:19:51 +0000 | [diff] [blame] | 66 | git reflog HEAD >expect && |
Ævar Arnfjörð Bjarmason | c9efc21 | 2019-08-27 01:37:53 -0400 | [diff] [blame] | 67 | git rebase$flag $* >stdout && |
Han-Wen Nienhuys | ce57d85 | 2020-07-10 17:19:51 +0000 | [diff] [blame] | 68 | git reflog HEAD >actual && |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 69 | if test $what = work |
| 70 | then |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 71 | old=\$(wc -l <expect) && |
Han-Wen Nienhuys | ce57d85 | 2020-07-10 17:19:51 +0000 | [diff] [blame] | 72 | test_line_count '-gt' \$old actual |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 73 | elif test $what = noop |
| 74 | then |
Han-Wen Nienhuys | ce57d85 | 2020-07-10 17:19:51 +0000 | [diff] [blame] | 75 | test_cmp expect actual |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 76 | fi && |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 77 | newhead=\$(git rev-parse HEAD) && |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 78 | if test $cmp = same |
| 79 | then |
| 80 | test_cmp_rev \$oldhead \$newhead |
| 81 | elif test $cmp = diff |
| 82 | then |
Denton Liu | 2c9e125 | 2019-11-12 15:07:45 -0800 | [diff] [blame] | 83 | test_cmp_rev ! \$oldhead \$newhead |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 84 | fi |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 85 | " |
| 86 | } |
| 87 | |
| 88 | changes='no changes' |
Denton Liu | 4effc5b | 2019-08-27 01:38:01 -0400 | [diff] [blame] | 89 | test_rebase_same_head success noop same success work same |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 90 | test_rebase_same_head success noop same success work same main |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 91 | test_rebase_same_head success noop same success work diff --onto B B |
| 92 | test_rebase_same_head success noop same success work diff --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 93 | test_rebase_same_head success noop same success work same --onto main... main |
| 94 | test_rebase_same_head success noop same success work same --keep-base main |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 95 | test_rebase_same_head success noop same success work same --keep-base |
| 96 | test_rebase_same_head success noop same success work same --no-fork-point |
| 97 | test_rebase_same_head success noop same success work same --keep-base --no-fork-point |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 98 | test_rebase_same_head success noop same success work same --fork-point main |
Denton Liu | 4effc5b | 2019-08-27 01:38:01 -0400 | [diff] [blame] | 99 | test_rebase_same_head success noop same success work diff --fork-point --onto B B |
| 100 | test_rebase_same_head success noop same success work diff --fork-point --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 101 | test_rebase_same_head success noop same success work same --fork-point --onto main... main |
| 102 | test_rebase_same_head success noop same success work same --keep-base --keep-base main |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 103 | |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 104 | test_expect_success 'add work same to side' ' |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 105 | test_commit E |
| 106 | ' |
| 107 | |
| 108 | changes='our changes' |
Denton Liu | 4effc5b | 2019-08-27 01:38:01 -0400 | [diff] [blame] | 109 | test_rebase_same_head success noop same success work same |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 110 | test_rebase_same_head success noop same success work same main |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 111 | test_rebase_same_head success noop same success work diff --onto B B |
| 112 | test_rebase_same_head success noop same success work diff --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 113 | test_rebase_same_head success noop same success work same --onto main... main |
| 114 | test_rebase_same_head success noop same success work same --keep-base main |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 115 | test_rebase_same_head success noop same success work same --keep-base |
| 116 | test_rebase_same_head success noop same success work same --no-fork-point |
| 117 | test_rebase_same_head success noop same success work same --keep-base --no-fork-point |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 118 | test_rebase_same_head success noop same success work same --fork-point main |
Denton Liu | 4effc5b | 2019-08-27 01:38:01 -0400 | [diff] [blame] | 119 | test_rebase_same_head success noop same success work diff --fork-point --onto B B |
| 120 | test_rebase_same_head success noop same success work diff --fork-point --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 121 | test_rebase_same_head success noop same success work same --fork-point --onto main... main |
| 122 | test_rebase_same_head success noop same success work same --fork-point --keep-base main |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 123 | |
Ævar Arnfjörð Bjarmason | 4336d36 | 2019-08-25 05:12:02 -0400 | [diff] [blame] | 124 | test_expect_success 'add work same to upstream' ' |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 125 | git checkout main && |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 126 | test_commit F && |
| 127 | git checkout side |
| 128 | ' |
| 129 | |
| 130 | changes='our and their changes' |
Elijah Newren | 9a70f3d | 2020-02-15 21:36:30 +0000 | [diff] [blame] | 131 | test_rebase_same_head success noop same success work diff --onto B B |
| 132 | test_rebase_same_head success noop same success work diff --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 133 | test_rebase_same_head success noop same success work diff --onto main... main |
| 134 | test_rebase_same_head success noop same success work diff --keep-base main |
Denton Liu | 414d924 | 2019-08-27 01:38:06 -0400 | [diff] [blame] | 135 | test_rebase_same_head success noop same success work diff --keep-base |
Ævar Arnfjörð Bjarmason | c9efc21 | 2019-08-27 01:37:53 -0400 | [diff] [blame] | 136 | test_rebase_same_head failure work same success work diff --fork-point --onto B B |
| 137 | test_rebase_same_head failure work same success work diff --fork-point --onto B... B |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 138 | test_rebase_same_head success noop same success work diff --fork-point --onto main... main |
| 139 | test_rebase_same_head success noop same success work diff --fork-point --keep-base main |
Denton Liu | 793ac7e | 2019-08-25 05:12:00 -0400 | [diff] [blame] | 140 | |
| 141 | test_done |