blob: 77a313f62eb36c5c340dff627e3c0afcffb65792 [file] [log] [blame]
Johannes Sixt7afa8452007-09-01 09:25:27 +02001#!/bin/sh
2
3test_description='messages from rebase operation'
4
Johannes Schindelind1c02d92020-11-18 23:44:25 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Johannes Sixt7afa8452007-09-01 09:25:27 +02008. ./test-lib.sh
9
Martin von Zweigbergk9e2248e2013-06-06 23:11:42 -070010test_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 Sixt7afa8452007-09-01 09:25:27 +020016
Martin von Zweigbergk9e2248e2013-06-06 23:11:42 -070017 git checkout -b topic O &&
18 git cherry-pick A B &&
19 test_commit Z fileZ &&
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +010020 git tag start
Johannes Sixt7afa8452007-09-01 09:25:27 +020021'
22
Johannes Sixt7afa8452007-09-01 09:25:27 +020023test_expect_success 'rebase -m' '
Johannes Schindelind1c02d92020-11-18 23:44:25 +000024 git rebase -m main >actual &&
Elijah Newren7db00f02020-02-15 21:36:26 +000025 test_must_be_empty actual
Johannes Sixt7afa8452007-09-01 09:25:27 +020026'
27
Johannes Schindelind1c02d92020-11-18 23:44:25 +000028test_expect_success 'rebase against main twice' '
29 git rebase --apply main >out &&
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070030 test_i18ngrep "Current branch topic is up to date" out
31'
32
Johannes Schindelind1c02d92020-11-18 23:44:25 +000033test_expect_success 'rebase against main twice with --force' '
34 git rebase --force-rebase --apply main >out &&
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070035 test_i18ngrep "Current branch topic is up to date, rebase forced" out
36'
37
Johannes Schindelind1c02d92020-11-18 23:44:25 +000038test_expect_success 'rebase against main twice from another branch' '
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070039 git checkout topic^ &&
Johannes Schindelind1c02d92020-11-18 23:44:25 +000040 git rebase --apply main topic >out &&
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070041 test_i18ngrep "Current branch topic is up to date" out
42'
43
Johannes Schindelind1c02d92020-11-18 23:44:25 +000044test_expect_success 'rebase fast-forward to main' '
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070045 git checkout topic^ &&
Elijah Newren10cdb9f2020-02-15 21:36:41 +000046 git rebase --apply topic >out &&
Martin von Zweigbergkc9581cc2013-06-06 23:11:43 -070047 test_i18ngrep "Fast-forwarded HEAD to topic" out
48'
49
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +010050test_expect_success 'rebase --stat' '
Jonathan Niedera48fcd82010-10-30 20:46:54 -050051 git reset --hard start &&
Johannes Schindelind1c02d92020-11-18 23:44:25 +000052 git rebase --stat main >diffstat.txt &&
Johannes Schindelin0f321f92020-11-09 00:09:21 +000053 grep "^ fileX | *1 +$" diffstat.txt
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +010054'
55
56test_expect_success 'rebase w/config rebase.stat' '
Jonathan Niedera48fcd82010-10-30 20:46:54 -050057 git reset --hard start &&
Johannes Schindelin0f321f92020-11-09 00:09:21 +000058 git config rebase.stat true &&
Johannes Schindelind1c02d92020-11-18 23:44:25 +000059 git rebase main >diffstat.txt &&
Johannes Schindelin0f321f92020-11-09 00:09:21 +000060 grep "^ fileX | *1 +$" diffstat.txt
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +010061'
62
63test_expect_success 'rebase -n overrides config rebase.stat config' '
Jonathan Niedera48fcd82010-10-30 20:46:54 -050064 git reset --hard start &&
Johannes Schindelin0f321f92020-11-09 00:09:21 +000065 git config rebase.stat true &&
Johannes Schindelind1c02d92020-11-18 23:44:25 +000066 git rebase -n main >diffstat.txt &&
Johannes Schindelin0f321f92020-11-09 00:09:21 +000067 ! grep "^ fileX | *1 +$" diffstat.txt
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +010068'
69
Erik Faye-Lund9180fea2012-05-30 18:39:42 +020070test_expect_success 'rebase --onto outputs the invalid ref' '
71 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
Jiang Xinc7108bf2012-07-25 22:53:08 +080072 test_i18ngrep "invalid-ref" err
Erik Faye-Lund9180fea2012-05-30 18:39:42 +020073'
74
Johannes Schindelin04519d72018-11-14 08:25:31 -080075test_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 Schindelin13a5a9f2018-11-29 11:09:21 -080082test_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 Newren1f6965f2020-04-07 16:59:23 +000088 git rebase reflog-onto &&
Johannes Schindelin13a5a9f2018-11-29 11:09:21 -080089 git log -g --format=%gs -3 >actual &&
90 cat >expect <<-\EOF &&
Elijah Newren1f6965f2020-04-07 16:59:23 +000091 rebase (finish): returning to refs/heads/reflog-topic
92 rebase (pick): reflog-to-rebase
93 rebase (start): checkout reflog-onto
Johannes Schindelin13a5a9f2018-11-29 11:09:21 -080094 EOF
95 test_cmp expect actual &&
96
97 git checkout -b reflog-prefix reflog-to-rebase &&
Elijah Newren1f6965f2020-04-07 16:59:23 +000098 GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
Johannes Schindelin13a5a9f2018-11-29 11:09:21 -080099 git log -g --format=%gs -3 >actual &&
100 cat >expect <<-\EOF &&
Elijah Newren1f6965f2020-04-07 16:59:23 +0000101 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 Schindelin13a5a9f2018-11-29 11:09:21 -0800104 EOF
105 test_cmp expect actual
106'
107
Johannes Schindelin8797f0f2018-11-29 05:01:54 -0800108test_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 Schindelind1c02d92020-11-18 23:44:25 +0000112 git -C unrelated branch --set-upstream-to=origin/main &&
Johannes Schindelin8797f0f2018-11-29 05:01:54 -0800113 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 Sixt7afa8452007-09-01 09:25:27 +0200118test_done