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

[PATCH v2] convert: clarify line ending conversion warning

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Apr 5, 2022, 05:35 UTC
Message-ID
<20220405053559.1072115-1-alexhenrie24@gmail.com>

The warning about converting line endings is extremely confusing. Its two sentences each use the word "will" without specifying a timeframe, which makes it sound like both sentences are referring to the same timeframe. On top of that, it uses the term "original line endings" without saying whether "original" means LF or CRLF.

Rephrase the warning to be clear about when the line endings will be changed and what they will be changed to.

On a platform whose native line endings are not CRLF (e.g. Linux), the "git add" step in the following sequence triggers the warning in question:

$ git config core.autocrlf true $ echo 'Hello world!' >hello.txt $ git add hello.txt warning: LF will be replaced by CRLF in hello.txt The file will have its original line endings in your working directory

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
v2:
- Quote the confusing warning in the above commit message
- Move the file name to the beginning of the warning message
- Put the file name in single quotes
- Use the arguably broader verb "touch" instead of "check out"
- Remove the period at the end of the sentence
- Remove the second sentence entirely
---
 convert.c            | 10 ++++------
 t/t0027-auto-crlf.sh |  8 ++++----
 2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/convert.c b/convert.c
index 8e39731efb..733e581cb9 100644
--- a/convert.c
+++ b/convert.c
@@ -195,9 +195,8 @@ static void check_global_conv_flags_eol(const char *path,
 		if (conv_flags & CONV_EOL_RNDTRP_DIE)
 			die(_("CRLF would be replaced by LF in %s"), path);
 		else if (conv_flags & CONV_EOL_RNDTRP_WARN)
-			warning(_("CRLF will be replaced by LF in %s.\n"
-				  "The file will have its original line"
-				  " endings in your working directory"), path);
+			warning(_("In '%s', CRLF will be replaced by LF the"
+				  " next time Git touches it"), path);
 	} else if (old_stats->lonelf && !new_stats->lonelf ) {
 		/*
 		 * CRLFs would be added by checkout
@@ -205,9 +204,8 @@ static void check_global_conv_flags_eol(const char *path,
 		if (conv_flags & CONV_EOL_RNDTRP_DIE)
 			die(_("LF would be replaced by CRLF in %s"), path);
 		else if (conv_flags & CONV_EOL_RNDTRP_WARN)
-			warning(_("LF will be replaced by CRLF in %s.\n"
-				  "The file will have its original line"
-				  " endings in your working directory"), path);
+			warning(_("In '%s', LF will be replaced by CRLF the"
+				  " next time Git touches it"), path);
 	}
 }
 
diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
index 0feb41a23f..7f80f46393 100755
--- a/t/t0027-auto-crlf.sh
+++ b/t/t0027-auto-crlf.sh
@@ -77,12 +77,12 @@ create_NNO_MIX_files () {
 
 check_warning () {
 	case "$1" in
-	LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;;
-	CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;;
-	'')	                                                 >"$2".expect ;;
+	LF_CRLF) echo "LF will be replaced by CRLF" >"$2".expect ;;
+	CRLF_LF) echo "CRLF will be replaced by LF" >"$2".expect ;;
+	'')	                                    >"$2".expect ;;
 	*) echo >&2 "Illegal 1": "$1" ; return false ;;
 	esac
-	grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" | uniq  >"$2".actual
+	sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq  >"$2".actual
 	test_cmp "$2".expect "$2".actual
 }
 
-- 
2.35.1
Next: Ævar Arnfjörð Bjarmason
Message 1 of 10 in “convert: clarify line ending conversion warning”
  1. convert: clarify line ending conversion warningAlex Henrie, Apr 5, 2022
  2. Ævar Arnfjörð BjarmasonApr 5, 2022
  3. Alex HenrieApr 5, 2022
  4. Junio C HamanoApr 6, 2022
  5. Torsten BögershausenApr 6, 2022
  6. Tao KlerksApr 6, 2022
  7. Alex HenrieApr 6, 2022
  8. Junio C HamanoApr 6, 2022
  9. Junio C HamanoApr 6, 2022
  10. convert: clarify line ending conversion warningAlex Henrie, Apr 8, 2022

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.