# Feature Request: Show status of the stash in git status command

13 messages from 2017-06-07 to 2017-06-13. Participants: Houston Fortney, Jeff King, Samuel Lijin, liam Beguin, Randall S. Becker, Igor Djordjevic, Junio C Hamano, Konstantin Khomoutov.
Thread: https://gitlist.dev/t/46138

## Houston Fortney, 2017-06-07 22:46

Subject: Feature Request: Show status of the stash in git status command
Message-ID: <CA+B9myHRahTd+FDgzK5AhXW+hq_Y_czMX9X6MXYBcr9WSPeiDw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BB9myHRahTd%2BFDgzK5AhXW%2Bhq_Y_czMX9X6MXYBcr9WSPeiDw%40mail.gmail.com

```
I sometimes forget about something that I stashed. It would be nice if
the git status command would just say "There are x entries in the
stash." It can say nothing if there is nothing stashed so it is
usually not adding clutter.

```

## Jeff King, 2017-06-10 08:25

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <20170610082534.6437ifexzly4oqg6@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170610082534.6437ifexzly4oqg6%40sigill.intra.peff.net
In-Reply-To: <CA+B9myHRahTd+FDgzK5AhXW+hq_Y_czMX9X6MXYBcr9WSPeiDw@mail.gmail.com>

```
On Wed, Jun 07, 2017 at 06:46:18PM -0400, Houston Fortney wrote:

> I sometimes forget about something that I stashed. It would be nice if
> the git status command would just say "There are x entries in the
> stash." It can say nothing if there is nothing stashed so it is
> usually not adding clutter.

I think the clutter issue would depend on your workflow around stash.

Some people carry tidbits in their stash for days or weeks. E.g., I
sometimes start on an idea and decide it's not worth pursuing (or more
likely, I post a snippet of a patch as a "how about this" to the mailing
list but don't plan on taking it further). Rather than run "git reset
--hard", I usually "git stash" the result. That means if I really do
decide I want it back, I can prowl through the stash list and find it.

All of which is to say that if we had such a feature, it should probably
be optional. For some people it would be very useful, and for others it
would be a nuisance.

Do you want to try a patch? I think you'd need to find the right spot in
wt-status.c to show the output, and then call for_each_reflog_ent() on
"refs/stash" and count the number of entries you see.

-Peff

```

## Samuel Lijin, 2017-06-10 10:12

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <CAJZjrdXCHVKQOxR=+z5cOkieKzE-iSMta--kHVjSYXuansb34Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAJZjrdXCHVKQOxR%3D%2Bz5cOkieKzE-iSMta--kHVjSYXuansb34Q%40mail.gmail.com
In-Reply-To: <20170610082534.6437ifexzly4oqg6@sigill.intra.peff.net>

```
On Sat, Jun 10, 2017 at 4:25 AM, Jeff King <peff@peff.net> wrote:
> On Wed, Jun 07, 2017 at 06:46:18PM -0400, Houston Fortney wrote:
>
>> I sometimes forget about something that I stashed. It would be nice if
>> the git status command would just say "There are x entries in the
>> stash." It can say nothing if there is nothing stashed so it is
>> usually not adding clutter.
>
> I think the clutter issue would depend on your workflow around stash.
>
> Some people carry tidbits in their stash for days or weeks. E.g., I
> sometimes start on an idea and decide it's not worth pursuing (or more
> likely, I post a snippet of a patch as a "how about this" to the mailing
> list but don't plan on taking it further). Rather than run "git reset
> --hard", I usually "git stash" the result. That means if I really do
> decide I want it back, I can prowl through the stash list and find it.
>
> All of which is to say that if we had such a feature, it should probably
> be optional. For some people it would be very useful, and for others it
> would be a nuisance.

Perhaps there should be a flag for this if it is implemented, say
status.showStash?

> Do you want to try a patch? I think you'd need to find the right spot in
> wt-status.c to show the output, and then call for_each_reflog_ent() on
> "refs/stash" and count the number of entries you see.
>
> -Peff

```

