From 31bff64100d0864741b57cc44e01a19359573e99 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 1 Oct 2015 10:18:41 +0200 Subject: [PATCH 1/2] rebase-i: explicitly accept tab as separator in commands The git-rebase-todo is parsed several times with different parsers. In principle, the user input is normalized by transform_todo_ids and further parsing can be stricter. In case the user wrote pick deadbeefcommit message the parser of transform_todo_ids was considering the sha1 to be "deadbeefcommit", and was leaving the tab in the transformed sheet. In practice, this went unnoticed since the actual command interpretation was done later in do_next which did accept the tab as a separator. Make it explicit in the code of transform_todo_ids that tabs are accepted. This way, code that mimicks it will also accept tabs as separator. A similar construct appears in skip_unnecessary_picks, but this one comes after transform_todo_ids, hence reads the normalized format, so it needs not be changed. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index dcc3401b5a..51e0e58c67 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -732,8 +732,8 @@ transform_todo_ids () { # that do not have a SHA-1 at the beginning of $rest. ;; *) - sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) && - rest="$sha1 ${rest#* }" + sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) && + rest="$sha1 ${rest#*[ ]}" ;; esac printf '%s\n' "$command${rest:+ }$rest" From 1db168ee971a6a61ce72480e1db9ddfd3629bfcf Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 1 Oct 2015 10:18:42 +0200 Subject: [PATCH 2/2] rebase-i: loosen over-eager check_bad_cmd check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 804098bb (git rebase -i: add static check for commands and SHA-1, 2015-06-29) tried to check all insns before running any in the todo list, but it did so by implementing its own parser that is a lot stricter than necessary. We used to allow lines that are indented (including comment lines), and we used to allow a whitespace between the insn and the commit object name to be HT, among other things, that are flagged as an invalid line by mistake. Fix this by using the same tokenizer that is used to parse the todo list file in the new check. 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. Largely based on patch by: Junio C Hamano [jc: updated test with quickfix from Torsten Bögershausen] Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 62 ++++++++++++++++------------------- t/t3404-rebase-interactive.sh | 15 +++++++++ 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 51e0e58c67..c42ba34c6f 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -849,7 +849,8 @@ add_exec_commands () { # Check if the SHA-1 passed as an argument is a # correct one, if not then print $2 in "$todo".badsha # $1: the SHA-1 to test -# $2: the line to display if incorrect SHA-1 +# $2: the line number of the input +# $3: the input filename check_commit_sha () { badsha=0 if test -z $1 @@ -865,9 +866,10 @@ check_commit_sha () { if test $badsha -ne 0 then + line="$(sed -n -e "${2}p" "$3")" warn "Warning: the SHA-1 is missing or isn't" \ "a commit in the following line:" - warn " - $2" + warn " - $line" warn fi @@ -878,37 +880,31 @@ check_commit_sha () { # from the todolist in stdin check_bad_cmd_and_sha () { retval=0 - git stripspace --strip-comments | - ( - while read -r line - do - IFS=' ' - set -- $line - command=$1 - sha1=$2 - - case $command in - ''|noop|x|"exec") - # Doesn't expect a SHA-1 - ;; - pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f) - if ! check_commit_sha $sha1 "$line" - then - retval=1 - fi - ;; - *) - warn "Warning: the command isn't recognized" \ - "in the following line:" - warn " - $line" - warn + lineno=0 + while read -r command rest + do + lineno=$(( $lineno + 1 )) + case $command in + "$comment_char"*|''|noop|x|exec) + # Doesn't expect a SHA-1 + ;; + pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f) + if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1" + then retval=1 - ;; - esac - done - - return $retval - ) + fi + ;; + *) + line="$(sed -n -e "${lineno}p" "$1")" + warn "Warning: the command isn't recognized" \ + "in the following line:" + warn " - $line" + warn + retval=1 + ;; + esac + done <"$1" + return $retval } # Print the list of the SHA-1 of the commits @@ -1002,7 +998,7 @@ check_todo_list () { ;; esac - if ! check_bad_cmd_and_sha <"$todo" + if ! check_bad_cmd_and_sha "$todo" then raise_error=t fi diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index ebdab4b95d..88d7d5358a 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1206,6 +1206,21 @@ test_expect_success 'static check of bad command' ' test C = $(git cat-file commit HEAD^ | sed -ne \$p) ' +test_expect_success 'tabs and spaces are accepted in the todolist' ' + rebase_setup_and_clean indented-comment && + write_script add-indent.sh <<-\EOF && + ( + # Turn single spaces into space/tab mix + sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1" + printf "\n\t# comment\n #more\n\t # comment\n" + ) >$1.new + mv "$1.new" "$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 <