git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Misleading documentation for git-diff-files (diff-filter)
@ 2018-01-03 16:07 John Cheng
  2018-01-03 23:53 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: John Cheng @ 2018-01-03 16:07 UTC (permalink / raw)
  To: git

I originally asked this question on stackoverflow
(https://stackoverflow.com/q/48039277).

I wanted to know if git diff-files shows files that are not in the
index but are in the working tree. The documentation says you can
supply --diff-filter=A, which will select file "that are added".
However, git-diff-files (appears) to never show any files with the
status of "A".

It seems like the cause is that git diff-files includes
diff-options.txt which uses a standard template for --diff-filter
which includes the "A" option. Perhaps a clarification can be added?

Compares the files in the working tree and the index.  When paths
are specified, compares only those named paths.  Otherwise all
entries in the index are compared.  The output format is the
same as for 'git diff-index' and 'git diff-tree'. Files not in the index are
not compared.





-- 
---
John L Cheng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Misleading documentation for git-diff-files (diff-filter)
  2018-01-03 16:07 Misleading documentation for git-diff-files (diff-filter) John Cheng
@ 2018-01-03 23:53 ` Junio C Hamano
  2018-01-04 15:53   ` John Cheng
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2018-01-03 23:53 UTC (permalink / raw)
  To: John Cheng; +Cc: git

John Cheng <johnlicheng@gmail.com> writes:

> I wanted to know if git diff-files shows files that are not in the
> index but are in the working tree.

At least in the original design of Git, that would fundamentally be
impossible, as Git _only_ cares about paths that are in the index,
so a new file won't be in the picture until it is added.  Because a
change is shown as "A"dded by the diff family of commands only when
the old side lacks a path that appears in the new side, there is no
way "diff-files" that compares the index and the working tree would
see a path that is missing from the old (i.e. the index) side.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Misleading documentation for git-diff-files (diff-filter)
  2018-01-03 23:53 ` Junio C Hamano
@ 2018-01-04 15:53   ` John Cheng
  2018-01-04 16:49     ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: John Cheng @ 2018-01-04 15:53 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

To be clear, I don't mean to imply that diff-files should include
files that are not the index. I was trying to say that as a user, the
documentation gave me a different impression.

For background, my intent was to have a script to look for local git
repos that with unstaged changes. After some trial and error, I found
that git-ls-files gave me what I needed. However, I wanted to point
out why I initially believed git-diff-files with show "added files".
Think of this more as user feedback.

On Wed, Jan 3, 2018 at 3:53 PM, Junio C Hamano <gitster@pobox.com> wrote:
> John Cheng <johnlicheng@gmail.com> writes:
>
>> I wanted to know if git diff-files shows files that are not in the
>> index but are in the working tree.
>
> At least in the original design of Git, that would fundamentally be
> impossible, as Git _only_ cares about paths that are in the index,
> so a new file won't be in the picture until it is added.  Because a
> change is shown as "A"dded by the diff family of commands only when
> the old side lacks a path that appears in the new side, there is no
> way "diff-files" that compares the index and the working tree would
> see a path that is missing from the old (i.e. the index) side.



-- 
---
John L Cheng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Misleading documentation for git-diff-files (diff-filter)
  2018-01-04 15:53   ` John Cheng
@ 2018-01-04 16:49     ` Jeff King
  2018-01-04 19:09       ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2018-01-04 16:49 UTC (permalink / raw)
  To: John Cheng; +Cc: Junio C Hamano, git

On Thu, Jan 04, 2018 at 07:53:53AM -0800, John Cheng wrote:

> To be clear, I don't mean to imply that diff-files should include
> files that are not the index. I was trying to say that as a user, the
> documentation gave me a different impression.
> 
> For background, my intent was to have a script to look for local git
> repos that with unstaged changes. After some trial and error, I found
> that git-ls-files gave me what I needed. However, I wanted to point
> out why I initially believed git-diff-files with show "added files".

I took your original mail to be a suggestion that the documentation
could be more clear. :)

So maybe something like the patch below?

It actually would be an interesting feature for a diff from the index to
the working tree to include untracked files as new entries. I don't
think we'd want to do that by default (since the actions a user needs to
take are quite different between a modified file, one marked
intent-to-add, and an untracked one). But I could see it being useful
for a caller to want to consider the whole tree as a single diff.