## Jeff King, 2017-06-10 10:22

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <20170610102217.vxf6tsrdfp6srupr@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170610102217.vxf6tsrdfp6srupr%40sigill.intra.peff.net
In-Reply-To: <CAJZjrdXCHVKQOxR=+z5cOkieKzE-iSMta--kHVjSYXuansb34Q@mail.gmail.com>

```
On Sat, Jun 10, 2017 at 06:12:28AM -0400, Samuel Lijin wrote:

> On Sat, Jun 10, 2017 at 4:25 AM, Jeff King <peff@peff.net> wrote:
> > On Wed, Jun 07, 2017 at 06:46:18PM -0400, Houston Fortney wrote:
> >
> >> I sometimes forget about something that I stashed. It would be nice if
> >> the git status command would just say "There are x entries in the
> >> stash." It can say nothing if there is nothing stashed so it is
> >> usually not adding clutter.
> >
> > I think the clutter issue would depend on your workflow around stash.
> >
> > Some people carry tidbits in their stash for days or weeks. E.g., I
> > sometimes start on an idea and decide it's not worth pursuing (or more
> > likely, I post a snippet of a patch as a "how about this" to the mailing
> > list but don't plan on taking it further). Rather than run "git reset
> > --hard", I usually "git stash" the result. That means if I really do
> > decide I want it back, I can prowl through the stash list and find it.
> >
> > All of which is to say that if we had such a feature, it should probably
> > be optional. For some people it would be very useful, and for others it
> > would be a nuisance.
> 
> Perhaps there should be a flag for this if it is implemented, say
> status.showStash?

Yes, that was what I was thinking.

-Peff

```

## liam Beguin, 2017-06-11 17:07

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <1c04d689-6796-17d1-e058-18874768c22a@gmail.com>
URL: https://gitlist.dev/e/1c04d689-6796-17d1-e058-18874768c22a%40gmail.com
In-Reply-To: <20170610102217.vxf6tsrdfp6srupr@sigill.intra.peff.net>

```
Hi,

As it looks like something easy enough for a beginner, I though I could
give it a try. Here is what it looks like. If it's good enough, I'll 
add a few lines to document 'status.showStash' and send a patch.

There is one thing I've noticed though. When using 'git stash pop', it
shows the the number of stashes before dropping the commit and I'm not
quite sure how to address this.

--

diff --git a/wt-status.c b/wt-status.c
index 25aafc35c833..fab66d4cd72e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -801,6 +801,27 @@ static void wt_longstatus_print_changed(struct wt_status *s)
 	wt_longstatus_print_trailer(s);
 }
 
+static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
+			    const char *email, timestamp_t timestamp, int tz,
+			    const char *message, void *cb_data)
+{
+	int *c = cb_data;
+	(*c)++;
+	return 0;
+}
+
+static void wt_longstatus_print_stash_summary(struct wt_status *s)
+{
+	int stash_count = 0;
+
+	for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
+	if (stash_count > 0)
+		status_printf_ln(s, GIT_COLOR_NORMAL,
+				 Q_("Your stash currently has %d commit",
+				    "Your stash currently has %d commits", stash_count),
+				 stash_count);
+}
+
 static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
 {
 	struct child_process sm_summary = CHILD_PROCESS_INIT;
@@ -1536,6 +1557,7 @@ static void wt_longstatus_print(struct wt_status *s)
 	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
 	const char *branch_status_color = color(WT_STATUS_HEADER, s);
 	struct wt_status_state state;
+	int show_stash = 0;
 
 	memset(&state, 0, sizeof(state));
 	wt_status_get_state(&state,
@@ -1641,6 +1663,8 @@ static void wt_longstatus_print(struct wt_status *s)
 		} else
 			printf(_("nothing to commit, working tree clean\n"));
 	}
+	if (!git_config_get_bool("status.showStash", &show_stash) && show_stash)
+		wt_longstatus_print_stash_summary(s);
 }
 
 static void wt_shortstatus_unmerged(struct string_list_item *it,




On 10/06/17 06:22 AM, Jeff King wrote:
> On Sat, Jun 10, 2017 at 06:12:28AM -0400, Samuel Lijin wrote:
> 
>> On Sat, Jun 10, 2017 at 4:25 AM, Jeff King <peff@peff.net> wrote:
>>> On Wed, Jun 07, 2017 at 06:46:18PM -0400, Houston Fortney wrote:
>>>
>>>> I sometimes forget about something that I stashed. It would be nice if
>>>> the git status command would just say "There are x entries in the
>>>> stash." It can say nothing if there is nothing stashed so it is
>>>> usually not adding clutter.
>>>
>>> I think the clutter issue would depend on your workflow around stash.
>>>
>>> Some people carry tidbits in their stash for days or weeks. E.g., I
>>> sometimes start on an idea and decide it's not worth pursuing (or more
>>> likely, I post a snippet of a patch as a "how about this" to the mailing
>>> list but don't plan on taking it further). Rather than run "git reset
>>> --hard", I usually "git stash" the result. That means if I really do
>>> decide I want it back, I can prowl through the stash list and find it.
>>>
>>> All of which is to say that if we had such a feature, it should probably
>>> be optional. For some people it would be very useful, and for others it
>>> would be a nuisance.
>>
>> Perhaps there should be a flag for this if it is implemented, say
>> status.showStash?
> 
> Yes, that was what I was thinking.
> 
> -Peff
> 

 - Liam

```

