Subject: Re: Behaviour of 'git stash show' when a stash has untracked files

From: Junio C Hamano <[email-masked]>
Date: Wed, 20 Sep 2017 14:33:04 +0900

Kaartic Sivaraam <[email-masked]> writes:

> Some time ago, I stashed a few changes along with untracked files. I
> almost forgot it until recently. Then I wanted to see what I change I
> had in the stash. So I did a 'git stash show <num>'. It worked fine but
> didn't say anything about the untracked files in that stash. That made
> me wonder where the untracked files I added went. I then applied the
> stash to see that they were still there but weren't listed in show.
>
> I understand that they aren't listed because 'git stash show' is
> typically a "diff between the stashed state and its original parent" as
> the documentation says but shouldn't there be at least a message that
> the stash contains untracked files? Those untracked files are "part of
> the stash" and I see no way to get information about their presence
> currently.
>
> So, should this behaviour be changed?

Hmm, crickets tell us that nobody is all that interested in this, it
seems.  I do not think I'd be against a new feature that lets users
ask what untracked paths are in the stash (and even their contents),
but I do think it is a bad idea to change a vanilla "stash show" to
show that information in addition to what is currently shown.

Two things need to be designed carefuly.  One is the UI to _invoke_
the new feature, the other is the output from the new feature.

As to the invocation, an obvious pair of choices are:

 - "git stash show-untracked stash@{0} [ [--] <pathspec>]"?
 - "git stash show --untracked stash@{0} [ [--] <pathspec>]"?

I'd personally vote for the former, if only because the latter makes
the design more complicated.  For one thing, tying the feature to
"show" means the output _must_ be in the form of "diff" output in
order to be consistent with the normal output from the subcommand,
but a whole-file creation diff may not be the best way to show the
entire contents of an untracked file.  Also by adding it as an
option to the existing "show" command, it makes it debatable if the
output should show the contents of untracked files in addition to
the stashed changes of tracked paths, or in place of them.  Because
I suspect that viewing contents of the untracked files and the
changes to tracked paths may serve quite different purposes from the
point of view of expected use cases, I am leaning towards saying
that it is a bad idea to show contents of untracked paths in
addition to changes to tracked paths.  There probably are other
reasons why we should prefer the former, i.e. a separate subcommand
to "git stash", independent of the existing "git stash show".

Assuming that we choose to go with a separate command, the output
format from the command does not have to be in the form of patch, so
perhaps "git stash show-untracked --list" may be a way to list the
paths (and we may want -z to show the list NUL-terminated like
"ls-files" does)?  There may be other operations to help those who
want a way to learn about untracked paths in a stash.  But this is
not exactly my itch so I'll let people who do have the itch to work
on designing the details out.