Skip to content

Commit 19d11d4

Browse files
committed
Merge branch 'gr/rebase-i-drop-warn' into maint
"git rebase -i" had a minor regression recently, which stopped considering a line that begins with an indented '#' in its insn sheet not a comment, which is now fixed. * gr/rebase-i-drop-warn: rebase-i: loosen over-eager check_bad_cmd check rebase-i: explicitly accept tab as separator in commands
2 parents d5fea24 + 1db168e commit 19d11d4

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

git-rebase--interactive.sh

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ transform_todo_ids () {
729729
# that do not have a SHA-1 at the beginning of $rest.
730730
;;
731731
*)
732-
sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) &&
733-
rest="$sha1 ${rest#* }"
732+
sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) &&
733+
rest="$sha1 ${rest#*[ ]}"
734734
;;
735735
esac
736736
printf '%s\n' "$command${rest:+ }$rest"
@@ -857,7 +857,8 @@ add_exec_commands () {
857857
# Check if the SHA-1 passed as an argument is a
858858
# correct one, if not then print $2 in "$todo".badsha
859859
# $1: the SHA-1 to test
860-
# $2: the line to display if incorrect SHA-1
860+
# $2: the line number of the input
861+
# $3: the input filename
861862
check_commit_sha () {
862863
badsha=0
863864
if test -z $1
@@ -873,9 +874,10 @@ check_commit_sha () {
873874

874875
if test $badsha -ne 0
875876
then
877+
line="$(sed -n -e "${2}p" "$3")"
876878
warn "Warning: the SHA-1 is missing or isn't" \
877879
"a commit in the following line:"
878-
warn " - $2"
880+
warn " - $line"
879881
warn
880882
fi
881883

@@ -886,37 +888,31 @@ check_commit_sha () {
886888
# from the todolist in stdin
887889
check_bad_cmd_and_sha () {
888890
retval=0
889-
git stripspace --strip-comments |
890-
(
891-
while read -r line
892-
do
893-
IFS=' '
894-
set -- $line
895-
command=$1
896-
sha1=$2
897-
898-
case $command in
899-
''|noop|x|"exec")
900-
# Doesn't expect a SHA-1
901-
;;
902-
pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
903-
if ! check_commit_sha $sha1 "$line"
904-
then
905-
retval=1
906-
fi
907-
;;
908-
*)
909-
warn "Warning: the command isn't recognized" \
910-
"in the following line:"
911-
warn " - $line"
912-
warn
891+
lineno=0
892+
while read -r command rest
893+
do
894+
lineno=$(( $lineno + 1 ))
895+
case $command in
896+
"$comment_char"*|''|noop|x|exec)
897+
# Doesn't expect a SHA-1
898+
;;
899+
pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
900+
if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1"
901+
then
913902
retval=1
914-
;;
915-
esac
916-
done
917-
918-
return $retval
919-
)
903+
fi
904+
;;
905+
*)
906+
line="$(sed -n -e "${lineno}p" "$1")"
907+
warn "Warning: the command isn't recognized" \
908+
"in the following line:"
909+
warn " - $line"
910+
warn
911+
retval=1
912+
;;
913+
esac
914+
done <"$1"
915+
return $retval
920916
}
921917

922918
# Print the list of the SHA-1 of the commits
@@ -1010,7 +1006,7 @@ check_todo_list () {
10101006
;;
10111007
esac
10121008

1013-
if ! check_bad_cmd_and_sha <"$todo"
1009+
if ! check_bad_cmd_and_sha "$todo"
10141010
then
10151011
raise_error=t
10161012
fi

t/t3404-rebase-interactive.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,21 @@ test_expect_success 'static check of bad command' '
12271227
test C = $(git cat-file commit HEAD^ | sed -ne \$p)
12281228
'
12291229

1230+
test_expect_success 'tabs and spaces are accepted in the todolist' '
1231+
rebase_setup_and_clean indented-comment &&
1232+
write_script add-indent.sh <<-\EOF &&
1233+
(
1234+
# Turn single spaces into space/tab mix
1235+
sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1236+
printf "\n\t# comment\n #more\n\t # comment\n"
1237+
) >$1.new
1238+
mv "$1.new" "$1"
1239+
EOF
1240+
test_set_editor "$(pwd)/add-indent.sh" &&
1241+
git rebase -i HEAD^^^ &&
1242+
test E = $(git cat-file commit HEAD | sed -ne \$p)
1243+
'
1244+
12301245
cat >expect <<EOF
12311246
Warning: the SHA-1 is missing or isn't a commit in the following line:
12321247
- edit XXXXXXX False commit

0 commit comments

Comments
 (0)