## Randall S. Becker, 2017-06-11 17:57

Subject: RE: Feature Request: Show status of the stash in git status command
Message-ID: <000b01d2e2dc$327c11c0$97743540$@nexbridge.com>
URL: https://gitlist.dev/e/000b01d2e2dc%24327c11c0%2497743540%24%40nexbridge.com
In-Reply-To: <1c04d689-6796-17d1-e058-18874768c22a@gmail.com>

```
On June 11, 2017 1:07 PM liam Beguin wrote:
>There is one thing I've noticed though. When using 'git stash pop', it shows the the number of stashes before dropping the commit and I'm not quite ?>sure how to address this.
<snip>
On 10/06/17 06:22 AM, Jeff King wrote:
> On Sat, Jun 10, 2017 at 06:12:28AM -0400, Samuel Lijin wrote:
>> On Sat, Jun 10, 2017 at 4:25 AM, Jeff King <peff@peff.net> wrote:
>>> On Wed, Jun 07, 2017 at 06:46:18PM -0400, Houston Fortney wrote:
>>>
>>>> I sometimes forget about something that I stashed. It would be nice 
>>>> if the git status command would just say "There are x entries in 
>>>> the stash." It can say nothing if there is nothing stashed so it is 
>>>> usually not adding clutter.
>>>
>>> I think the clutter issue would depend on your workflow around stash.
>>>
>>> Some people carry tidbits in their stash for days or weeks. E.g., I 
>>> sometimes start on an idea and decide it's not worth pursuing (or 
>>> more likely, I post a snippet of a patch as a "how about this" to 
>>> the mailing list but don't plan on taking it further). Rather than 
>>> run "git reset --hard", I usually "git stash" the result. That means 
>>> if I really do decide I want it back, I can prowl through the stash list and find it.
>>>
>>> All of which is to say that if we had such a feature, it should 
>>> probably be optional. For some people it would be very useful, and 
>>> for others it would be a nuisance.
>>
>> Perhaps there should be a flag for this if it is implemented, say 
>> status.showStash?

Random thought: what if a stash id could be used in the same way as any other ref, so diff stash[0] stash[1] would be possible - although I can see this being problematic for a merge or rebase.

Cheers,
Randall


```

