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

git status reports file modified when only line-endings have changed (was git diff --quiet exits with 1 on clean tree with CRLF conversions)

From
Mike Crowe <mac@mcrowe.com>
Date
Mar 2, 2017, 15:38 UTC
Message-ID
<20170302153817.GC7821@mcrowe.com>
In-Reply-To
<d98aa589-3e08-249d-0c88-72dbcee1a568@web.de>
On Tuesday 28 February 2017 at 19:06:44 +0100, Torsten Bögershausen wrote:
> My understanding is that git diff --quiet should be quiet, when
> git add will not do anything (but the file is "touched".
> The touched means that Git will detect e.g a new mtime or inode
> or file size when doing lstat().
Does the same apply to "git status"?

If so, then whilst investigating the "git diff --quiet" problems in this thread I've found a similar bug with "git status". It reports the file has modifications even if only the line-endings have changed, and issuing "git add" causes the perceived modification to disappear.

It can be very confusing for users if "git status" reports a modification but for "git diff" to claim that the files are identical.

This bug is still reproducible even with the fix from https://public-inbox.org/git/xmqqshmyhtnu.fsf@gitster.mtv.corp.google.com/T/#m67cbfad1f2efe721f0c2afac2a1523b743bb57ca

Here's the test case. Test 3 is the part that currently fails:
commit de5f3f1d9161cdd46342689abe38a046fc71850e
Author: Mike Crowe <mac@mcrowe.com>
Date:   Sat Feb 25 09:28:37 2017 +0000
    status: Add tests for status output when file line endings change
diff --git a/t/t7518-status-eol-change.sh b/t/t7518-status-eol-change.sh
new file mode 100755
index 0000000..e18186f
--- /dev/null
+++ b/t/t7518-status-eol-change.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Copyright (c) 2017 Mike Crowe
+#
+
+test_description='git status with files that require CRLF conversion'
+
+. ./test-lib.sh
+
+cat >expected_no_change <<EOF
+On branch master
+nothing to commit, working tree clean
+EOF
+
+test_expect_success setup '
+	echo "* text=auto" > .gitattributes &&
+	printf "Hello\r\nWorld\r\n" > crlf.txt &&
+	printf "expected_no_change\nactual\n" > .gitignore &&
+	git add .gitignore .gitattributes crlf.txt &&
+	git commit -m "initial"
+'
+test_expect_success 'git status reports no change if file regenerated' '
+	printf "Hello\r\nWorld\r\n" > crlf.txt &&
+	git status >actual &&
+	test_cmp expected_no_change actual
+'
+test_expect_success 'git status reports no change if line endings change' '
+	printf "Hello\nWorld\n" > crlf.txt &&
+	git status >actual &&
+	test_cmp expected_no_change actual
+'
+test_expect_success 'git status reports no change if line ending change is staged' '
+	git add crlf.txt &&
+	git status >actual &&
+	test_cmp expected_no_change actual
+'
+test_done
Previous: Mike Crowe
Message 29 of 29 in “git diff --quiet exits with 1 on clean tree with CRLF conversions”
  1. Mike CroweFeb 17, 2017
  2. Junio C HamanoFeb 17, 2017
  3. Mike CroweFeb 17, 2017
  4. Mike CroweFeb 20, 2017
  5. Junio C HamanoFeb 20, 2017
  6. Mike CroweFeb 25, 2017
  7. Junio C HamanoFeb 27, 2017
  8. Torsten BögershausenFeb 28, 2017
  9. Junio C HamanoFeb 28, 2017
  10. 1/1 git diff --quiet exits with 1 on clean tree with CRLF conversionstboegi@web.de, Mar 1, 2017
  11. Junio C HamanoMar 1, 2017
  12. Junio C HamanoMar 1, 2017
  13. Jeff KingMar 2, 2017
  14. Junio C HamanoMar 2, 2017
  15. Jeff KingMar 2, 2017
  16. diff: do not short-cut CHECK_SIZE_ONLY check in diff_populate_filespec()Junio C Hamano, Mar 2, 2017
  17. Mike CroweMar 2, 2017
  18. Junio C HamanoMar 2, 2017
  19. Mike CroweMar 2, 2017
  20. Torsten BögershausenMar 3, 2017
  21. Junio C HamanoMar 3, 2017
  22. Torsten BögershausenMar 4, 2017
  23. Junio C HamanoMar 4, 2017
  24. Torsten BögershausenMar 2, 2017
  25. Mike CroweMar 1, 2017
  26. Junio C HamanoMar 1, 2017
  27. Torsten BögershausenMar 2, 2017
  28. Mike CroweMar 3, 2017
  29. git status reports file modified when only line-endings have changed (was git diff --quiet exits with 1 on clean tree with CRLF conversions)Mike Crowe, Mar 2, 2017

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.