Skip to content

Commit 666b6e1

Browse files
phillipwoodgitster
authored andcommitted
rebase -i: fix parsing of "fixup -C<commit>"
If the user omits the space between "-C" and the commit in a fixup command then it is parsed as an ordinary fixup and the commit message is not updated as it should be. Fix this by making the space between "-C" and "<commit>" optional as it is for the "merge" command. Note that set_replace_editor() is changed to set $GIT_SEQUENCE_EDITOR instead of $EDITOR in order to be able to replace the todo list and reword commits with $FAKE_COMMIT_MESSAGE. This is safe as all the existing users are using set_replace_editor() to replace the todo list. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7aed2c0 commit 666b6e1

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

sequencer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,12 +2532,10 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
25322532
}
25332533

25342534
if (item->command == TODO_FIXUP) {
2535-
if (skip_prefix(bol, "-C", &bol) &&
2536-
(*bol == ' ' || *bol == '\t')) {
2535+
if (skip_prefix(bol, "-C", &bol)) {
25372536
bol += strspn(bol, " \t");
25382537
item->flags |= TODO_REPLACE_FIXUP_MSG;
2539-
} else if (skip_prefix(bol, "-c", &bol) &&
2540-
(*bol == ' ' || *bol == '\t')) {
2538+
} else if (skip_prefix(bol, "-c", &bol)) {
25412539
bol += strspn(bol, " \t");
25422540
item->flags |= TODO_EDIT_FIXUP_MSG;
25432541
}

t/lib-rebase.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ check_reworded_commits () {
211211
# usage: set_replace_editor <file>
212212
#
213213
# Replace the todo file with the exact contents of the given file.
214+
# N.B. sets GIT_SEQUENCE_EDITOR rather than EDITOR so it can be
215+
# combined with set_fake_editor to reword commits and replace the
216+
# todo list
214217
set_replace_editor () {
215218
cat >script <<-\EOF &&
216219
cat FILENAME >"$1"
@@ -219,6 +222,7 @@ set_replace_editor () {
219222
cat "$1"
220223
EOF
221224

222-
sed -e "s/FILENAME/$1/g" <script | write_script fake-editor.sh &&
223-
test_set_editor "$(pwd)/fake-editor.sh"
225+
sed -e "s/FILENAME/$1/g" script |
226+
write_script fake-sequence-editor.sh &&
227+
test_set_sequence_editor "$(pwd)/fake-sequence-editor.sh"
224228
}

t/t3437-rebase-fixup-options.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test_expect_success 'setup' '
5050
body
5151
EOF
5252
53+
test_commit initial &&
5354
test_commit A A &&
5455
test_commit B B &&
5556
get_author HEAD >expected-author &&
@@ -208,4 +209,29 @@ test_expect_success 'fixup -C works upon --autosquash with amend!' '
208209
actual-squash-message
209210
'
210211

212+
test_expect_success 'fixup -[Cc]<commit> works' '
213+
test_when_finished "test_might_fail git rebase --abort" &&
214+
cat >todo <<-\EOF &&
215+
pick A
216+
fixup -CA1
217+
pick B
218+
fixup -cA2
219+
EOF
220+
(
221+
set_replace_editor todo &&
222+
FAKE_COMMIT_MESSAGE="edited and fixed up" \
223+
git rebase -i initial initial
224+
) &&
225+
git log --pretty=format:%B initial.. >actual &&
226+
cat >expect <<-EOF &&
227+
edited and fixed up
228+
$EMPTY
229+
new subject
230+
$EMPTY
231+
new
232+
body
233+
EOF
234+
test_cmp expect actual
235+
'
236+
211237
test_done

t/test-lib-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ test_set_editor () {
3232
export EDITOR
3333
}
3434

35+
# Like test_set_editor but sets GIT_SEQUENCE_EDITOR instead of EDITOR
36+
test_set_sequence_editor () {
37+
FAKE_SEQUENCE_EDITOR="$1"
38+
export FAKE_SEQUENCE_EDITOR
39+
GIT_SEQUENCE_EDITOR='"$FAKE_SEQUENCE_EDITOR"'
40+
export GIT_SEQUENCE_EDITOR
41+
}
42+
3543
test_decode_color () {
3644
awk '
3745
function name(n) {

0 commit comments

Comments
 (0)