## Igor Djordjevic, 2017-06-11 18:18

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <11f1877a-6ec3-02c1-5b06-c1a07a389010@gmail.com>
URL: https://gitlist.dev/e/11f1877a-6ec3-02c1-5b06-c1a07a389010%40gmail.com
In-Reply-To: <000b01d2e2dc$327c11c0$97743540$@nexbridge.com>

```
Hi Randall,

On 11/06/2017 19:57, Randall S. Becker wrote:
> Random thought: what if a stash id could be used in the same way as 
> any other ref, so diff stash[0] stash[1] would be possible - 
> although I can see this being problematic for a merge or rebase.

Not sure if I`m misunderstanding you, but at least `git diff 
stash@{0} stash@{1}` seems to already work as expected - I remember 
using it in the past, and I`ve tried it again now[1], and it still 
works.

[1] git version 2.13.0.windows.1

Regards,
Buga

```

## Randall S. Becker, 2017-06-11 18:30

Subject: RE: Feature Request: Show status of the stash in git status command
Message-ID: <000c01d2e2e0$cda526b0$68ef7410$@nexbridge.com>
URL: https://gitlist.dev/e/000c01d2e2e0%24cda526b0%2468ef7410%24%40nexbridge.com
In-Reply-To: <11f1877a-6ec3-02c1-5b06-c1a07a389010@gmail.com>

```
On June 11, 2017 2:19 PM  Igor Djordjevic wrote: 
>On 11/06/2017 19:57, Randall S. Becker wrote:
>> Random thought: what if a stash id could be used in the same way as 
>> any other ref, so diff stash[0] stash[1] would be possible - although 
>> I can see this being problematic for a merge or rebase.
>Not sure if I`m misunderstanding you, but at least `git diff stash@{0} stash@{1}` seems to already work as expected - I remember using it in the past, >and I`ve tried it again now[1], and it still works.

I'm sorry for not checking first before posting. Thanks 😊

Randall


```

## Junio C Hamano, 2017-06-12 15:35

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <xmqqpoe9p6bn.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqpoe9p6bn.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <1c04d689-6796-17d1-e058-18874768c22a@gmail.com>

```
liam Beguin <liambeguin@gmail.com> writes:

> +static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
> +			    const char *email, timestamp_t timestamp, int tz,
> +			    const char *message, void *cb_data)
> +{
> +	int *c = cb_data;
> +	(*c)++;
> +	return 0;
> +}

Count up, and tell the caller to keep going by returning 0.  That
sounds sane.

> +static void wt_longstatus_print_stash_summary(struct wt_status *s)
> +{
> +	int stash_count = 0;
> +
> +	for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);

And do so with a counter initialized to 0.  Also sane.

> +	if (stash_count > 0)
> +		status_printf_ln(s, GIT_COLOR_NORMAL,
> +				 Q_("Your stash currently has %d commit",
> +				    "Your stash currently has %d commits", stash_count),
> +				 stash_count);

Conceptually, the contents of the stash are *not* commits, even
though the implementation happens to use a commit to represent each
stash entry.  Perhaps "has %d entry/entries" is an improvement, but
a quick scanning of an early part of "git stash --help" tells me
that

	You have 1 stash / You have 4 stashes

would be the best, as the documentation calls each entry "a stash".
E.g. "list" is explained to list "the stashes", and "show <stash>"
is explained to show the changes recorded in "the stash".

> +}
> +
>  static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
>  {
>  	struct child_process sm_summary = CHILD_PROCESS_INIT;
> @@ -1536,6 +1557,7 @@ static void wt_longstatus_print(struct wt_status *s)
>  	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
>  	const char *branch_status_color = color(WT_STATUS_HEADER, s);
>  	struct wt_status_state state;
> +	int show_stash = 0;
>  
>  	memset(&state, 0, sizeof(state));
>  	wt_status_get_state(&state,
> @@ -1641,6 +1663,8 @@ static void wt_longstatus_print(struct wt_status *s)
>  		} else
>  			printf(_("nothing to commit, working tree clean\n"));
>  	}
> +	if (!git_config_get_bool("status.showStash", &show_stash) && show_stash)
> +		wt_longstatus_print_stash_summary(s);
>  }

Try to get "status.showstash" as a boolean, and only when it
succeeds and the value is true, give this extra info (i.e. when the
variable does not exist, do not complain and do not show).  Sounds
sensible.

Overall the logic looks good to me; just the phrasing is
questionable, relative to the existing documentation.

Thanks.

```

