@@ -10,10 +10,15 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
10
test_expect_success ' setup' '
11
11
test_commit O fileO &&
12
12
test_commit X fileX &&
13
+ git branch fast-forward &&
13
14
test_commit A fileA &&
14
15
test_commit B fileB &&
15
16
test_commit Y fileY &&
16
17
18
+ git checkout -b conflicts O &&
19
+ test_commit P &&
20
+ test_commit Q &&
21
+
17
22
git checkout -b topic O &&
18
23
git cherry-pick A B &&
19
24
test_commit Z fileZ &&
@@ -79,54 +84,86 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
79
84
test_i18ngrep "Invalid whitespace option" err
80
85
'
81
86
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
-
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
87
+ write_reflog_expect () {
88
+ if test $mode = --apply
89
+ then
90
+ sed ' s/.*(finish)/rebase finished/; s/ ([^)]*)//'
91
+ else
92
+ cat
93
+ fi > expect
94
+ }
95
+
96
+ test_reflog () {
97
+ mode=$1
98
+ reflog_action=" $2 "
99
+
100
+ test_expect_success " rebase $mode reflog${reflog_action: + GIT_REFLOG_ACTION=$reflog_action } " '
101
+ git checkout conflicts &&
102
+ test_when_finished "git reset --hard Q" &&
103
+
104
+ (
105
+ if test -n "$reflog_action"
106
+ then
107
+ GIT_REFLOG_ACTION="$reflog_action" &&
108
+ export GIT_REFLOG_ACTION
109
+ fi &&
110
+ git rebase $mode main
111
+ ) &&
112
+
113
+ git log -g --format=%gs -4 >actual &&
114
+ write_reflog_expect <<-EOF &&
115
+ ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
116
+ ${reflog_action:-rebase} (pick): Q
117
+ ${reflog_action:-rebase} (pick): P
118
+ ${reflog_action:-rebase} (start): checkout main
94
119
EOF
95
120
test_cmp expect actual &&
96
121
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
122
+ git log -g --format=%gs -1 conflicts >actual &&
123
+ write_reflog_expect <<-EOF &&
124
+ ${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main)
104
125
EOF
105
- test_cmp expect actual
106
- '
107
-
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)" &&
111
-
112
- git rebase --apply Y &&
126
+ test_cmp expect actual &&
113
127
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
128
+ # check there is only one new entry in the branch reflog
129
+ test_cmp_rev conflicts@{1} Q
130
+ '
131
+
132
+ test_expect_success " rebase $mode fast-forward reflog${reflog_action: + GIT_REFLOG_ACTION=$reflog_action } " '
133
+ git checkout fast-forward &&
134
+ test_when_finished "git reset --hard X" &&
135
+
136
+ (
137
+ if test -n "$reflog_action"
138
+ then
139
+ GIT_REFLOG_ACTION="$reflog_action" &&
140
+ export GIT_REFLOG_ACTION
141
+ fi &&
142
+ git rebase $mode main
143
+ ) &&
144
+
145
+ git log -g --format=%gs -2 >actual &&
146
+ write_reflog_expect <<-EOF &&
147
+ ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward
148
+ ${reflog_action:-rebase} (start): checkout main
120
149
EOF
121
150
test_cmp expect actual &&
122
151
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
152
+ git log -g --format=%gs -1 fast-forward >actual &&
153
+ write_reflog_expect <<-EOF &&
154
+ ${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main)
127
155
EOF
128
- test_cmp expect actual
129
- '
156
+ test_cmp expect actual &&
157
+
158
+ # check there is only one new entry in the branch reflog
159
+ test_cmp_rev fast-forward@{1} X
160
+ '
161
+ }
162
+
163
+ test_reflog --merge
164
+ test_reflog --merge my-reflog-action
165
+ test_reflog --apply
166
+ test_reflog --apply my-reflog-action
130
167
131
168
test_expect_success ' rebase -i onto unrelated history' '
132
169
git init unrelated &&
0 commit comments