Skip to content

Commit fde07fc

Browse files
committed
Merge branch 'cm/rebase-i-updates'
Follow-up fixes to "cm/rebase-i" topic. * cm/rebase-i-updates: doc/rebase -i: fix typo in the documentation of 'fixup' command t/t3437: fixup the test 'multiple fixup -c opens editor once' t/t3437: use named commits in the tests t/t3437: simplify and document the test helpers t/t3437: check the author date of fixed up commit t/t3437: remove the dependency of 'expected-message' file from tests t/t3437: fixup here-docs in the 'setup' test t/lib-rebase: update the documentation of FAKE_LINES rebase -i: clarify and fix 'fixup -c' rebase-todo help sequencer: rename a few functions sequencer: fixup the datatype of the 'flag' argument
2 parents ce4296c + fa153c1 commit fde07fc

File tree

5 files changed

+87
-76
lines changed

5 files changed

+87
-76
lines changed

Documentation/git-rebase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ is used. In that case the suggested commit message is only the message
894894
of the "fixup -c" commit, and an editor is opened allowing you to edit
895895
the message. The contents (patch) of the "fixup -c" commit are still
896896
incorporated into the folded commit. If there is more than one "fixup -c"
897-
commit, the message from the last last one is used. You can also use
897+
commit, the message from the final one is used. You can also use
898898
"fixup -C" to get the same behavior as "fixup -c" except without opening
899899
an editor.
900900

