threads / discuss / 64575

diff: should warn about EOL when --no-index ?

Subject: diff: should warn about EOL when --no-index ?

## tl;dr

4 messages between Dec 3, 2025 and Dec 4, 2025.

replies: 3people: 3as markdown or json

Kristoffer Haugsbakk· Dec 3, 2025, 16:26 UTC · lore

When using `git diff --no-index` on some CRLF files with my setup and config:

    warning: in the working copy of '<something>.csv', CRLF will be replaced by LF the next time Git touches it

To my mind, I’m saying that I don’t care about the working tree per se. In particular, in this case, I’m just using git-diff(1) as a difference utility on some non-Git files (this happens to be outside a Git repository).

-- 
Kristoffer Haugsbakk
Torsten Bögershausen· Dec 3, 2025, 19:54 UTC · re: Kristoffer Haugsbakk · lore

Re: diff: should warn about EOL when --no-index ?

On Wed, Dec 03, 2025 at 05:26:49PM +0100, Kristoffer Haugsbakk wrote:
Show 13 quoted lines
> When using `git diff --no-index` on some CRLF files with my setup 
> and config:
> 
>     warning: in the working copy of '<something>.csv', CRLF will be replaced by LF the next time Git touches it
> 
> To my mind, I’m saying that I don’t care about the working tree per
> se. In particular, in this case, I’m just using git-diff(1) as a
> difference utility on some non-Git files (this happens to be outside a
> Git repository).
> 
> -- 
> Kristoffer Haugsbakk
> 

Not being an expert in `git diff --no-index`: It seems as if Git reads the .gitconfig and possible .gitattributes here ? Or what exact setup do yoe use, what is the value for core.autocrlf and do you have a .gitattributes file ? Thinking about it: The warning may be not needed. On the other hand: It seems as if something in your repo is not as it should be ? Because the repo should be normalized ? And if it was, there would be no warning ?

What does git ls-files --eol give you ?

More information is welcome
Kristoffer Haugsbakk· Dec 4, 2025, 08:24 UTC · re: Torsten Bögershausen · lore

Re: diff: should warn about EOL when --no-index ?

On Wed, Dec 3, 2025, at 20:54, Torsten Bögershausen wrote:
Show 6 quoted lines
> On Wed, Dec 03, 2025 at 05:26:49PM +0100, Kristoffer Haugsbakk wrote:
>>[[snip]
>> 
>
> Not being an expert in `git diff --no-index`:
> It seems as if Git reads the .gitconfig and possible .gitattributes here ?

Yes it has to do with my config or defaults. That doesn’t matter to the question.

Show 6 quoted lines
> Or what exact setup do yoe use, what is the value for
> core.autocrlf
> and do you have a .gitattributes file ?
> Thinking about it: The warning may be not needed.
> On the other hand: It seems as if something in your repo is
> not as it should be ?
It’s outside a Git repo.
Show 8 quoted lines
> Because the repo should be normalized ?
> And if it was, there would be no warning ?
>
> What does
> git ls-files --eol
> give you ?
>
> More information is welcome

The warning could be about normalizing the other way for that matter. I’m asking whether the warning should be there in this case.

I certainly don’t want to subject people to iteratively guess what my config is like.

Junio C Hamano· Dec 3, 2025, 22:06 UTC · re: Kristoffer Haugsbakk · lore

Re: diff: should warn about EOL when --no-index ?

"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:
Show 9 quoted lines
> When using `git diff --no-index` on some CRLF files with my setup 
> and config:
>
>     warning: in the working copy of '<something>.csv', CRLF will be replaced by LF the next time Git touches it
>
> To my mind, I’m saying that I don’t care about the working tree per
> se. In particular, in this case, I’m just using git-diff(1) as a
> difference utility on some non-Git files (this happens to be outside a
> Git repository).

"git diff --no-index" is "we cannot bother to add our diff goodness to other people's diff (like GNU) and instead we tweak our diff machinery to work sufficiently well without repository", aka "better alternative to GNU diff". So you are correct to notice that it is wrong to give the specific error/warning message that is only applicable when the thing were found in a Git controlled working tree.

But at the same time, the "better alternative" part comes from the fact that our diff machinery can be tweaked with configuration variables and attributes (mostly coloring, but diff algos and even textconv filters may be good things that may want to be usable outside a repository), so it would unfortunately not be a solution to stop reading these Git controlled files.

The warning seems to come from check_global_conv_flags_eol() that is called by crlf_to_git() and environment.c defines global_conv_flags_eol to ensure everybody calling convert_to_git() will get the warning when their contents would not round-trip cleanly across CRLF-to-LF and then back with LF-to-CRLF. Perhaps we should disable it in "diff --no-index" but the right way to do so is unclear. E.g., if we want the same for "git grep --no-index", it may be that "disable the warning because 'diff --index' is calling us" is way too narrow and "disable the warning because we are running outside a repository" may be a better alternative. But do we want or not want the same warning when we run "git diff --no-index" inside a Git controlled working tree? I am not sure.

← back to recent threads