git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
Cc: git@vger.kernel.org
Subject: Re: diff: should warn about EOL when --no-index ?
Date: Wed, 03 Dec 2025 14:06:09 -0800	[thread overview]
Message-ID: <xmqq4iq76x0u.fsf@gitster.g> (raw)
In-Reply-To: <03643900-db0b-48b7-93a7-4d96632af57c@app.fastmail.com> (Kristoffer Haugsbakk's message of "Wed, 03 Dec 2025 17:26:49 +0100")

"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> 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.



      parent reply	other threads:[~2025-12-03 22:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03 16:26 diff: should warn about EOL when --no-index ? Kristoffer Haugsbakk
2025-12-03 19:54 ` Torsten Bögershausen
2025-12-04  8:24   ` Kristoffer Haugsbakk
2025-12-03 22:06 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4iq76x0u.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kristofferhaugsbakk@fastmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).