-- >8 --
Subject: [PATCH] docs/diff-options: clarify scope of diff-filter types

The same document for "--diff-filter" is included by many
programs in the diff family. Because it mentions all
possible types (added, removed, etc), this may imply to the
reader that all types can be generated by a particular
command. But this isn't necessarily the case; "diff-files"
cannot generally produce an "Added" entry, since the diff is
limited to what is already in the index.

Let's make it clear that the list here is the full one, and
does not imply anything about what a particular invocation
may produce.

Note that conditionally including items (e.g., omitting
"Added" in the git-diff-files manpage) isn't the right
solution here for two reasons:

  - The problem isn't diff-files, but doing an index to
    working tree diff. "git diff" can do the same diff, but
    also has other modes where "Added" does show up.

  - The direction of the diff matters. Doing "diff-files -R"
    can get you Added entries (but not Deleted ones).

So it's best just to explain that the set of available types
depends on the specific diff invocation.

Reported-by: John Cheng <johnlicheng@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/diff-options.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 9d1586b956..743af97b06 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -469,6 +469,12 @@ ifndef::git-format-patch[]
 +
 Also, these upper-case letters can be downcased to exclude.  E.g.
 `--diff-filter=ad` excludes added and deleted paths.
++
+Note that not all diffs can feature all types. For instance, diffs
+from the index to the working tree can never have Added entries
+(because the set of paths included in the diff is limited by what is in
+the index).  Similarly, copied and renamed entries cannot appear if
+detection for those types is disabled.
 
 -S<string>::
 	Look for differences that change the number of occurrences of
-- 
2.16.0.rc0.391.gbd38408415


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Misleading documentation for git-diff-files (diff-filter)
  2018-01-04 16:49     ` Jeff King
@ 2018-01-04 19:09       ` Junio C Hamano
  2018-01-04 19:11         ` John Cheng
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2018-01-04 19:09 UTC (permalink / raw)
  To: Jeff King; +Cc: John Cheng, git

Jeff King <peff@peff.net> writes:

> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
> index 9d1586b956..743af97b06 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -469,6 +469,12 @@ ifndef::git-format-patch[]
>  +
>  Also, these upper-case letters can be downcased to exclude.  E.g.
>  `--diff-filter=ad` excludes added and deleted paths.
> ++
> +Note that not all diffs can feature all types. For instance, diffs
> +from the index to the working tree can never have Added entries
> +(because the set of paths included in the diff is limited by what is in
> +the index).  Similarly, copied and renamed entries cannot appear if
> +detection for those types is disabled.

Makes sense; thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Misleading documentation for git-diff-files (diff-filter)
  2018-01-04 19:09       ` Junio C Hamano
@ 2018-01-04 19:11         ` John Cheng
  0 siblings, 0 replies; 6+ messages in thread
From: John Cheng @ 2018-01-04 19:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, git

Thanks for the clarification! I also didn't realize that diff-files -R
will show added files. You learn something new everyday ;)

On Thu, Jan 4, 2018 at 11:09 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jeff King <peff@peff.net> writes:
>
>> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
>> index 9d1586b956..743af97b06 100644
>> --- a/Documentation/diff-options.txt
>> +++ b/Documentation/diff-options.txt
>> @@ -469,6 +469,12 @@ ifndef::git-format-patch[]
>>  +
>>  Also, these upper-case letters can be downcased to exclude.  E.g.
>>  `--diff-filter=ad` excludes added and deleted paths.
>> ++
>> +Note that not all diffs can feature all types. For instance, diffs
>> +from the index to the working tree can never have Added entries
>> +(because the set of paths included in the diff is limited by what is in
>> +the index).  Similarly, copied and renamed entries cannot appear if
>> +detection for those types is disabled.
>
> Makes sense; thanks.



-- 
---
John L Cheng

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-04 19:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-03 16:07 Misleading documentation for git-diff-files (diff-filter) John Cheng
2018-01-03 23:53 ` Junio C Hamano
2018-01-04 15:53   ` John Cheng
2018-01-04 16:49     ` Jeff King
2018-01-04 19:09       ` Junio C Hamano
2018-01-04 19:11         ` John Cheng

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).