| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2019 Denton Liu |
| 4 | # |
| 5 | |
| 6 | test_description='ensure rebase fast-forwards commits when possible' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | test_expect_success setup ' |
| 14 | # Commit dates are hardcoded to 2005, and the reflog entries will have |
| 15 | # a matching timestamp. Maintenance may thus immediately expire |
| 16 | # reflogs if it was running. |
| 17 | git config set gc.reflogExpire never && |
| 18 | git config set gc.reflogExpireUnreachable never && |
| 19 | |
| 20 | test_commit A && |
| 21 | test_commit B && |
| 22 | test_commit C && |
| 23 | test_commit D && |
| 24 | git checkout -t -b side |
| 25 | ' |
| 26 | |
| 27 | test_rebase_same_head () { |
| 28 | status_n="$1" && |
| 29 | shift && |
| 30 | what_n="$1" && |
| 31 | shift && |
| 32 | cmp_n="$1" && |
| 33 | shift && |
| 34 | status_f="$1" && |
| 35 | shift && |
| 36 | what_f="$1" && |
| 37 | shift && |
| 38 | cmp_f="$1" && |
| 39 | shift && |
| 40 | test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --apply" "$*" && |
| 41 | test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --apply --no-ff" "$*" |
| 42 | test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --merge" "$*" && |
| 43 | test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --merge --no-ff" "$*" |
| 44 | test_rebase_same_head_ $status_n $what_n $cmp_n 1 " --merge" "$*" && |
| 45 | test_rebase_same_head_ $status_f $what_f $cmp_f 1 " --merge --no-ff" "$*" |
| 46 | } |
| 47 | |
| 48 | test_rebase_same_head_ () { |
| 49 | status="$1" && |
| 50 | shift && |
| 51 | what="$1" && |
| 52 | shift && |
| 53 | cmp="$1" && |
| 54 | shift && |
| 55 | abbreviate="$1" && |
| 56 | shift && |
| 57 | flag="$1" |
| 58 | shift && |
| 59 | if test $abbreviate -eq 1 |
| 60 | then |
| 61 | msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD" |
| 62 | else |
| 63 | msg="git rebase$flag $* with $changes is $what with $cmp HEAD" |
| 64 | fi && |
| 65 | test_expect_$status "$msg" " |
| 66 | if test $abbreviate -eq 1 |
| 67 | then |
| 68 | test_config rebase.abbreviateCommands true |
| 69 | fi && |
| 70 | oldhead=\$(git rev-parse HEAD) && |
| 71 | test_when_finished 'git reset --hard \$oldhead' && |
| 72 | git reflog HEAD >expect && |
| 73 | git rebase$flag $* >stdout && |
| 74 | git reflog HEAD >actual && |
| 75 | if test $what = work |
| 76 | then |
| 77 | old=\$(wc -l <expect) && |
| 78 | test_line_count '-gt' \$old actual |
| 79 | elif test $what = noop |
| 80 | then |
| 81 | test_cmp expect actual |
| 82 | fi && |
| 83 | newhead=\$(git rev-parse HEAD) && |
| 84 | if test $cmp = same |
| 85 | then |
| 86 | test_cmp_rev \$oldhead \$newhead |
| 87 | elif test $cmp = diff |
| 88 | then |
| 89 | test_cmp_rev ! \$oldhead \$newhead |
| 90 | fi |
| 91 | " |
| 92 | } |
| 93 | |
| 94 | changes='no changes' |
| 95 | test_rebase_same_head success noop same success work same |
| 96 | test_rebase_same_head success noop same success work same main |
| 97 | test_rebase_same_head success noop same success work diff --onto B B |
| 98 | test_rebase_same_head success noop same success work diff --onto B... B |
| 99 | test_rebase_same_head success noop same success work same --onto main... main |
| 100 | test_rebase_same_head success noop same success work same --keep-base main |
| 101 | test_rebase_same_head success noop same success work same --keep-base |
| 102 | test_rebase_same_head success noop same success work same --no-fork-point |
| 103 | test_rebase_same_head success noop same success work same --keep-base --no-fork-point |
| 104 | test_rebase_same_head success noop same success work same --fork-point main |
| 105 | test_rebase_same_head success noop same success work diff --fork-point --onto B B |
| 106 | test_rebase_same_head success noop same success work diff --fork-point --onto B... B |
| 107 | test_rebase_same_head success noop same success work same --fork-point --onto main... main |
| 108 | test_rebase_same_head success noop same success work same --keep-base --keep-base main |
| 109 | |
| 110 | test_expect_success 'add work same to side' ' |
| 111 | test_commit E |
| 112 | ' |
| 113 | |
| 114 | changes='our changes' |
| 115 | test_rebase_same_head success noop same success work same |
| 116 | test_rebase_same_head success noop same success work same main |
| 117 | test_rebase_same_head success noop same success work diff --onto B B |
| 118 | test_rebase_same_head success noop same success work diff --onto B... B |
| 119 | test_rebase_same_head success noop same success work same --onto main... main |
| 120 | test_rebase_same_head success noop same success work same --keep-base main |
| 121 | test_rebase_same_head success noop same success work same --keep-base |
| 122 | test_rebase_same_head success noop same success work same --no-fork-point |
| 123 | test_rebase_same_head success noop same success work same --keep-base --no-fork-point |
| 124 | test_rebase_same_head success noop same success work same --fork-point main |
| 125 | test_rebase_same_head success noop same success work diff --fork-point --onto B B |
| 126 | test_rebase_same_head success noop same success work diff --fork-point --onto B... B |
| 127 | test_rebase_same_head success noop same success work same --fork-point --onto main... main |
| 128 | test_rebase_same_head success noop same success work same --fork-point --keep-base main |
| 129 | |
| 130 | test_expect_success 'add work same to upstream' ' |
| 131 | git checkout main && |
| 132 | test_commit F && |
| 133 | git checkout side |
| 134 | ' |
| 135 | |
| 136 | changes='our and their changes' |
| 137 | test_rebase_same_head success noop same success work diff --onto B B |
| 138 | test_rebase_same_head success noop same success work diff --onto B... B |
| 139 | test_rebase_same_head success noop same success work diff --onto main... main |
| 140 | test_rebase_same_head success noop same success work diff --keep-base main |
| 141 | test_rebase_same_head success noop same success work diff --keep-base |
| 142 | test_rebase_same_head failure work same success work diff --fork-point --onto B B |
| 143 | test_rebase_same_head failure work same success work diff --fork-point --onto B... B |
| 144 | test_rebase_same_head success noop same success work diff --fork-point --onto main... main |
| 145 | test_rebase_same_head success noop same success work diff --fork-point --keep-base main |
| 146 | |
| 147 | test_done |