Skip to content

Commit 234b3da

Browse files
mhaggergitster
authored andcommitted
rebase-i: Ignore comments and blank lines in peek_next_command
Previously, blank lines and/or comments within a series of squash/fixup commands would confuse "git rebase -i" into thinking that the series was finished. It would therefore require the user to edit the commit message for the squash/fixup commits seen so far. Then, after continuing, it would ask the user to edit the commit message again. Ignore comments and blank lines within a group of squash/fixup commands, allowing them to be processed in one go. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 05c95db commit 234b3da

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

git-rebase--interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ make_squash_message () {
338338
}
339339

340340
peek_next_command () {
341-
sed -n "1s/ .*$//p" < "$TODO"
341+
sed -n -e "/^#/d" -e "/^$/d" -e "s/ .*//p" -e "q" < "$TODO"
342342
}
343343

344344
do_next () {

t/t3404-rebase-interactive.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,30 @@ test_expect_success 'squash and fixup generate correct log messages' '
265265
git branch -D squash-fixup
266266
'
267267

268+
test_expect_success 'squash ignores comments' '
269+
git checkout -b skip-comments E &&
270+
base=$(git rev-parse HEAD~4) &&
271+
FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
272+
EXPECT_HEADER_COUNT=4 \
273+
git rebase -i $base &&
274+
test $base = $(git rev-parse HEAD^) &&
275+
test 1 = $(git show | grep ONCE | wc -l) &&
276+
git checkout to-be-rebased &&
277+
git branch -D skip-comments
278+
'
279+
280+
test_expect_success 'squash ignores blank lines' '
281+
git checkout -b skip-blank-lines E &&
282+
base=$(git rev-parse HEAD~4) &&
283+
FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
284+
EXPECT_HEADER_COUNT=4 \
285+
git rebase -i $base &&
286+
test $base = $(git rev-parse HEAD^) &&
287+
test 1 = $(git show | grep ONCE | wc -l) &&
288+
git checkout to-be-rebased &&
289+
git branch -D skip-blank-lines
290+
'
291+
268292
test_expect_success 'squash works as expected' '
269293
for n in one two three four
270294
do

0 commit comments

Comments
 (0)