rebase-interactive.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ void append_todo_help(int command_count,
4444
"r, reword <commit> = use commit, but edit the commit message\n"
4545
"e, edit <commit> = use commit, but stop for amending\n"
4646
"s, squash <commit> = use commit, but meld into previous commit\n"
47-
"f, fixup [-C | -c] <commit> = like \"squash\", but discard this\n"
48-
" commit's log message. Use -C to replace with this\n"
49-
" commit message or -c to edit the commit message\n"
47+
"f, fixup [-C | -c] <commit> = like \"squash\" but keep only the previous\n"
48+
" commit's log message, unless -C is used, in which case\n"
49+
" keep only this commit's message; -c is same as -C but\n"
50+
" opens the editor\n"
5051
"x, exec <command> = run command (the rest of the line) using shell\n"
5152
"b, break = stop here (continue rebase later with 'git rebase --continue')\n"
5253
"d, drop <commit> = remove commit\n"
@@ -55,7 +56,7 @@ void append_todo_help(int command_count,
5556
"m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]\n"
5657
". create a merge commit using the original merge commit's\n"
5758
". message (or the oneline, if no original merge commit was\n"
58-
". specified). Use -c <commit> to reword the commit message.\n"
59+
". specified); use -c <commit> to reword the commit message\n"
5960
"\n"
6061
"These lines can be re-ordered; they are executed from top to bottom.\n");
6162
unsigned edit_todo = !(shortrevisions && shortonto);

sequencer.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,8 +1752,7 @@ static const char skip_first_commit_msg_str[] = N_("The 1st commit message will
17521752
static const char skip_nth_commit_msg_fmt[] = N_("The commit message #%d will be skipped:");
17531753
static const char combined_commit_msg_fmt[] = N_("This is a combination of %d commits.");
17541754

1755-
static int check_fixup_flag(enum todo_command command,
1756-
enum todo_item_flags flag)
1755+
static int is_fixup_flag(enum todo_command command, unsigned flag)
17571756
{
17581757
return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) ||
17591758
(flag & TODO_EDIT_FIXUP_MSG));
@@ -1858,7 +1857,7 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
18581857

18591858
static int append_squash_message(struct strbuf *buf, const char *body,
18601859
enum todo_command command, struct replay_opts *opts,
1861-
enum todo_item_flags flag)
1860+
unsigned flag)
18621861
{
18631862
const char *fixup_msg;
18641863
size_t commented_len = 0, fixup_off;
@@ -1882,7 +1881,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
18821881
strbuf_addstr(buf, body + commented_len);
18831882

18841883
/* fixup -C after squash behaves like squash */
1885-
if (check_fixup_flag(command, flag) && !seen_squash(opts)) {
1884+
if (is_fixup_flag(command, flag) && !seen_squash(opts)) {
18861885
/*
18871886
* We're replacing the commit message so we need to
18881887
* append the Signed-off-by: trailer if the user
@@ -1914,7 +1913,7 @@ static int update_squash_messages(struct repository *r,
19141913
enum todo_command command,
19151914
struct commit *commit,
19161915
struct replay_opts *opts,
1917-
enum todo_item_flags flag)
1916+
unsigned flag)
19181917
{
19191918
struct strbuf buf = STRBUF_INIT;
19201919
int res = 0;
@@ -1937,7 +1936,7 @@ static int update_squash_messages(struct repository *r,
19371936
opts->current_fixup_count + 2);
19381937
strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
19391938
strbuf_release(&header);
1940-
if (check_fixup_flag(command, flag) && !seen_squash(opts))
1939+
if (is_fixup_flag(command, flag) && !seen_squash(opts))
19411940
update_squash_message_for_fixup(&buf);
19421941
} else {
19431942
struct object_id head;
@@ -1960,11 +1959,11 @@ static int update_squash_messages(struct repository *r,
19601959
strbuf_addf(&buf, "%c ", comment_line_char);
19611960
strbuf_addf(&buf, _(combined_commit_msg_fmt), 2);
19621961
strbuf_addf(&buf, "\n%c ", comment_line_char);
1963-
strbuf_addstr(&buf, check_fixup_flag(command, flag) ?
1962+
strbuf_addstr(&buf, is_fixup_flag(command, flag) ?
19641963
_(skip_first_commit_msg_str) :
19651964
_(first_commit_msg_str));
19661965
strbuf_addstr(&buf, "\n\n");
1967-
if (check_fixup_flag(command, flag))
1966+
if (is_fixup_flag(command, flag))
19681967
strbuf_add_commented_lines(&buf, body, strlen(body));
19691968
else
19701969
strbuf_addstr(&buf, body);
@@ -1977,7 +1976,7 @@ static int update_squash_messages(struct repository *r,
19771976
oid_to_hex(&commit->object.oid));
19781977
find_commit_subject(message, &body);
19791978

1980-
if (command == TODO_SQUASH || check_fixup_flag(command, flag)) {
1979+
if (command == TODO_SQUASH || is_fixup_flag(command, flag)) {
19811980
res = append_squash_message(&buf, body, command, opts, flag);
19821981
} else if (command == TODO_FIXUP) {
19831982
strbuf_addf(&buf, "\n%c ", comment_line_char);
@@ -5670,7 +5669,7 @@ static int subject2item_cmp(const void *fndata,
56705669

56715670
define_commit_slab(commit_todo_item, struct todo_item *);
56725671

5673-
static inline int skip_fixup_amend_squash(const char *subject, const char **p) {
5672+
static int skip_fixupish(const char *subject, const char **p) {
56745673
return skip_prefix(subject, "fixup! ", p) ||
56755674
skip_prefix(subject, "amend! ", p) ||
56765675
skip_prefix(subject, "squash! ", p);
@@ -5734,13 +5733,13 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
57345733
format_subject(&buf, subject, " ");
57355734
subject = subjects[i] = strbuf_detach(&buf, &subject_len);
57365735
unuse_commit_buffer(item->commit, commit_buffer);
5737-
if (skip_fixup_amend_squash(subject, &p)) {
5736+
if (skip_fixupish(subject, &p)) {
57385737
struct commit *commit2;
57395738

57405739
for (;;) {
57415740
while (isspace(*p))
57425741
p++;
5743-
if (!skip_fixup_amend_squash(p, &p))
5742+
if (!skip_fixupish(p, &p))
57445743
break;
57455744
}
57465745

t/lib-rebase.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
# specified line.
1616
#
1717
# "<cmd> <lineno>" -- add a line with the specified command
18-
# ("pick", "squash", "fixup", "edit", "reword" or "drop") and the
19-
# SHA1 taken from the specified line.
18+
# ("pick", "squash", "fixup"|"fixup_-C"|"fixup_-c", "edit", "reword" or "drop")
19+
# and the SHA1 taken from the specified line.
2020
#
21-
# "exec_cmd_with_args" -- add an "exec cmd with args" line.
21+
# "_" -- add a space, like "fixup_-C" implies "fixup -C" and
22+
# "exec_cmd_with_args" add an "exec cmd with args" line.
2223
#
2324
# "#" -- Add a comment line.
2425
#

t/t3437-rebase-fixup-options.sh

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ This test checks the "fixup [-C|-c]" command of rebase interactive.
99
In addition to amending the contents of the commit, "fixup -C"
1010
replaces the original commit message with the message of the fixup
1111
commit. "fixup -c" also replaces the original message, but opens the
12-
editor to allow the user to edit the message before committing.
12+
editor to allow the user to edit the message before committing. Similar
13+
to the "fixup" command that works with "fixup!", "fixup -C" works with
14+
"amend!" upon --autosquash.
1315
'
1416

1517
. ./test-lib.sh
@@ -18,35 +20,35 @@ editor to allow the user to edit the message before committing.
1820

1921
EMPTY=""
2022

23+
# test_commit_message <rev> -m <msg>
24+
# test_commit_message <rev> <path>
25+
# Verify that the commit message of <rev> matches
26+
# <msg> or the content of <path>.
2127
test_commit_message () {
22-
rev="$1" && # commit or tag we want to test
23-
file="$2" && # test against the content of a file
24-
git show --no-patch --pretty=format:%B "$rev" >actual-message &&
25-
if test "$2" = -m
26-
then
27-
str="$3" && # test against a string
28-
printf "%s\n" "$str" >tmp-expected-message &&
29-
file="tmp-expected-message"
30-
fi
31-
test_cmp "$file" actual-message
28+
git show --no-patch --pretty=format:%B "$1" >actual &&
29+
case "$2" in
30+
-m)
31+
echo "$3" >expect &&
32+
test_cmp expect actual ;;
33+
*)
34+
test_cmp "$2" actual ;;
35+
esac
3236
}
3337

3438
get_author () {
3539
rev="$1" &&
36-
git log -1 --pretty=format:"%an %ae" "$rev"
40+
git log -1 --pretty=format:"%an %ae %at" "$rev"
3741
}
3842

3943
test_expect_success 'setup' '
4044
cat >message <<-EOF &&
41-
amend! B
42-
${EMPTY}
43-
new subject
44-
${EMPTY}
45-
new
46-
body
47-
EOF
48-
49-
sed "1,2d" message >expected-message &&
45+
amend! B
46+
$EMPTY
47+
new subject
48+
$EMPTY
49+
new
50+
body
51+
EOF
5052
5153
test_commit A A &&
5254
test_commit B B &&
@@ -68,40 +70,43 @@ test_expect_success 'setup' '
6870
echo B1 >B &&
6971
test_tick &&
7072
git commit --fixup=HEAD -a &&
73+
git tag B1 &&
7174
test_tick &&
7275
git commit --allow-empty -F - <<-EOF &&
73-
amend! B
74-
${EMPTY}
75-
B
76-
${EMPTY}
77-
edited 1
78-
EOF
76+
amend! B
77+
$EMPTY
78+
B
79+
$EMPTY
80+
edited 1
81+
EOF
7982
test_tick &&
8083
git commit --allow-empty -F - <<-EOF &&
81-
amend! amend! B
82-
${EMPTY}
83-
B
84-
${EMPTY}
85-
edited 1
86-
${EMPTY}
87-
edited 2
88-
EOF
84+
amend! amend! B
85+
$EMPTY
86+
B
87+
$EMPTY
88+
edited 1
89+
$EMPTY
90+
edited 2
91+
EOF
8992
echo B2 >B &&
9093
test_tick &&
9194
FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
95+
git tag B2 &&
9296
echo B3 >B &&
9397
test_tick &&
9498
git commit -a -F - <<-EOF &&
95-
amend! amend! amend! B
96-
${EMPTY}
97-
B
98-
${EMPTY}
99-
edited 1
100-
${EMPTY}
101-
edited 2
102-
${EMPTY}
103-
edited 3
104-
EOF
99+
amend! amend! amend! B
100+
$EMPTY
101+
B
102+
$EMPTY
103+
edited 1
104+
$EMPTY
105+
edited 2
106+
$EMPTY
107+
edited 3
108+
EOF
109+
git tag B3 &&
105110
106111
GIT_AUTHOR_NAME="Rebase Author" &&
107112
GIT_AUTHOR_EMAIL="[email protected]" &&
@@ -134,6 +139,7 @@ test_expect_success 'simple fixup -c works' '
134139
test_expect_success 'fixup -C removes amend! from message' '
135140
test_when_finished "test_might_fail git rebase --abort" &&
136141
git checkout --detach A1 &&
142+
git log -1 --pretty=format:%b >expected-message &&
137143
FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
138144
test_cmp_rev HEAD^ A &&
139145
test_cmp_rev HEAD^{tree} A1^{tree} &&
@@ -145,13 +151,14 @@ test_expect_success 'fixup -C removes amend! from message' '
145151
test_expect_success 'fixup -C with conflicts gives correct message' '
146152
test_when_finished "test_might_fail git rebase --abort" &&
147153
git checkout --detach A1 &&
154+
git log -1 --pretty=format:%b >expected-message &&
155+
test_write_lines "" "edited" >>expected-message &&
148156
test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
149157
git checkout --theirs -- A &&
150158
git add A &&
151159
FAKE_COMMIT_AMEND=edited git rebase --continue &&
152160
test_cmp_rev HEAD^ conflicts &&
153161
test_cmp_rev HEAD^{tree} A1^{tree} &&
154-
test_write_lines "" edited >>expected-message &&
155162
test_commit_message HEAD expected-message &&
156163
get_author HEAD >actual-author &&
157164
test_cmp expected-author actual-author
@@ -167,20 +174,20 @@ test_expect_success 'skipping fixup -C after fixup gives correct message' '
167174
'
168175

169176
test_expect_success 'sequence of fixup, fixup -C & squash --signoff works' '
170-
git checkout --detach branch &&
177+
git checkout --detach B3 &&
171178
FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
172179
FAKE_COMMIT_AMEND=squashed \
173180
FAKE_MESSAGE_COPY=actual-squash-message \
174181
git -c commit.status=false rebase -ik --signoff A &&
175-
git diff-tree --exit-code --patch HEAD branch -- &&
182+
git diff-tree --exit-code --patch HEAD B3 -- &&
176183
test_cmp_rev HEAD^ A &&
177184
test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
178185
actual-squash-message
179186
'
180187

181188
test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
182189
test_when_finished "test_might_fail git rebase --abort" &&
183-
git checkout branch && git checkout --detach branch~2 &&
190+
git checkout --detach B2~ &&
184191
git log -1 --pretty=format:%b >expected-message &&
185192
FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
186193
test_cmp_rev HEAD^ A &&
@@ -190,13 +197,16 @@ test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fix
190197
test_expect_success 'multiple fixup -c opens editor once' '
191198
test_when_finished "test_might_fail git rebase --abort" &&
192199
git checkout --detach A3 &&
193-
base=$(git rev-parse HEAD~4) &&
194-
FAKE_COMMIT_MESSAGE="Modified-A3" \
200+
git log -1 --pretty=format:%B >expected-message &&
201+
test_write_lines "" "Modified-A3" >>expected-message &&
202+
FAKE_COMMIT_AMEND="Modified-A3" \
195203
FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
196204
EXPECT_HEADER_COUNT=4 \
197-
git rebase -i $base &&
198-
test_cmp_rev $base HEAD^ &&
199-
test 1 = $(git show | grep Modified-A3 | wc -l)
205+
git rebase -i A &&
206+
test_cmp_rev HEAD^ A &&
207+
get_author HEAD >actual-author &&
208+
test_cmp expected-author actual-author &&
209+
test_commit_message HEAD expected-message
200210
'
201211

202212
test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
@@ -211,12 +221,12 @@ test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
211221
'
212222

213223
test_expect_success 'fixup -C works upon --autosquash with amend!' '
214-
git checkout --detach branch &&
224+
git checkout --detach B3 &&
215225
FAKE_COMMIT_AMEND=squashed \
216226
FAKE_MESSAGE_COPY=actual-squash-message \
217227
git -c commit.status=false rebase -ik --autosquash \
218228
--signoff A &&
219-
git diff-tree --exit-code --patch HEAD branch -- &&
229+
git diff-tree --exit-code --patch HEAD B3 -- &&
220230
test_cmp_rev HEAD^ A &&
221231
test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
222232
actual-squash-message

0 commit comments

Comments
 (0)