Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t3406-rebase-message.sh
blobd17b450e811cc0f13ab94ac76e288f782e897d64
1 #!/bin/sh
3 test_description='messages from rebase operation'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
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 &&
17 git checkout -b topic O &&
18 git cherry-pick A B &&
19 test_commit Z fileZ &&
20 git tag start
23 test_expect_success 'rebase -m' '
24 git rebase -m main >actual &&
25 test_must_be_empty actual
28 test_expect_success 'rebase against main twice' '
29 git rebase --apply main >out &&
30 test_i18ngrep "Current branch topic is up to date" out
33 test_expect_success 'rebase against main twice with --force' '
34 git rebase --force-rebase --apply main >out &&
35 test_i18ngrep "Current branch topic is up to date, rebase forced" out
38 test_expect_success 'rebase against main twice from another branch' '
39 git checkout topic^ &&
40 git rebase --apply main topic >out &&
41 test_i18ngrep "Current branch topic is up to date" out
44 test_expect_success 'rebase fast-forward to main' '
45 git checkout topic^ &&
46 git rebase --apply topic >out &&
47 test_i18ngrep "Fast-forwarded HEAD to topic" out
50 test_expect_success 'rebase --stat' '
51 git reset --hard start &&
52 git rebase --stat main >diffstat.txt &&
53 grep "^ fileX | *1 +$" diffstat.txt
56 test_expect_success 'rebase w/config rebase.stat' '
57 git reset --hard start &&
58 git config rebase.stat true &&
59 git rebase main >diffstat.txt &&
60 grep "^ fileX | *1 +$" diffstat.txt
63 test_expect_success 'rebase -n overrides config rebase.stat config' '
64 git reset --hard start &&
65 git config rebase.stat true &&
66 git rebase -n main >diffstat.txt &&
67 ! grep "^ fileX | *1 +$" diffstat.txt
70 test_expect_success 'rebase --onto outputs the invalid ref' '
71 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
72 test_i18ngrep "invalid-ref" err
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
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 &&
88 git rebase reflog-onto &&
89 git log -g --format=%gs -3 >actual &&
90 cat >expect <<-\EOF &&
91 rebase (finish): returning to refs/heads/reflog-topic
92 rebase (pick): reflog-to-rebase
93 rebase (start): checkout reflog-onto
94 EOF
95 test_cmp expect actual &&
97 git checkout -b reflog-prefix reflog-to-rebase &&
98 GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
99 git log -g --format=%gs -3 >actual &&
100 cat >expect <<-\EOF &&
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
105 test_cmp expect actual
108 test_expect_success 'rebase --apply reflog' '
109 git checkout -b reflog-apply start &&
110 old_head_reflog="$(git log -g --format=%gs -1 HEAD)" &&
112 git rebase --apply Y &&
114 git log -g --format=%gs -4 HEAD >actual &&
115 cat >expect <<-EOF &&
116 rebase finished: returning to refs/heads/reflog-apply
117 rebase: Z
118 rebase: checkout Y
119 $old_head_reflog
121 test_cmp expect actual &&
123 git log -g --format=%gs -2 reflog-apply >actual &&
124 cat >expect <<-EOF &&
125 rebase finished: refs/heads/reflog-apply onto $(git rev-parse Y)
126 branch: Created from start
128 test_cmp expect actual
131 test_expect_success 'rebase -i onto unrelated history' '
132 git init unrelated &&
133 test_commit -C unrelated 1 &&
134 git -C unrelated remote add -f origin "$PWD" &&
135 git -C unrelated branch --set-upstream-to=origin/main &&
136 git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
137 test_i18ngrep "Changes to " actual &&
138 test_i18ngrep "5 files changed" actual
141 test_done