git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: gitster@pobox.com
Cc: git@vger.kernel.org,
	"Galan Rémi" <remi.galan-alfonso@ensimag.grenoble-inp.fr>,
	"Matthieu Moy" <Matthieu.Moy@imag.fr>
Subject: [PATCH] rebase: accept indented comments (fixes regression)
Date: Wed, 30 Sep 2015 10:11:01 +0200	[thread overview]
Message-ID: <1443600661-19391-1-git-send-email-Matthieu.Moy@imag.fr> (raw)

With Git <2.0.6, 'git rebase' used to accept lines starting with
whitespaces followed with '#' as a comment. This was broken by
804098b (git rebase -i: add static check for commands and SHA-1,
2015-06-29), which introduced additional checks on the TODO-list using
"git stripspaces" which only strips comments starting at the first
column.

Whether it's a good thing to accept indented comments is
debatable (other commands like "git commit" do not accept them), but we
already accepted them in the past, and some people and scripts rely on
this behavior. Also, a line starting with space followed by a '#' cannot
have any meaning other than being a comment, hence it doesn't harm to
accept them as comments.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
Junio C Hamano <gitster@pobox.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> I know you alluded to preprocess what is fed to stripspace, but I
>> wonder if we can remove the misguided call to stripspace in the
>> first place and do something like the attached instead.
>>
>>  git-rebase--interactive.sh | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
>> index f01637b..a64f77a 100644
>> --- a/git-rebase--interactive.sh
>> +++ b/git-rebase--interactive.sh
>> @@ -886,7 +886,6 @@ check_commit_sha () {
>>  # from the todolist in stdin
>>  check_bad_cmd_and_sha () {
>>  	retval=0
>> -	git stripspace --strip-comments |
>>  	(
>>  		while read -r line
>>  		do
>> @@ -896,7 +895,7 @@ check_bad_cmd_and_sha () {
>>  			sha1=$2
>>  
>>  			case $command in
>> -			''|noop|x|"exec")
>> +			'#'*|''|noop|x|"exec")
>>  				# Doesn't expect a SHA-1
>>  				;;
>>  			pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
>
> Nah, that would not work, as I misread the "split only at SP" manual
> parsing of $line.

OK, let's go for the solution I seem to be able to get right even with
low cafeine ;-).

 git-rebase--interactive.sh    |  3 +++
 t/t3404-rebase-interactive.sh | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f01637b..55adf78 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -886,6 +886,9 @@ check_commit_sha () {
 # from the todolist in stdin
 check_bad_cmd_and_sha () {
 	retval=0
+	# git rebase -i accepts comments preceeded by spaces, while
+	# stripspace does not.
+	sed 's/^[[:space:]]*//' |
 	git stripspace --strip-comments |
 	(
 		while read -r line
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index d26e3f5..ac5bac3 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1227,6 +1227,16 @@ test_expect_success 'static check of bad command' '
 	test C = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'indented comments are accepted' '
+	rebase_setup_and_clean indented-comment &&
+	write_script add-indent.sh <<-\EOF &&
+	printf "\n \t # comment\n" >>$1
+	EOF
+	test_set_editor "$(pwd)/add-indent.sh" &&
+	git rebase -i HEAD^ &&
+	test E = $(git cat-file commit HEAD | sed -ne \$p)
+'
+
 cat >expect <<EOF
 Warning: the SHA-1 is missing or isn't a commit in the following line:
  - edit XXXXXXX False commit
-- 
2.6.0.rc2.24.g231a9a1.dirty

             reply	other threads:[~2015-09-30  8:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30  8:11 Matthieu Moy [this message]
2015-09-30  9:58 ` [PATCH] rebase: accept indented comments (fixes regression) Remi Galan Alfonso
2015-09-30 18:05 ` Junio C Hamano
2015-09-30 19:17   ` Matthieu Moy
2015-09-30 19:31     ` Junio C Hamano
2015-09-30 19:18   ` Junio C Hamano
2015-09-30 19:50     ` Matthieu Moy
2015-09-30 20:34       ` Junio C Hamano
2015-10-01  8:18         ` [PATCH v3 1/2] rebase-i: explicitly accept tab as separator in commands Matthieu Moy
2015-10-01  8:18           ` [PATCH v3 2/2] rebase-i: loosen over-eager check_bad_cmd check Matthieu Moy
2015-09-30 20:01     ` [PATCH] " Matthieu Moy
2015-09-30 20:04       ` Eric Sunshine
2015-09-30 20:10         ` [PATCH v2] " Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443600661-19391-1-git-send-email-Matthieu.Moy@imag.fr \
    --to=matthieu.moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=remi.galan-alfonso@ensimag.grenoble-inp.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).