Thread (1 message) 1 message, 1 author, 2025-12-03

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

From: Junio C Hamano <hidden>
Date: 2025-12-03 22:06:12

"Kristoffer Haugsbakk" [off-list ref] writes:
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.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help