Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='messages from rebase operation' |
| 4 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
Martin von Zweigbergk | 9e2248e | 2013-06-06 23:11:42 -0700 | [diff] [blame] | 10 | test_expect_success 'setup' ' |
| 11 | test_commit O fileO && |
| 12 | test_commit X fileX && |
| 13 | test_commit A fileA && |
| 14 | test_commit B fileB && |
| 15 | test_commit Y fileY && |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 16 | |
Martin von Zweigbergk | 9e2248e | 2013-06-06 23:11:42 -0700 | [diff] [blame] | 17 | git checkout -b topic O && |
| 18 | git cherry-pick A B && |
| 19 | test_commit Z fileZ && |
Tor Arne Vestbø | a9c3821 | 2009-03-01 23:11:38 +0100 | [diff] [blame] | 20 | git tag start |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 21 | ' |
| 22 | |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 23 | test_expect_success 'rebase -m' ' |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 24 | git rebase -m main >actual && |
Elijah Newren | 7db00f0 | 2020-02-15 21:36:26 +0000 | [diff] [blame] | 25 | test_must_be_empty actual |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 26 | ' |
| 27 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 28 | test_expect_success 'rebase against main twice' ' |
| 29 | git rebase --apply main >out && |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 30 | test_i18ngrep "Current branch topic is up to date" out |
| 31 | ' |
| 32 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 33 | test_expect_success 'rebase against main twice with --force' ' |
| 34 | git rebase --force-rebase --apply main >out && |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 35 | test_i18ngrep "Current branch topic is up to date, rebase forced" out |
| 36 | ' |
| 37 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 38 | test_expect_success 'rebase against main twice from another branch' ' |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 39 | git checkout topic^ && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 40 | git rebase --apply main topic >out && |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 41 | test_i18ngrep "Current branch topic is up to date" out |
| 42 | ' |
| 43 | |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 44 | test_expect_success 'rebase fast-forward to main' ' |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 45 | git checkout topic^ && |
Elijah Newren | 10cdb9f | 2020-02-15 21:36:41 +0000 | [diff] [blame] | 46 | git rebase --apply topic >out && |
Martin von Zweigbergk | c9581cc | 2013-06-06 23:11:43 -0700 | [diff] [blame] | 47 | test_i18ngrep "Fast-forwarded HEAD to topic" out |
| 48 | ' |
| 49 | |
Tor Arne Vestbø | a9c3821 | 2009-03-01 23:11:38 +0100 | [diff] [blame] | 50 | test_expect_success 'rebase --stat' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 51 | git reset --hard start && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 52 | git rebase --stat main >diffstat.txt && |
Johannes Schindelin | 0f321f9 | 2020-11-09 00:09:21 +0000 | [diff] [blame] | 53 | grep "^ fileX | *1 +$" diffstat.txt |
Tor Arne Vestbø | a9c3821 | 2009-03-01 23:11:38 +0100 | [diff] [blame] | 54 | ' |
| 55 | |
| 56 | test_expect_success 'rebase w/config rebase.stat' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 57 | git reset --hard start && |
Johannes Schindelin | 0f321f9 | 2020-11-09 00:09:21 +0000 | [diff] [blame] | 58 | git config rebase.stat true && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 59 | git rebase main >diffstat.txt && |
Johannes Schindelin | 0f321f9 | 2020-11-09 00:09:21 +0000 | [diff] [blame] | 60 | grep "^ fileX | *1 +$" diffstat.txt |
Tor Arne Vestbø | a9c3821 | 2009-03-01 23:11:38 +0100 | [diff] [blame] | 61 | ' |
| 62 | |
| 63 | test_expect_success 'rebase -n overrides config rebase.stat config' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 64 | git reset --hard start && |
Johannes Schindelin | 0f321f9 | 2020-11-09 00:09:21 +0000 | [diff] [blame] | 65 | git config rebase.stat true && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 66 | git rebase -n main >diffstat.txt && |
Johannes Schindelin | 0f321f9 | 2020-11-09 00:09:21 +0000 | [diff] [blame] | 67 | ! grep "^ fileX | *1 +$" diffstat.txt |
Tor Arne Vestbø | a9c3821 | 2009-03-01 23:11:38 +0100 | [diff] [blame] | 68 | ' |
| 69 | |
Erik Faye-Lund | 9180fea | 2012-05-30 18:39:42 +0200 | [diff] [blame] | 70 | test_expect_success 'rebase --onto outputs the invalid ref' ' |
| 71 | test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err && |
Jiang Xin | c7108bf | 2012-07-25 22:53:08 +0800 | [diff] [blame] | 72 | test_i18ngrep "invalid-ref" err |
Erik Faye-Lund | 9180fea | 2012-05-30 18:39:42 +0200 | [diff] [blame] | 73 | ' |
| 74 | |
Johannes Schindelin | 04519d7 | 2018-11-14 08:25:31 -0800 | [diff] [blame] | 75 | test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' ' |
| 76 | test_must_fail git rebase -Cnot-a-number HEAD 2>err && |
| 77 | test_i18ngrep "numerical value" err && |
| 78 | test_must_fail git rebase --whitespace=bad HEAD 2>err && |
| 79 | test_i18ngrep "Invalid whitespace option" err |
| 80 | ' |
| 81 | |
Johannes Schindelin | 13a5a9f | 2018-11-29 11:09:21 -0800 | [diff] [blame] | 82 | test_expect_success 'GIT_REFLOG_ACTION' ' |
| 83 | git checkout start && |
| 84 | test_commit reflog-onto && |
| 85 | git checkout -b reflog-topic start && |
| 86 | test_commit reflog-to-rebase && |
| 87 | |
Elijah Newren | 1f6965f | 2020-04-07 16:59:23 +0000 | [diff] [blame] | 88 | git rebase reflog-onto && |
Johannes Schindelin | 13a5a9f | 2018-11-29 11:09:21 -0800 | [diff] [blame] | 89 | git log -g --format=%gs -3 >actual && |
| 90 | cat >expect <<-\EOF && |
Elijah Newren | 1f6965f | 2020-04-07 16:59:23 +0000 | [diff] [blame] | 91 | rebase (finish): returning to refs/heads/reflog-topic |
| 92 | rebase (pick): reflog-to-rebase |
| 93 | rebase (start): checkout reflog-onto |
Johannes Schindelin | 13a5a9f | 2018-11-29 11:09:21 -0800 | [diff] [blame] | 94 | EOF |
| 95 | test_cmp expect actual && |
| 96 | |
| 97 | git checkout -b reflog-prefix reflog-to-rebase && |
Elijah Newren | 1f6965f | 2020-04-07 16:59:23 +0000 | [diff] [blame] | 98 | GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto && |
Johannes Schindelin | 13a5a9f | 2018-11-29 11:09:21 -0800 | [diff] [blame] | 99 | git log -g --format=%gs -3 >actual && |
| 100 | cat >expect <<-\EOF && |
Elijah Newren | 1f6965f | 2020-04-07 16:59:23 +0000 | [diff] [blame] | 101 | change-the-reflog (finish): returning to refs/heads/reflog-prefix |
| 102 | change-the-reflog (pick): reflog-to-rebase |
| 103 | change-the-reflog (start): checkout reflog-onto |
Johannes Schindelin | 13a5a9f | 2018-11-29 11:09:21 -0800 | [diff] [blame] | 104 | EOF |
| 105 | test_cmp expect actual |
| 106 | ' |
| 107 | |
Johannes Schindelin | 8797f0f | 2018-11-29 05:01:54 -0800 | [diff] [blame] | 108 | test_expect_success 'rebase -i onto unrelated history' ' |
| 109 | git init unrelated && |
| 110 | test_commit -C unrelated 1 && |
| 111 | git -C unrelated remote add -f origin "$PWD" && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 112 | git -C unrelated branch --set-upstream-to=origin/main && |
Johannes Schindelin | 8797f0f | 2018-11-29 05:01:54 -0800 | [diff] [blame] | 113 | git -C unrelated -c core.editor=true rebase -i -v --stat >actual && |
| 114 | test_i18ngrep "Changes to " actual && |
| 115 | test_i18ngrep "5 files changed" actual |
| 116 | ' |
| 117 | |
Johannes Sixt | 7afa845 | 2007-09-01 09:25:27 +0200 | [diff] [blame] | 118 | test_done |