## liam Beguin, 2017-06-13 03:42

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <2217b9a1-dc8c-635a-649e-eae2dec5aaa5@gmail.com>
URL: https://gitlist.dev/e/2217b9a1-dc8c-635a-649e-eae2dec5aaa5%40gmail.com
In-Reply-To: <xmqqpoe9p6bn.fsf@gitster.mtv.corp.google.com>

```
Hi, 

Thanks for the feedback. I'll be sending a patch with the updates shortly!

On 12/06/17 11:35 AM, Junio C Hamano wrote:
> liam Beguin <liambeguin@gmail.com> writes:
> 
>> +static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
>> +			    const char *email, timestamp_t timestamp, int tz,
>> +			    const char *message, void *cb_data)
>> +{
>> +	int *c = cb_data;
>> +	(*c)++;
>> +	return 0;
>> +}
> 
> Count up, and tell the caller to keep going by returning 0.  That
> sounds sane.
> 
>> +static void wt_longstatus_print_stash_summary(struct wt_status *s)
>> +{
>> +	int stash_count = 0;
>> +
>> +	for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
> 
> And do so with a counter initialized to 0.  Also sane.
> 
>> +	if (stash_count > 0)
>> +		status_printf_ln(s, GIT_COLOR_NORMAL,
>> +				 Q_("Your stash currently has %d commit",
>> +				    "Your stash currently has %d commits", stash_count),
>> +				 stash_count);
> 
> Conceptually, the contents of the stash are *not* commits, even
> though the implementation happens to use a commit to represent each
> stash entry.  Perhaps "has %d entry/entries" is an improvement, but
> a quick scanning of an early part of "git stash --help" tells me
> that

what's different between a stash and a commit? 

> 
> 	You have 1 stash / You have 4 stashes
> 
> would be the best, as the documentation calls each entry "a stash".
> E.g. "list" is explained to list "the stashes", and "show <stash>"
> is explained to show the changes recorded in "the stash".
> 
>> +}
>> +
>>  static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
>>  {
>>  	struct child_process sm_summary = CHILD_PROCESS_INIT;
>> @@ -1536,6 +1557,7 @@ static void wt_longstatus_print(struct wt_status *s)
>>  	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
>>  	const char *branch_status_color = color(WT_STATUS_HEADER, s);
>>  	struct wt_status_state state;
>> +	int show_stash = 0;
>>  
>>  	memset(&state, 0, sizeof(state));
>>  	wt_status_get_state(&state,
>> @@ -1641,6 +1663,8 @@ static void wt_longstatus_print(struct wt_status *s)
>>  		} else
>>  			printf(_("nothing to commit, working tree clean\n"));
>>  	}
>> +	if (!git_config_get_bool("status.showStash", &show_stash) && show_stash)
>> +		wt_longstatus_print_stash_summary(s);
>>  }
> 
> Try to get "status.showstash" as a boolean, and only when it
> succeeds and the value is true, give this extra info (i.e. when the
> variable does not exist, do not complain and do not show).  Sounds
> sensible.
> 
> Overall the logic looks good to me; just the phrasing is
> questionable, relative to the existing documentation.
> 
> Thanks.
> 

Thanks,

 - Liam 

```

## Konstantin Khomoutov, 2017-06-13 06:42

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <20170613064142.aww23a75pu3ytym6@tigra>
URL: https://gitlist.dev/e/20170613064142.aww23a75pu3ytym6%40tigra
In-Reply-To: <2217b9a1-dc8c-635a-649e-eae2dec5aaa5@gmail.com>

