Skip to content

Commit 39743cf

Browse files
committed
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1db25aa commit 39743cf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

git-rebase--interactive.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ amend="$state_dir"/amend
7777
rewritten_list="$state_dir"/rewritten-list
7878
rewritten_pending="$state_dir"/rewritten-pending
7979

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+
8084
strategy_args=
8185
if test -n "$do_merge"
8286
then
@@ -518,6 +522,10 @@ do_next () {
518522
"$comment_char"*|''|noop|drop|d)
519523
mark_action_done
520524
;;
525+
"$cr")
526+
# Work around CR left by "read" (e.g. with Git for Windows' Bash).
527+
mark_action_done
528+
;;
521529
pick|p)
522530
comment_for_reflog pick
523531

@@ -888,6 +896,10 @@ check_bad_cmd_and_sha () {
888896
"$comment_char"*|''|noop|x|exec)
889897
# Doesn't expect a SHA-1
890898
;;
899+
"$cr")
900+
# Work around CR left by "read" (e.g. with Git for
901+
# Windows' Bash).
902+
;;
891903
pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
892904
if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1"
893905
then

t/t3404-rebase-interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ test_expect_success 'static check of bad SHA-1' '
12401240
test E = $(git cat-file commit HEAD | sed -ne \$p)
12411241
'
12421242

1243-
test_expect_failure 'editor saves as CR/LF' '
1243+
test_expect_success 'editor saves as CR/LF' '
12441244
git checkout -b with-crlf &&
12451245
write_script add-crs.sh <<-\EOF &&
12461246
sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&

0 commit comments

Comments
 (0)