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

Re: Duplicate safecrlf warning for racily clean index entry

From
Torsten Bögershausen <tboegi@web.de>
Date
Feb 21, 2018, 07:53 UTC
Message-ID
<20180221075323.GA18213@tor.lan>
In-Reply-To
<1519134146.6055.23.camel@mattmccutchen.net>
On Tue, Feb 20, 2018 at 08:42:26AM -0500, Matt McCutchen wrote:
Show 19 quoted lines
> I noticed that if a file subject to a safecrlf warning is added to the
> index in the same second that it is created, resulting in a "racily
> clean" index entry, then a subsequent "git add" command prints another
> safecrlf warning.  I reproduced this on the current "next"
> (499d7c4f91).  The procedure:
> 
> $ git init
> $ git config core.autocrlf true
> $ echo foo >file1 && git add file1 && git add file1
> warning: LF will be replaced by CRLF in file1.
> The file will have its original line endings in your working directory.
> warning: LF will be replaced by CRLF in file1.
> The file will have its original line endings in your working directory.
> $ echo bar >file2 && sleep 1 && git add file2 && git add file2
> warning: LF will be replaced by CRLF in file2.
> The file will have its original line endings in your working directory.
> 
> This came up when I ran the test suite for Braid on Windows
> (https://github.com/cristibalan/braid/issues/77).

I think a .gitattributes file could/should be used. I'll answer there seperatly.

Show 19 quoted lines
> 
> The phenomenon actually seems to be more general: touching the file
> causes the next "git add" to print a safecrlf warning, suggesting that
> the warning occurs whenever the index entry is dirty.  One could argue
> that a new warning is reasonable after touching the file, but it seems
> clear that "racy cleanliness" is an implementation detail that
> shouldn't have user-visible nondeterministic effects.
> 
> In either case, if "git update-index --refresh" (or "git status") is
> run before "git add", then "git add" does not print the warning.  On
> the other hand, if line endings in the working tree file are changed,
> then git shows the file as having an unstaged change, even though the
> content that would be added to the index after CRLF conversion is
> identical.  So it seems that git remembers the pre-conversion file
> content and uses it for "git update-index --refresh" and would just
> need to use it for "git add" as well.
> 
> Thoughts about the proposed change?  Does someone want to work on it or
> give me a pointer to where to get started?
Good analyzes, thanks for that.

I don't hava a pointer, but what should happen ? 2 warnings for 2 "git add" should be OK, I think.

1 warning is part of the optimization, that Git does to handle hundrets and thousands of files efficciently.

Is the 1/2 warning  real live problem  ?
> 
> Thanks,
> Matt
Previous: Matt McCutchenNext: Matt McCutchen
Message 2 of 5 in “Duplicate safecrlf warning for racily clean index entry”
  1. Matt McCutchenFeb 20, 2018
  2. Torsten BögershausenFeb 21, 2018
  3. Matt McCutchenFeb 21, 2018
  4. Matt McCutchenFeb 21, 2018
  5. Junio C HamanoFeb 21, 2018

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.