git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 0/2] Fix interactive rebase when the editor saves with CR/LF

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 28, 2015, 14:54 UTC
Message-ID
<cover.1446043983.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1445939154.git.johannes.schindelin@gmx.de>

Chad Boles reported that `git rebase -i` recently started producing errors when the editor saves files with DOS line endings. The symptom is:

	Warning: the command isn't recognized in the following line:
	 -
	You can fix this with 'git rebase --edit-todo'.
	Or you can abort the rebase with 'git rebase --abort'.

The real bummer is that simply calling `git rebase --continue` "fixes" it.

Turns out that we now check whether a single Carriage Return is a valid command. This new check was introduced recently (1db168ee9, ironically named "rebase-i: loosen over-eager check_bad_cmd check").

The fix provided by Junio works around this issue by testing for an explicit trailing carriage return and handles it like an empty line.

Unfortunately, this is the best we can do for now as there is disagreement about a more general fix.

This iteration clarifies the comments in git-rebase--interactive, updates the commit message to state that this has been tested with Git for Windows, and replaces the description of the proposed fix with a description of the actual work-around provided by Junio.

Johannes Schindelin (1):
  Demonstrate rebase fails when the editor saves with CR/LF
Junio C Hamano (1):
  rebase-i: work around Windows CRLF line endings
 git-rebase--interactive.sh    | 12 ++++++++++++
 t/t3404-rebase-interactive.sh | 12 ++++++++++++
 2 files changed, 24 insertions(+)
Interdiff vs v3:
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index daadf2d..34cfe66 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -77,8 +77,7 @@ amend="$state_dir"/amend
 rewritten_list="$state_dir"/rewritten-list
 rewritten_pending="$state_dir"/rewritten-pending
 
-# Work around a Windows port of shell that does not strip
-# the newline at the end of a line correctly.
+# Work around Git for Windows' Bash that strips only LFs but no CRs.
 cr=$(printf "\015")
 
 strategy_args=
@@ -523,8 +522,8 @@ do_next () {
 		mark_action_done
 		;;
 	"$cr")
-		# Windows port of shell not stripping the newline
-		# at the end of an empty line correctly.
+		# Work around Carriage Returns not being stripped (e.g. with
+		# Git for Windows' Bash).
 		mark_action_done
 		;;
 	pick|p)
@@ -906,8 +905,8 @@ check_bad_cmd_and_sha () {
 			# Doesn't expect a SHA-1
 			;;
 		"$cr")
-			# Windows port of shell not stripping the newline
-			# at the end of an empty line correctly.
+			# Work around Carriage Returns not being stripped
+			# (e.g. with Git for Windows' Bash).
 			;;
 		pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
 			if ! check_commit_sha "${rest%%[ 	]*}" "$lineno" "$1"
-- 
2.1.4
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 26 of 31 in “Fix interactive rebase when the editor saves with CR/LF”
  1. 0/2 Fix interactive rebase when the editor saves with CR/LFJohannes Schindelin, Oct 25, 2015
  2. 1/2 Demonstrate rebase fails when the editor saves with CR/LFJohannes Schindelin, Oct 25, 2015
  3. 2/2 sh-setup: explicitly mark CR as a field separatorJohannes Schindelin, Oct 25, 2015
  4. Philip OakleyOct 25, 2015
  5. Johannes SchindelinOct 25, 2015
  6. 0/2 Fix interactive rebase when the editor saves with CR/LFJohannes Schindelin, Oct 25, 2015
  7. 1/2 Demonstrate rebase fails when the editor saves with CR/LFJohannes Schindelin, Oct 25, 2015
  8. 2/2 sh-setup: explicitly mark CR as a field separatorJohannes Schindelin, Oct 25, 2015
  9. Matthieu MoyOct 26, 2015
  10. Junio C HamanoOct 26, 2015
  11. Junio C HamanoOct 26, 2015
  12. Johannes SchindelinOct 27, 2015
  13. Johannes SchindelinOct 27, 2015
  14. Junio C HamanoOct 27, 2015
  15. Matthieu MoyOct 27, 2015
  16. Junio C HamanoOct 25, 2015
  17. Johannes SchindelinOct 26, 2015
  18. Junio C HamanoOct 26, 2015
  19. Johannes SchindelinOct 27, 2015
  20. 0/2 Fix interactive rebase when the editor saves with CR/LFJohannes Schindelin, Oct 27, 2015
  21. 1/2 Demonstrate rebase fails when the editor saves with CR/LFJohannes Schindelin, Oct 27, 2015
  22. 2/2 rebase-i: work around Windows CRLF line endingsJohannes Schindelin, Oct 27, 2015
  23. Johannes SchindelinOct 27, 2015
  24. Junio C HamanoOct 27, 2015
  25. Johannes SchindelinOct 28, 2015
  26. 0/2 Fix interactive rebase when the editor saves with CR/LFJohannes Schindelin, Oct 28, 2015
  27. 1/2 Demonstrate rebase fails when the editor saves with CR/LFJohannes Schindelin, Oct 28, 2015
  28. 2/2 rebase-i: work around Windows CRLF line endingsJohannes Schindelin, Oct 28, 2015
  29. Junio C HamanoOct 28, 2015
  30. Johannes SchindelinOct 25, 2015
  31. shell scripting woes, was Re: [PATCH 2/2] sh-setup: explicitly mark CR as a field separatorJohannes Schindelin, Oct 25, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.