# [PATCHv2 0/3] rebase-i: Ignore comments and blank lines among squash/fixup commands

6 messages from 2010-01-12 to 2010-01-13. Participants: Michael Haggerty, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/22181

## Michael Haggerty, 2010-01-12 15:38

Subject: [PATCHv2 0/3] rebase-i: Ignore comments and blank lines among squash/fixup commands
Message-ID: <cover.1263310175.git.mhagger@alum.mit.edu>
URL: https://gitlist.dev/e/cover.1263310175.git.mhagger%40alum.mit.edu
In-Reply-To: <7vr5pw3pwp.fsf@alter.siamese.dyndns.org>

```
Here is v2 of the patch (now patch series) for making "rebase -i"
ignore comments and blank lines while it is processing blocks of
squash/fixup commands.

Please note that this version applies to "next", not "master", because
it depends on some changes to t/t3404-rebase-interactive.sh that were
made in mh/rebase-fixup.  (This dependency is superficial and could be
removed if necessary.)

The first patch in this series is not essential to the functionality
but I found it useful when debugging the tests.

Michael Haggerty (3):
  lib-rebase: Provide clearer debugging info about what the editor did
  lib-rebase: Allow comments and blank lines to be added to the rebase
    script
  rebase-i: Ignore comments and blank lines in peek_next_command

 git-rebase--interactive.sh    |    2 +-
 t/lib-rebase.sh               |   26 +++++++++++++++++++-------
 t/t3404-rebase-interactive.sh |   24 ++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 8 deletions(-)

```

## Michael Haggerty, 2010-01-12 15:38

Subject: [PATCHv2 1/3] lib-rebase: Provide clearer debugging info about what the editor did
Message-ID: <a6ef19853c00263c2875026cb438ce46d3fcf950.1263310175.git.mhagger@alum.mit.edu>
URL: https://gitlist.dev/e/a6ef19853c00263c2875026cb438ce46d3fcf950.1263310175.git.mhagger%40alum.mit.edu
In-Reply-To: <7vr5pw3pwp.fsf@alter.siamese.dyndns.org>

```
(For testing "rebase -i"): Output the "rebase -i" command script
before and after the edits, to make it clearer what the editor did.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 t/lib-rebase.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index f4dda02..0fce595 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -29,6 +29,7 @@ test -z "$EXPECT_COUNT" ||
 test -z "$FAKE_LINES" && exit
 grep -v '^#' < "$1" > "$1".tmp
 rm -f "$1"
+echo 'rebase -i script before editing:'
 cat "$1".tmp
 action=pick
 for line in $FAKE_LINES; do
@@ -36,12 +37,12 @@ for line in $FAKE_LINES; do
 	squash|fixup|edit|reword)
 		action="$line";;
 	*)
-		echo sed -n "${line}s/^pick/$action/p"
-		sed -n "${line}p" < "$1".tmp
 		sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
 		action=pick;;
 	esac
 done
+echo 'rebase -i script after editing:'
+cat "$1"
 EOF
 
 	test_set_editor "$(pwd)/fake-editor.sh"
-- 
1.6.6.140.ga53ad

```

## Michael Haggerty, 2010-01-12 15:38

Subject: [PATCHv2 2/3] lib-rebase: Allow comments and blank lines to be added to the rebase script
Message-ID: <253943b83514372775e375575bba9d7de33c0b28.1263310175.git.mhagger@alum.mit.edu>
URL: https://gitlist.dev/e/253943b83514372775e375575bba9d7de33c0b28.1263310175.git.mhagger%40alum.mit.edu
In-Reply-To: <7vr5pw3pwp.fsf@alter.siamese.dyndns.org>