```
On Mon, Jun 12, 2017 at 11:42:44PM -0400, liam Beguin wrote:

[...]
>> Conceptually, the contents of the stash are *not* commits, even
>> though the implementation happens to use a commit to represent each
>> stash entry.  Perhaps "has %d entry/entries" is an improvement, but
>> a quick scanning of an early part of "git stash --help" tells me
>> that
> 
> what's different between a stash and a commit? 

The same that exists between an interface and a concrete implementation
in a programming language.

"A stash entry" is a concept which is defined to keep explicitly
recorded untracked files and which can be applied, shown and deleted
from the stash bag (well, you can create a branch off it as well).

The fact a stash entry is a merge commit of two synthetic commits is an
implementation detail.  It can be very useful at times for power users,
but regular Git users need not be concerned with this.

Another fact worth reiterating that what the UI displays to the user is
better to match what the user reads in the docs. ;-)


```

## liam Beguin, 2017-06-13 12:34

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <be7311a1-1dfa-2cb6-4426-6771db545892@gmail.com>
URL: https://gitlist.dev/e/be7311a1-1dfa-2cb6-4426-6771db545892%40gmail.com
In-Reply-To: <20170613064142.aww23a75pu3ytym6@tigra>

```
Hi, 

On 13/06/17 02:42 AM, Konstantin Khomoutov wrote:
> On Mon, Jun 12, 2017 at 11:42:44PM -0400, liam Beguin wrote:
> 
> [...]
>>> Conceptually, the contents of the stash are *not* commits, even
>>> though the implementation happens to use a commit to represent each
>>> stash entry.  Perhaps "has %d entry/entries" is an improvement, but
>>> a quick scanning of an early part of "git stash --help" tells me
>>> that
>>
>> what's different between a stash and a commit? 
> 
> The same that exists between an interface and a concrete implementation
> in a programming language.

Makes sense, I thought there was a more fundamental difference.

> 
> "A stash entry" is a concept which is defined to keep explicitly
> recorded untracked files and which can be applied, shown and deleted
> from the stash bag (well, you can create a branch off it as well).

I've noticed this but I don't understand when it can be used.
I'll try to find out more on this.

> 
> The fact a stash entry is a merge commit of two synthetic commits is an
> implementation detail.  It can be very useful at times for power users,
> but regular Git users need not be concerned with this.
> 
> Another fact worth reiterating that what the UI displays to the user is
> better to match what the user reads in the docs. ;-)
> 

I'll make changes as suggested by Junio. I slightly prefer
"Your stash has %d entry/entries" over "You have %d stash/stashes" 
but I'll go with what's used elsewhere in the documentation. 

Thanks,

 - Liam

```

## Junio C Hamano, 2017-06-13 13:06

Subject: Re: Feature Request: Show status of the stash in git status command
Message-ID: <xmqq4lvk9gvf.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq4lvk9gvf.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <be7311a1-1dfa-2cb6-4426-6771db545892@gmail.com>

```
liam Beguin <liambeguin@gmail.com> writes:

>> The fact a stash entry is a merge commit of two synthetic commits is an
>> implementation detail.  It can be very useful at times for power users,
>> but regular Git users need not be concerned with this.
>> 
>> Another fact worth reiterating that what the UI displays to the user is
>> better to match what the user reads in the docs. ;-)
>
> I'll make changes as suggested by Junio. I slightly prefer
> "Your stash has %d entry/entries" over "You have %d stash/stashes" 
> but I'll go with what's used elsewhere in the documentation. 

Yup, I agree that I would definitely call them "stash entries" if I
were writing the documentation today, but lets match the new message
to the existing lingo first and think about renaming "a stash" to "a
stash entry" as a separate step.  The latter would become a larger
change (we'd also need to add an entry to glossary-contents.txt).

Thanks.

```
