rebase-i: work around Windows CRLF line endings

Editors on Windows can and do save text files with CRLF line endings, which is the convention on the platform. We are seeing reports that the "read" command in a port of bash to the environment however does not strip the CRLF at the end, not adjusting for the same convention on the platform. This breaks the recently added sanity checks for the insn sheet fed to "rebase -i"; instead of an empty line (hence nothing in $command), the script was getting a lone CR in there. Special case a lone CR and treat it the same way as an empty line to work this around. This patch (also) passes the test with Git for Windows, where the issue was seen first. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 28, 2015 at 15:54 UTC 39743cf554caaed462464b55315ab5b37f5ab1b9
2 files changed +13 -1
git-rebase--interactive.sh
+12
@@ -77,6 +77,10 @@ amend="$state_dir"/amend
77 rewritten_list="$state_dir"/rewritten-list
78 rewritten_pending="$state_dir"/rewritten-pending
79
80 +# Work around Git for Windows' Bash whose "read" does not strip CRLF
81 +# and leaves CR at the end instead.
82 +cr=$(printf "\015")
83 +
84 strategy_args=
85 if test -n "$do_merge"
86 then
@@ -518,6 +522,10 @@ do_next () {
522 "$comment_char"*|''|noop|drop|d)
523 mark_action_done
524 ;;
525 + "$cr")
526 + # Work around CR left by "read" (e.g. with Git for Windows' Bash).
527 + mark_action_done
528 + ;;
529 pick|p)
530 comment_for_reflog pick
531
@@ -888,6 +896,10 @@ check_bad_cmd_and_sha () {
896 "$comment_char"*|''|noop|x|exec)
897 # Doesn't expect a SHA-1
898 ;;
899 + "$cr")
900 + # Work around CR left by "read" (e.g. with Git for
901 + # Windows' Bash).
902 + ;;
903 pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
904 if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1"
905 then
t/t3404-rebase-interactive.sh
+1 -1
@@ -1240,7 +1240,7 @@ test_expect_success 'static check of bad SHA-1' '
1240 test E = $(git cat-file commit HEAD | sed -ne \$p)
1241 '
1242
1243 -test_expect_failure 'editor saves as CR/LF' '
1243 +test_expect_success 'editor saves as CR/LF' '
1244 git checkout -b with-crlf &&
1245 write_script add-crs.sh <<-\EOF &&
1246 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&