```
(For testing "rebase -i"): Support new action types in $FAKE_LINES to
allow comments and blank lines to be added to the "rebase -i" command
list.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 t/lib-rebase.sh |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 0fce595..0db8250 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -5,13 +5,20 @@
 # - override the commit message with $FAKE_COMMIT_MESSAGE,
 # - amend the commit message with $FAKE_COMMIT_AMEND
 # - check that non-commit messages have a certain line count with $EXPECT_COUNT
-# - rewrite a rebase -i script with $FAKE_LINES in the form
+# - rewrite a rebase -i script as directed by $FAKE_LINES.
+#   $FAKE_LINES consists of a sequence of words separated by spaces.
+#   The following word combinations are possible:
 #
-#	"[<lineno1>] [<lineno2>]..."
+#   "<lineno>" -- add a "pick" line with the SHA1 taken from the
+#       specified line.
 #
-#   If a line number is prefixed with "squash", "fixup", "edit", or
-#   "reword", the respective line's command will be replaced with the
-#   specified one.
+#   "<cmd> <lineno>" -- add a line with the specified command
+#       ("squash", "fixup", "edit", or "reword") and the SHA1 taken
+#       from the specified line.
+#
+#   "#" -- Add a comment line.
+#
+#   ">" -- Add a blank line.
 
 set_fake_editor () {
 	echo "#!$SHELL_PATH" >fake-editor.sh
@@ -36,6 +43,10 @@ for line in $FAKE_LINES; do
 	case $line in
 	squash|fixup|edit|reword)
 		action="$line";;
+	"#")
+		echo '# comment' >> "$1";;
+	">")
+		echo >> "$1";;
 	*)
 		sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
 		action=pick;;
-- 
1.6.6.140.ga53ad

```

## Michael Haggerty, 2010-01-12 15:38

Subject: [PATCHv2 3/3] rebase-i: Ignore comments and blank lines in peek_next_command
Message-ID: <39d924c84c79adc0dc0df9933ccf6f19dfa6937c.1263310175.git.mhagger@alum.mit.edu>
URL: https://gitlist.dev/e/39d924c84c79adc0dc0df9933ccf6f19dfa6937c.1263310175.git.mhagger%40alum.mit.edu
In-Reply-To: <7vr5pw3pwp.fsf@alter.siamese.dyndns.org>

```
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>
---
 git-rebase--interactive.sh    |    2 +-
 t/t3404-rebase-interactive.sh |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 27479db..2e56e64 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -340,7 +340,7 @@ make_squash_message () {
 }
 
 peek_next_command () {
-	sed -n "1s/ .*$//p" < "$TODO"
+	sed -n -e "/^#/d" -e "/^$/d" -e "s/ .*//p" -e "q" < "$TODO"
 }
 
 do_next () {
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ea26115..d9382e4 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -265,6 +265,30 @@ test_expect_success 'squash and fixup generate correct log messages' '
 	git branch -D squash-fixup
 '
 
+test_expect_success 'squash ignores comments' '
+	git checkout -b skip-comments E &&
+	base=$(git rev-parse HEAD~4) &&
+	FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
+		EXPECT_HEADER_COUNT=4 \
+		git rebase -i $base &&
+	test $base = $(git rev-parse HEAD^) &&
+	test 1 = $(git show | grep ONCE | wc -l) &&
+	git checkout to-be-rebased &&
+	git branch -D skip-comments
+'
+
+test_expect_success 'squash ignores blank lines' '
+	git checkout -b skip-blank-lines E &&
+	base=$(git rev-parse HEAD~4) &&
+	FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
+		EXPECT_HEADER_COUNT=4 \
+		git rebase -i $base &&
+	test $base = $(git rev-parse HEAD^) &&
+	test 1 = $(git show | grep ONCE | wc -l) &&
+	git checkout to-be-rebased &&
+	git branch -D skip-blank-lines
+'
+
 test_expect_success 'squash works as expected' '
 	for n in one two three four
 	do
-- 
1.6.6.140.ga53ad

```

## Johannes Schindelin, 2010-01-12 16:37

Subject: Re: [PATCHv2 0/3] rebase-i: Ignore comments and blank lines among squash/fixup commands
Message-ID: <alpine.DEB.1.00.1001121737310.4985@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1001121737310.4985%40pacific.mpi-cbg.de
In-Reply-To: <cover.1263310175.git.mhagger@alum.mit.edu>

```
Hi,

On Tue, 12 Jan 2010, Michael Haggerty wrote:

> Here is v2 of the patch (now patch series) for making "rebase -i" ignore 
> comments and blank lines while it is processing blocks of squash/fixup 
> commands.

Me likee.

Thanks,
Dscho

```

## Junio C Hamano, 2010-01-13 06:55

Subject: Re: [PATCHv2 1/3] lib-rebase: Provide clearer debugging info about what the editor did
Message-ID: <7vd41etrwp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd41etrwp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <a6ef19853c00263c2875026cb438ce46d3fcf950.1263310175.git.mhagger@alum.mit.edu>

```
Very nice; thanks.

```
