threads / patch / 46199

patch, 3 partsadd stash count information to git-status command

Subject: [PATCH 0/3] add stash count information to git-status command

## tl;dr

16 messages between Jun 16, 2017 and Jun 19, 2017. Diffs are folded; open one to read it.

replies: 15people: 3as markdown or json

Liam Beguin· Jun 16, 2017, 04:30 UTC · lore

As discussed here [*1*], this allows `git status` to show the number of entries currently stashed away.

I also tried to update the related parts of the documentation to use 'stash entry' instead of 'stash' as we agreed that it was a bit better. I don't mind dropping the documentation update and using something like "You have %d stash/stashes" in the status message if it makes the change "too big".

*1* https://public-inbox.org/git/CA+B9myHRahTd+FDgzK5AhXW+hq_Y_czMX9X6MXYBcr9WSPeiDw@mail.gmail.com/
Liam Beguin (3):
  stash: update documentation to use 'stash entries'
  wt-status: add optional stash status information
  glossary: define stash entries
 Documentation/config.txt           | 11 ++++++---
 Documentation/git-pull.txt         |  2 +-
 Documentation/git-rebase.txt       |  2 +-
 Documentation/git-stash.txt        | 49 +++++++++++++++++++-------------------
 Documentation/gitcli.txt           |  2 +-
 Documentation/glossary-content.txt |  4 ++++
 git-stash.sh                       |  6 ++---
 wt-status.c                        | 24 +++++++++++++++++++
 8 files changed, 67 insertions(+), 33 deletions(-)
-- 
2.9.4
Liam Beguin· Jun 16, 2017, 04:30 UTC · re: Liam Beguin · lore

[PATCH 1/3] stash: update documentation to use 'stash entries'

Most of the time, a 'stash entry' is called a 'stash' or a 'stash state'. Lets use 'stash entry' instead.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/config.txt     |  6 +++---
 Documentation/git-pull.txt   |  2 +-
 Documentation/git-rebase.txt |  2 +-
 Documentation/git-stash.txt  | 49 ++++++++++++++++++++++----------------------
 Documentation/gitcli.txt     |  2 +-
 git-stash.sh                 |  6 +++---
 6 files changed, 34 insertions(+), 33 deletions(-)
Show changes to 6 files +34 −33

Documentation/config.txt, Documentation/git-pull.txt, Documentation/git-rebase.txt, Documentation/git-stash.txt, Documentation/gitcli.txt, git-stash.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f6278a5ae6a1..23b807065d92 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2620,7 +2620,7 @@ rebase.autoSquash::
 	If set to true enable `--autosquash` option by default.
 
 rebase.autoStash::
-	When set to true, automatically create a temporary stash
+	When set to true, automatically create a temporary stash entry
 	before the operation begins, and apply it after the operation
 	ends.  This means that you can run rebase on a dirty worktree.
 	However, use with care: the final stash application after a
@@ -3029,12 +3029,12 @@ status.submoduleSummary::
 
 stash.showPatch::
 	If this is set to true, the `git stash show` command without an
-	option will show the stash in patch form.  Defaults to false.
+	option will show the stash entry in patch form.  Defaults to false.
 	See description of 'show' command in linkgit:git-stash[1].
 
 stash.showStat::
 	If this is set to true, the `git stash show` command without an
-	option will show diffstat of the stash.  Defaults to true.
+	option will show diffstat of the stash entry.  Defaults to true.
 	See description of 'show' command in linkgit:git-stash[1].
 
 submodule.<name>.url::
diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index e414185f5a6a..9db5e08f4a63 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -131,7 +131,7 @@ unless you have read linkgit:git-rebase[1] carefully.
 --autostash::
 --no-autostash::
 	Before starting rebase, stash local modifications away (see
-	linkgit:git-stash[1]) if needed, and apply the stash when
+	linkgit:git-stash[1]) if needed, and apply the stash entry when
 	done. `--no-autostash` is useful to override the `rebase.autoStash`
 	configuration variable (see linkgit:git-config[1]).
 +
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 53f4e144444a..a5afd602d8eb 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -446,7 +446,7 @@ used to override and disable this setting.
 
 --autostash::
 --no-autostash::
-	Automatically create a temporary stash before the operation
+	Automatically create a temporary stash entry before the operation
 	begins, and apply it after the operation ends.  This means
 	that you can run rebase on a dirty worktree.  However, use
 	with care: the final stash application after a successful
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 70191d06b69e..59979ad31dfe 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -51,18 +51,18 @@ OPTIONS
 save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
 push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--] [<pathspec>...]::
 
-	Save your local modifications to a new 'stash' and roll them
+	Save your local modifications to a new 'stash entry' and roll them
 	back to HEAD (in the working tree and in the index).
 	The <message> part is optional and gives
 	the description along with the stashed state.
 +
 For quickly making a snapshot, you can omit "push".  In this mode,
 non-option arguments are not allowed to prevent a misspelled
-subcommand from making an unwanted stash.  The two exceptions to this
+subcommand from making an unwanted entry.  The two exceptions to this
 are `stash -p` which acts as alias for `stash push -p` and pathspecs,
 which are allowed after a double hyphen `--` for disambiguation.
 +
-When pathspec is given to 'git stash push', the new stash records the
+When pathspec is given to 'git stash push', the new stash entry records the
 modified states only for the files that match the pathspec.  The index
 entries and working tree files are then rolled back to the state in
 HEAD only for these files, too, leaving files that do not match the
@@ -89,10 +89,10 @@ The `--patch` option implies `--keep-index`.  You can use
 
 list [<options>]::
 
-	List the stashes that you currently have.  Each 'stash' is listed
-	with its name (e.g. `stash@{0}` is the latest stash, `stash@{1}` is
+	List the stash entries that you currently have.  Each 'stash entry' is
+	listed with its name (e.g. `stash@{0}` is the latest entry, `stash@{1}` is
 	the one before, etc.), the name of the branch that was current when the
-	stash was made, and a short description of the commit the stash was
+	entry was made, and a short description of the commit the entry was
 	based on.
 +
 ----------------------------------------------------------------
@@ -105,11 +105,11 @@ command to control what is shown and how. See linkgit:git-log[1].
 
 show [<stash>]::
 
-	Show the changes recorded in the stash as a diff between the
-	stashed state and its original parent. When no `<stash>` is given,
+	Show the changes recorded in the stash entry as a diff between the
+	stashed entry and its original parent. When no `<stash>` is given, it
 	shows the latest one. By default, the command shows the diffstat, but
 	it will accept any format known to 'git diff' (e.g., `git stash show
-	-p stash@{1}` to view the second most recent stash in patch form).
+	-p stash@{1}` to view the second most recent entry in patch form).
 	You can use stash.showStat and/or stash.showPatch config variables
 	to change the default behavior.
 
@@ -149,26 +149,27 @@ branch <branchname> [<stash>]::
 +
 This is useful if the branch on which you ran `git stash save` has
 changed enough that `git stash apply` fails due to conflicts. Since
-the stash is applied on top of the commit that was HEAD at the time
-`git stash` was run, it restores the originally stashed state with
-no conflicts.
+the stash entry is applied on top of the commit that was HEAD at the
+time `git stash` was run, it restores the originally stashed entry
+with no conflicts.
 
 clear::
-	Remove all the stashed states. Note that those states will then
+	Remove all the stashed entries. Note that those entries will then
 	be subject to pruning, and may be impossible to recover (see
 	'Examples' below for a possible strategy).
 
 drop [-q|--quiet] [<stash>]::
 
-	Remove a single stashed state from the stash list. When no `<stash>`
+	Remove a single stashed entry from the stash list. When no `<stash>`
 	is given, it removes the latest one. i.e. `stash@{0}`, otherwise
 	`<stash>` must be a valid stash log reference of the form
 	`stash@{<revision>}`.
 
 create::
 
-	Create a stash (which is a regular commit object) and return its
-	object name, without storing it anywhere in the ref namespace.
+	Create a stash entry (which is a regular commit object) and
+	return its object name, without storing it anywhere in the ref
+	namespace.
 	This is intended to be useful for scripts.  It is probably not
 	the command you want to use; see "save" above.
 
@@ -182,10 +183,10 @@ store::
 DISCUSSION
 ----------
 
-A stash is represented as a commit whose tree records the state of the
-working directory, and its first parent is the commit at `HEAD` when
-the stash was created.  The tree of the second parent records the
-state of the index when the stash is made, and it is made a child of
+A stash entry is represented as a commit whose tree records the state
+of the working directory, and its first parent is the commit at `HEAD`
+when the entry was created.  The tree of the second parent records the
+state of the index when the entry is made, and it is made a child of
 the `HEAD` commit.  The ancestry graph looks like this:
 
             .----W
@@ -269,12 +270,12 @@ $ edit/build/test remaining parts
 $ git commit foo -m 'Remaining parts'
 ----------------------------------------------------------------
 
-Recovering stashes that were cleared/dropped erroneously::
+Recovering stash entries that were cleared/dropped erroneously::
 
-If you mistakenly drop or clear stashes, they cannot be recovered
+If you mistakenly drop or clear stash entries, they cannot be recovered
 through the normal safety mechanisms.  However, you can try the
-following incantation to get a list of stashes that are still in your
-repository, but not reachable any more:
+following incantation to get a list of stash entries that are still in
+your repository, but not reachable any more:
 +
 ----------------------------------------------------------------
 git fsck --unreachable |
diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt
index dfe7d8372723..9f13266a6851 100644
--- a/Documentation/gitcli.txt
+++ b/Documentation/gitcli.txt
@@ -194,7 +194,7 @@ different things.
  * The `--index` option is used to ask a command that
    usually works on files in the working tree to *also*
    affect the index.  For example, `git stash apply` usually
-   merges changes recorded in a stash to the working tree,
+   merges changes recorded in a stash entry to the working tree,
    but with the `--index` option, it also merges changes to
    the index as well.
 
diff --git a/git-stash.sh b/git-stash.sh
index 2fb651b2b8d9..0dfa4785f361 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -481,7 +481,7 @@ parse_flags_and_rev()
 
 	case $# in
 		0)
-			have_stash || die "$(gettext "No stash found.")"
+			have_stash || die "$(gettext "No stash entry found.")"
 			set -- ${ref_stash}@{0}
 		;;
 		1)
@@ -573,7 +573,7 @@ apply_stash () {
 		GIT_INDEX_FILE="$TMPindex" git-read-tree "$u_tree" &&
 		GIT_INDEX_FILE="$TMPindex" git checkout-index --all &&
 		rm -f "$TMPindex" ||
-		die "$(gettext "Could not restore untracked files from stash")"
+		die "$(gettext "Could not restore untracked files from stash entry")"
 	fi
 
 	eval "
@@ -627,7 +627,7 @@ pop_stash() {
 		drop_stash "$@"
 	else
 		status=$?
-		say "$(gettext "The stash is kept in case you need it again.")"
+		say "$(gettext "The stash entry is kept in case you need it again.")"
 		exit $status
 	fi
 }
-- 
2.9.4
Jeff King· Jun 16, 2017, 12:06 UTC · re: Liam Beguin · lore

Re: [PATCH 1/3] stash: update documentation to use 'stash entries'

On Fri, Jun 16, 2017 at 12:30:48AM -0400, Liam Beguin wrote:
> Most of the time, a 'stash entry' is called a 'stash'
> or a 'stash state'. Lets use 'stash entry' instead.
I agree that this reads better. There is one exception:
Show 11 quoted lines
> diff --git a/git-stash.sh b/git-stash.sh
> index 2fb651b2b8d9..0dfa4785f361 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -481,7 +481,7 @@ parse_flags_and_rev()
>  
>  	case $# in
>  		0)
> -			have_stash || die "$(gettext "No stash found.")"
> +			have_stash || die "$(gettext "No stash entry found.")"
>  			set -- ${ref_stash}@{0}

I don't think your change is wrong (and it's probably more grammatical than the original), but should this perhaps be "No stashes found" or "No stash entries found"?

-Peff
Junio C Hamano· Jun 16, 2017, 21:24 UTC · re: Liam Beguin · lore

Re: [PATCH 1/3] stash: update documentation to use 'stash entries'

Liam Beguin <liambeguin@gmail.com> writes:
Show 23 quoted lines
> Most of the time, a 'stash entry' is called a 'stash'
> or a 'stash state'. Lets use 'stash entry' instead.
>
> Signed-off-by: Liam Beguin <liambeguin@gmail.com>
> ---
> diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
> index 70191d06b69e..59979ad31dfe 100644
> --- a/Documentation/git-stash.txt
> +++ b/Documentation/git-stash.txt
> @@ -51,18 +51,18 @@ OPTIONS
>  save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
>  push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--] [<pathspec>...]::
>  
> -	Save your local modifications to a new 'stash' and roll them
> +	Save your local modifications to a new 'stash entry' and roll them
>  	back to HEAD (in the working tree and in the index).
>  	The <message> part is optional and gives
>  	the description along with the stashed state.
>  +
>  For quickly making a snapshot, you can omit "push".  In this mode,
>  non-option arguments are not allowed to prevent a misspelled
> -subcommand from making an unwanted stash.  The two exceptions to this
> +subcommand from making an unwanted entry.  The two exceptions to this

It is more clear to spell it out as 'unwanted stash entry' in the context of this sentence.

Show 7 quoted lines
>  list [<options>]::
>  
> -	List the stashes that you currently have.  Each 'stash' is listed
> -	with its name (e.g. `stash@{0}` is the latest stash, `stash@{1}` is
> +	List the stash entries that you currently have.  Each 'stash entry' is
> +	listed with its name (e.g. `stash@{0}` is the latest entry, `stash@{1}` is
>  	the one before, etc.), the name of the branch that was current when the

Unlike the previous one, 'the latest entry' here is clear enough that it is talking about 'the latest stash entry' from the context, and I think this paragraph is good.

> -	stash was made, and a short description of the commit the stash was
> +	entry was made, and a short description of the commit the entry was
So is this one.
Show 7 quoted lines
> @@ -105,11 +105,11 @@ command to control what is shown and how. See linkgit:git-log[1].
>  
>  show [<stash>]::
>  
> -	Show the changes recorded in the stash as a diff between the
> -	stashed state and its original parent. When no `<stash>` is given,
> +	Show the changes recorded in the stash entry as a diff between the
This is good, but...
> +	stashed entry and its original parent. When no `<stash>` is given, it

... the original phrasing "stashed state" is better than this rewrite, because a "stash entry" is a vessel that holds a set of "stashed states" (the working tree state, the state of the index, and the contents of untracked files).

I think what is shown is "between the stashed contents of the working tree and the commit back when the stash entry was created".

Show 10 quoted lines
> @@ -149,26 +149,27 @@ branch <branchname> [<stash>]::
>  +
>  This is useful if the branch on which you ran `git stash save` has
>  changed enough that `git stash apply` fails due to conflicts. Since
> -the stash is applied on top of the commit that was HEAD at the time
> -`git stash` was run, it restores the originally stashed state with
> -no conflicts.
> +the stash entry is applied on top of the commit that was HEAD at the
> +time `git stash` was run, it restores the originally stashed entry
> +with no conflicts.

Again, I do not think the last one should be made into "stashed entry". We are restoring the stashed state, recorded in the named 'stash entry'.

>  clear::
> -	Remove all the stashed states. Note that those states will then
> +	Remove all the stashed entries. Note that those entries will then
This is removing 'all the stash entries'.
>  drop [-q|--quiet] [<stash>]::
>  
> -	Remove a single stashed state from the stash list. When no `<stash>`
> +	Remove a single stashed entry from the stash list. When no `<stash>`
A single 'stash entry' is being removed from the list of stash entries.
Liam Beguin· Jun 16, 2017, 04:30 UTC · re: Liam Beguin · lore

[PATCH 2/3] wt-status: add optional stash status information

Add the `status.showStash` configuration option to allow git-status to show information about currently stashed entries.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/config.txt |  5 +++++
 wt-status.c              | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
Show changes to 2 files +29 −0

Documentation/config.txt, wt-status.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 23b807065d92..e83b0f641574 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2992,6 +2992,11 @@ status.displayCommentPrefix::
 	behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
 	Defaults to false.
 
+status.showStash::
+	If set to true, linkgit:git-status[1] will display the number of
+	entries currently stashed away.
+	Defaults to false.
+
 status.showUntrackedFiles::
 	By default, linkgit:git-status[1] and linkgit:git-commit[1] show
 	files which are not currently tracked by Git. Directories which
diff --git a/wt-status.c b/wt-status.c
index bf651f16fae8..7114eec123c8 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 entry",
+				    "Your stash currently has %d entries", 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;
@@ -1537,6 +1558,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,
@@ -1642,6 +1664,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,
-- 
2.9.4
Jeff King· Jun 16, 2017, 12:14 UTC · re: Liam Beguin · lore

Re: [PATCH 2/3] wt-status: add optional stash status information

On Fri, Jun 16, 2017 at 12:30:49AM -0400, Liam Beguin wrote:
Show 7 quoted lines
> @@ -1642,6 +1664,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);
>  }

This feels like a funny place to look up the config. How would you override it if were to have a "--no-stash" command line option?

The usual flow is for the caller to examine the config and set up fields in the wt_status object, which are then respected here in the low-level code.

So I think you probably want to handle this in git_status_config() along with other similar variables (like "status.branch").

I don't personally insist on actually adding "--no-stash" or similar to override it from the command line (there is always "git -c status.showStash=false" in a pinch). But I have seen other reviewers (including the maintainer) ask for that in the past, so you may want to anticipate it.

-Peff
Junio C Hamano· Jun 16, 2017, 21:29 UTC · re: Jeff King · lore

Re: [PATCH 2/3] wt-status: add optional stash status information

Jeff King <peff@peff.net> writes:
Show 12 quoted lines
> On Fri, Jun 16, 2017 at 12:30:49AM -0400, Liam Beguin wrote:
>
>> @@ -1642,6 +1664,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);
>>  }
>
> This feels like a funny place to look up the config. How would you
> override it if were to have a "--no-stash" command line option?
Good suggestion.

This is a common mistake we saw in submissions by many new contributors, and a good practice to avoid it is to start from a command line option without a configuration variable. I.e. make sure that

    $ git status --show-stash
    $ git status --show-stash --no-show-stash

work well. After that, add support for status.showStash and make these also work well:

    $ git -c status.showStash=false status --show-stash
    $ git -c status.showStash=true status --no-show-stash

These two new ones need to result in command line options overriding the configured default.

And have these four getting tested in test scripts.
Liam Beguin· Jun 16, 2017, 04:30 UTC · re: Liam Beguin · lore

[PATCH 3/3] glossary: define stash entries

Add glossary entry for "stash entries".
Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/glossary-content.txt | 4 ++++
 1 file changed, 4 insertions(+)
Show changes to Documentation/glossary-content.txt +4 −0
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 6e991c246915..026f66e7240a 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -570,6 +570,10 @@ The most notable example is `HEAD`.
 	is created by giving the `--depth` option to linkgit:git-clone[1], and
 	its history can be later deepened with linkgit:git-fetch[1].
 
+[[def_stash]]stash entry::
+	An <<def_object,object>> used to temporarily store the content of a
+	<<def_dirty,dirty>> working directory for futur reuse.
+
 [[def_submodule]]submodule::
 	A <<def_repository,repository>> that holds the history of a
 	separate project inside another repository (the latter of
-- 
2.9.4
Jeff King· Jun 16, 2017, 12:16 UTC · re: Liam Beguin · lore

Re: [PATCH 3/3] glossary: define stash entries

On Fri, Jun 16, 2017 at 12:30:50AM -0400, Liam Beguin wrote:
Show 11 quoted lines
> diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
> index 6e991c246915..026f66e7240a 100644
> --- a/Documentation/glossary-content.txt
> +++ b/Documentation/glossary-content.txt
> @@ -570,6 +570,10 @@ The most notable example is `HEAD`.
>  	is created by giving the `--depth` option to linkgit:git-clone[1], and
>  	its history can be later deepened with linkgit:git-fetch[1].
>  
> +[[def_stash]]stash entry::
> +	An <<def_object,object>> used to temporarily store the content of a
> +	<<def_dirty,dirty>> working directory for futur reuse.
s/futur/&e/
I think we'd usually say "contents" (plural) of a working directory.

It also stores the contents of the index. git-stash(1) says "current state of the working directory and the index".

-Peff
Jeff King· Jun 16, 2017, 12:16 UTC · re: Liam Beguin · lore

Re: [PATCH 0/3] add stash count information to git-status command

On Fri, Jun 16, 2017 at 12:30:47AM -0400, Liam Beguin wrote:
Show 8 quoted lines
> As discussed here [*1*], this allows `git status` to show the number of
> entries currently stashed away.
> 
> I also tried to update the related parts of the documentation to use
> 'stash entry' instead of 'stash' as we agreed that it was a bit better.
> I don't mind dropping the documentation update and using something like
> "You have %d stash/stashes" in the status message if it makes the change
> "too big".

I like the overall direction (including the documentation update). I noted a few minor problems in the various patches, though.

-Peff
Liam Beguin· Jun 16, 2017, 12:47 UTC · re: Jeff King · lore

Re: [PATCH 0/3] add stash count information to git-status command

Hi, 
On 16/06/17 08:16 AM, Jeff King wrote:
Show 13 quoted lines
> On Fri, Jun 16, 2017 at 12:30:47AM -0400, Liam Beguin wrote:
> 
>> As discussed here [*1*], this allows `git status` to show the number of
>> entries currently stashed away.
>>
>> I also tried to update the related parts of the documentation to use
>> 'stash entry' instead of 'stash' as we agreed that it was a bit better.
>> I don't mind dropping the documentation update and using something like
>> "You have %d stash/stashes" in the status message if it makes the change
>> "too big".
> 
> I like the overall direction (including the documentation update). I
> noted a few minor problems in the various patches, though.
Thanks for reviewing! I'll try to send an update later today.
> 
> -Peff
> 
 - Liam
Liam Beguin· Jun 17, 2017, 22:30 UTC · re: Liam Beguin · lore

[PATCH v2 0/3] add stash count information to git-status command

As discussed here [*1*], this allows `git status` to show the number of entries currently stashed away.

I also tried to update the related parts of the documentation to use 'stash entry' instead of 'stash' as we agreed that it was a bit better.

*1* https://public-inbox.org/git/CA+B9myHRahTd+FDgzK5AhXW+hq_Y_czMX9X6MXYBcr9WSPeiDw@mail.gmail.com/
Liam Beguin (3):
  stash: update documentation to use 'stash entry'
  status: add optional stash count information
  glossary: define 'stash entry'
 Documentation/config.txt           | 11 +++++--
 Documentation/git-pull.txt         |  2 +-
 Documentation/git-rebase.txt       |  2 +-
 Documentation/git-stash.txt        | 60 ++++++++++++++++++++------------------
 Documentation/git-status.txt       |  3 ++
 Documentation/gitcli.txt           |  2 +-
 Documentation/glossary-content.txt |  4 +++
 builtin/commit.c                   |  6 ++++
 git-stash.sh                       |  6 ++--
 t/t7508-status.sh                  | 32 ++++++++++++++++++++
 wt-status.c                        | 24 +++++++++++++++
 wt-status.h                        |  1 +
 12 files changed, 115 insertions(+), 38 deletions(-)
Base-commit: 97e2ff464302565877a00b8a9aa6a2d85bd1445e
Changes since v1:
 - update commit messages to be more consistent
 - improve Documentation based on feedback
 - move config lookup to `git_status_config()`
 - add '--show-stash' command line option to `git-status`
 - add tests for now option
Interdiff:
Show changes to 8 files +59 −16

Documentation/git-stash.txt, Documentation/git-status.txt, Documentation/glossary-content.txt, builtin/commit.c, git-stash.sh, t/t7508-status.sh, wt-status.c, wt-status.h

diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 59979ad31dfe..00f95fee1faf 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -58,7 +58,7 @@ push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q
 +
 For quickly making a snapshot, you can omit "push".  In this mode,
 non-option arguments are not allowed to prevent a misspelled
-subcommand from making an unwanted entry.  The two exceptions to this
+subcommand from making an unwanted stash entry.  The two exceptions to this
 are `stash -p` which acts as alias for `stash push -p` and pathspecs,
 which are allowed after a double hyphen `--` for disambiguation.
 +
@@ -106,10 +106,11 @@ command to control what is shown and how. See linkgit:git-log[1].
 show [<stash>]::
 
 	Show the changes recorded in the stash entry as a diff between the
-	stashed entry and its original parent. When no `<stash>` is given, it
-	shows the latest one. By default, the command shows the diffstat, but
-	it will accept any format known to 'git diff' (e.g., `git stash show
-	-p stash@{1}` to view the second most recent entry in patch form).
+	stashed contents and the commit back when the stash entry was first
+	created. When no `<stash>` is given, it shows the latest one.
+	By default, the command shows the diffstat, but it will accept any
+	format known to 'git diff' (e.g., `git stash show -p stash@{1}`
+	to view the second most recent entry in patch form).
 	You can use stash.showStat and/or stash.showPatch config variables
 	to change the default behavior.
 
@@ -150,20 +151,20 @@ branch <branchname> [<stash>]::
 This is useful if the branch on which you ran `git stash save` has
 changed enough that `git stash apply` fails due to conflicts. Since
 the stash entry is applied on top of the commit that was HEAD at the
-time `git stash` was run, it restores the originally stashed entry
+time `git stash` was run, it restores the originally stashed state
 with no conflicts.
 
 clear::
-	Remove all the stashed entries. Note that those entries will then
+	Remove all the stash entries. Note that those entries will then
 	be subject to pruning, and may be impossible to recover (see
 	'Examples' below for a possible strategy).
 
 drop [-q|--quiet] [<stash>]::
 
-	Remove a single stashed entry from the stash list. When no `<stash>`
-	is given, it removes the latest one. i.e. `stash@{0}`, otherwise
-	`<stash>` must be a valid stash log reference of the form
-	`stash@{<revision>}`.
+	Remove a single stash entry from the list of stash entries.
+	When no `<stash>` is given, it removes the latest one.
+	i.e. `stash@{0}`, otherwise `<stash>` must be a valid stash
+	log reference of the form `stash@{<revision>}`.
 
 create::
 
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index d70abc6afe3a..d47f198f15cd 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -32,6 +32,9 @@ OPTIONS
 --branch::
 	Show the branch and tracking info even in short-format.
 
+--show-stash::
+	Show the number of entries currently stashed away.
+
 --porcelain[=<version>]::
 	Give the output in an easy-to-parse format for scripts.
 	This is similar to the short output, but will remain stable
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 026f66e7240a..b71b943b12ed 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -571,8 +571,8 @@ The most notable example is `HEAD`.
 	its history can be later deepened with linkgit:git-fetch[1].
 
 [[def_stash]]stash entry::
-	An <<def_object,object>> used to temporarily store the content of a
-	<<def_dirty,dirty>> working directory for futur reuse.
+	An <<def_object,object>> used to temporarily store the contents of a
+	<<def_dirty,dirty>> working directory and the index for future reuse.
 
 [[def_submodule]]submodule::
 	A <<def_repository,repository>> that holds the history of a
diff --git a/builtin/commit.c b/builtin/commit.c
index ef52457effc1..c089fb87e363 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1295,6 +1295,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
 		status_deferred_config.show_branch = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "status.showstash")) {
+		s->show_stash = git_config_bool(k, v);
+		return 0;
+	}
 	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
 		s->use_color = git_config_colorbool(k, v);
 		return 0;
@@ -1343,6 +1347,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 			    N_("show status concisely"), STATUS_FORMAT_SHORT),
 		OPT_BOOL('b', "branch", &s.show_branch,
 			 N_("show branch information")),
+		OPT_BOOL(0, "show-stash", &s.show_stash,
+			 N_("show stash information")),
 		{ OPTION_CALLBACK, 0, "porcelain", &status_format,
 		  N_("version"), N_("machine-readable output"),
 		  PARSE_OPT_OPTARG, opt_parse_porcelain },
diff --git a/git-stash.sh b/git-stash.sh
index 0dfa4785f361..68be4146bd2a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -481,7 +481,7 @@ parse_flags_and_rev()
 
 	case $# in
 		0)
-			have_stash || die "$(gettext "No stash entry found.")"
+			have_stash || die "$(gettext "No stash entries found.")"
 			set -- ${ref_stash}@{0}
 		;;
 		1)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 79427840a4fa..7121a550c7ce 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1608,4 +1608,36 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
 	git config -f .gitmodules  --remove-section submodule.subname
 '
 
+test_expect_success 'show stash info with "--show-stash"' '
+	git reset --hard &&
+	git stash clear &&
+	echo 1 >file &&
+	git add file &&
+	git stash &&
+	git status >expected_default &&
+	git status --show-stash >expected_with_stash &&
+	test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
+'
+
+test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
+	git status --show-stash --no-show-stash >expected_without_stash &&
+	test_cmp expected_default expected_without_stash
+'
+
+test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
+	git -c status.showStash=false status --show-stash >actual &&
+	test_cmp expected_with_stash actual
+'
+
+test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
+	git -c status.showStash=true status --no-show-stash >actual &&
+	test_cmp expected_without_stash actual
+'
+
+test_expect_success 'no additionnal info if no stash entries' '
+	git stash clear &&
+	git -c status.showStash=true status >actual &&
+	test_cmp expected_without_stash actual
+'
+
 test_done
diff --git a/wt-status.c b/wt-status.c
index 7114eec123c8..7992a73902ae 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -137,6 +137,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->untracked.strdup_strings = 1;
 	s->ignored.strdup_strings = 1;
 	s->show_branch = -1;  /* unspecified */
+	s->show_stash = 0;
 	s->display_comment_prefix = 0;
 }
 
@@ -1558,7 +1559,6 @@ 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,
@@ -1664,7 +1664,7 @@ 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)
+	if(s->show_stash)
 		wt_longstatus_print_stash_summary(s);
 }
 
diff --git a/wt-status.h b/wt-status.h
index 8a3864783b03..d8ae2e590daf 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -77,6 +77,7 @@ struct wt_status {
 	unsigned colopts;
 	int null_termination;
 	int show_branch;
+	int show_stash;
 	int hints;
 
 	enum wt_status_format status_format;
-- 
2.9.4
Liam Beguin· Jun 17, 2017, 22:30 UTC · re: Liam Beguin · lore

[PATCH v2 3/3] glossary: define 'stash entry'

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/glossary-content.txt | 4 ++++
 1 file changed, 4 insertions(+)
Show changes to Documentation/glossary-content.txt +4 −0
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 6e991c246915..b71b943b12ed 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -570,6 +570,10 @@ The most notable example is `HEAD`.
 	is created by giving the `--depth` option to linkgit:git-clone[1], and
 	its history can be later deepened with linkgit:git-fetch[1].
 
+[[def_stash]]stash entry::
+	An <<def_object,object>> used to temporarily store the contents of a
+	<<def_dirty,dirty>> working directory and the index for future reuse.
+
 [[def_submodule]]submodule::
 	A <<def_repository,repository>> that holds the history of a
 	separate project inside another repository (the latter of
-- 
2.9.4
Liam Beguin· Jun 17, 2017, 22:30 UTC · re: Liam Beguin · lore

[PATCH v2 1/3] stash: update documentation to use 'stash entry'

Most of the time, a 'stash entry' is called a 'stash'. Lets try to make this more consistent and use 'stash entry' instead.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/config.txt     |  6 ++---
 Documentation/git-pull.txt   |  2 +-
 Documentation/git-rebase.txt |  2 +-
 Documentation/git-stash.txt  | 60 +++++++++++++++++++++++---------------------
 Documentation/gitcli.txt     |  2 +-
 git-stash.sh                 |  6 ++---
 6 files changed, 40 insertions(+), 38 deletions(-)
Show changes to 6 files +40 −38

Documentation/config.txt, Documentation/git-pull.txt, Documentation/git-rebase.txt, Documentation/git-stash.txt, Documentation/gitcli.txt, git-stash.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f6278a5ae6a1..23b807065d92 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2620,7 +2620,7 @@ rebase.autoSquash::
 	If set to true enable `--autosquash` option by default.
 
 rebase.autoStash::
-	When set to true, automatically create a temporary stash
+	When set to true, automatically create a temporary stash entry
 	before the operation begins, and apply it after the operation
 	ends.  This means that you can run rebase on a dirty worktree.
 	However, use with care: the final stash application after a
@@ -3029,12 +3029,12 @@ status.submoduleSummary::
 
 stash.showPatch::
 	If this is set to true, the `git stash show` command without an
-	option will show the stash in patch form.  Defaults to false.
+	option will show the stash entry in patch form.  Defaults to false.
 	See description of 'show' command in linkgit:git-stash[1].
 
 stash.showStat::
 	If this is set to true, the `git stash show` command without an
-	option will show diffstat of the stash.  Defaults to true.
+	option will show diffstat of the stash entry.  Defaults to true.
 	See description of 'show' command in linkgit:git-stash[1].
 
 submodule.<name>.url::
diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index e414185f5a6a..9db5e08f4a63 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -131,7 +131,7 @@ unless you have read linkgit:git-rebase[1] carefully.
 --autostash::
 --no-autostash::
 	Before starting rebase, stash local modifications away (see
-	linkgit:git-stash[1]) if needed, and apply the stash when
+	linkgit:git-stash[1]) if needed, and apply the stash entry when
 	done. `--no-autostash` is useful to override the `rebase.autoStash`
 	configuration variable (see linkgit:git-config[1]).
 +
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 53f4e144444a..a5afd602d8eb 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -446,7 +446,7 @@ used to override and disable this setting.
 
 --autostash::
 --no-autostash::
-	Automatically create a temporary stash before the operation
+	Automatically create a temporary stash entry before the operation
 	begins, and apply it after the operation ends.  This means
 	that you can run rebase on a dirty worktree.  However, use
 	with care: the final stash application after a successful
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 70191d06b69e..00f95fee1faf 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -51,18 +51,18 @@ OPTIONS
 save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
 push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--] [<pathspec>...]::
 
-	Save your local modifications to a new 'stash' and roll them
+	Save your local modifications to a new 'stash entry' and roll them
 	back to HEAD (in the working tree and in the index).
 	The <message> part is optional and gives
 	the description along with the stashed state.
 +
 For quickly making a snapshot, you can omit "push".  In this mode,
 non-option arguments are not allowed to prevent a misspelled
-subcommand from making an unwanted stash.  The two exceptions to this
+subcommand from making an unwanted stash entry.  The two exceptions to this
 are `stash -p` which acts as alias for `stash push -p` and pathspecs,
 which are allowed after a double hyphen `--` for disambiguation.
 +
-When pathspec is given to 'git stash push', the new stash records the
+When pathspec is given to 'git stash push', the new stash entry records the
 modified states only for the files that match the pathspec.  The index
 entries and working tree files are then rolled back to the state in
 HEAD only for these files, too, leaving files that do not match the
@@ -89,10 +89,10 @@ The `--patch` option implies `--keep-index`.  You can use
 
 list [<options>]::
 
-	List the stashes that you currently have.  Each 'stash' is listed
-	with its name (e.g. `stash@{0}` is the latest stash, `stash@{1}` is
+	List the stash entries that you currently have.  Each 'stash entry' is
+	listed with its name (e.g. `stash@{0}` is the latest entry, `stash@{1}` is
 	the one before, etc.), the name of the branch that was current when the
-	stash was made, and a short description of the commit the stash was
+	entry was made, and a short description of the commit the entry was
 	based on.
 +
 ----------------------------------------------------------------
@@ -105,11 +105,12 @@ command to control what is shown and how. See linkgit:git-log[1].
 
 show [<stash>]::
 
-	Show the changes recorded in the stash as a diff between the
-	stashed state and its original parent. When no `<stash>` is given,
-	shows the latest one. By default, the command shows the diffstat, but
-	it will accept any format known to 'git diff' (e.g., `git stash show
-	-p stash@{1}` to view the second most recent stash in patch form).
+	Show the changes recorded in the stash entry as a diff between the
+	stashed contents and the commit back when the stash entry was first
+	created. When no `<stash>` is given, it shows the latest one.
+	By default, the command shows the diffstat, but it will accept any
+	format known to 'git diff' (e.g., `git stash show -p stash@{1}`
+	to view the second most recent entry in patch form).
 	You can use stash.showStat and/or stash.showPatch config variables
 	to change the default behavior.
 
@@ -149,26 +150,27 @@ branch <branchname> [<stash>]::
 +
 This is useful if the branch on which you ran `git stash save` has
 changed enough that `git stash apply` fails due to conflicts. Since
-the stash is applied on top of the commit that was HEAD at the time
-`git stash` was run, it restores the originally stashed state with
-no conflicts.
+the stash entry is applied on top of the commit that was HEAD at the
+time `git stash` was run, it restores the originally stashed state
+with no conflicts.
 
 clear::
-	Remove all the stashed states. Note that those states will then
+	Remove all the stash entries. Note that those entries will then
 	be subject to pruning, and may be impossible to recover (see
 	'Examples' below for a possible strategy).
 
 drop [-q|--quiet] [<stash>]::
 
-	Remove a single stashed state from the stash list. When no `<stash>`
-	is given, it removes the latest one. i.e. `stash@{0}`, otherwise
-	`<stash>` must be a valid stash log reference of the form
-	`stash@{<revision>}`.
+	Remove a single stash entry from the list of stash entries.
+	When no `<stash>` is given, it removes the latest one.
+	i.e. `stash@{0}`, otherwise `<stash>` must be a valid stash
+	log reference of the form `stash@{<revision>}`.
 
 create::
 
-	Create a stash (which is a regular commit object) and return its
-	object name, without storing it anywhere in the ref namespace.
+	Create a stash entry (which is a regular commit object) and
+	return its object name, without storing it anywhere in the ref
+	namespace.
 	This is intended to be useful for scripts.  It is probably not
 	the command you want to use; see "save" above.
 
@@ -182,10 +184,10 @@ store::
 DISCUSSION
 ----------
 
-A stash is represented as a commit whose tree records the state of the
-working directory, and its first parent is the commit at `HEAD` when
-the stash was created.  The tree of the second parent records the
-state of the index when the stash is made, and it is made a child of
+A stash entry is represented as a commit whose tree records the state
+of the working directory, and its first parent is the commit at `HEAD`
+when the entry was created.  The tree of the second parent records the
+state of the index when the entry is made, and it is made a child of
 the `HEAD` commit.  The ancestry graph looks like this:
 
             .----W
@@ -269,12 +271,12 @@ $ edit/build/test remaining parts
 $ git commit foo -m 'Remaining parts'
 ----------------------------------------------------------------
 
-Recovering stashes that were cleared/dropped erroneously::
+Recovering stash entries that were cleared/dropped erroneously::
 
-If you mistakenly drop or clear stashes, they cannot be recovered
+If you mistakenly drop or clear stash entries, they cannot be recovered
 through the normal safety mechanisms.  However, you can try the
-following incantation to get a list of stashes that are still in your
-repository, but not reachable any more:
+following incantation to get a list of stash entries that are still in
+your repository, but not reachable any more:
 +
 ----------------------------------------------------------------
 git fsck --unreachable |
diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt
index dfe7d8372723..9f13266a6851 100644
--- a/Documentation/gitcli.txt
+++ b/Documentation/gitcli.txt
@@ -194,7 +194,7 @@ different things.
  * The `--index` option is used to ask a command that
    usually works on files in the working tree to *also*
    affect the index.  For example, `git stash apply` usually
-   merges changes recorded in a stash to the working tree,
+   merges changes recorded in a stash entry to the working tree,
    but with the `--index` option, it also merges changes to
    the index as well.
 
diff --git a/git-stash.sh b/git-stash.sh
index 2fb651b2b8d9..68be4146bd2a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -481,7 +481,7 @@ parse_flags_and_rev()
 
 	case $# in
 		0)
-			have_stash || die "$(gettext "No stash found.")"
+			have_stash || die "$(gettext "No stash entries found.")"
 			set -- ${ref_stash}@{0}
 		;;
 		1)
@@ -573,7 +573,7 @@ apply_stash () {
 		GIT_INDEX_FILE="$TMPindex" git-read-tree "$u_tree" &&
 		GIT_INDEX_FILE="$TMPindex" git checkout-index --all &&
 		rm -f "$TMPindex" ||
-		die "$(gettext "Could not restore untracked files from stash")"
+		die "$(gettext "Could not restore untracked files from stash entry")"
 	fi
 
 	eval "
@@ -627,7 +627,7 @@ pop_stash() {
 		drop_stash "$@"
 	else
 		status=$?
-		say "$(gettext "The stash is kept in case you need it again.")"
+		say "$(gettext "The stash entry is kept in case you need it again.")"
 		exit $status
 	fi
 }
-- 
2.9.4
Liam Beguin· Jun 17, 2017, 22:30 UTC · re: Liam Beguin · lore

[PATCH v2 2/3] status: add optional stash count information

Introduce '--show-stash' and its configuration option 'status.showStash' to allow git-status to show information about currently stashed entries.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/config.txt     |  5 +++++
 Documentation/git-status.txt |  3 +++
 builtin/commit.c             |  6 ++++++
 t/t7508-status.sh            | 32 ++++++++++++++++++++++++++++++++
 wt-status.c                  | 24 ++++++++++++++++++++++++
 wt-status.h                  |  1 +
 6 files changed, 71 insertions(+)
Show changes to 6 files +71 −0

Documentation/config.txt, Documentation/git-status.txt, builtin/commit.c, t/t7508-status.sh, wt-status.c, wt-status.h

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 23b807065d92..e83b0f641574 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2992,6 +2992,11 @@ status.displayCommentPrefix::
 	behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
 	Defaults to false.
 
+status.showStash::
+	If set to true, linkgit:git-status[1] will display the number of
+	entries currently stashed away.
+	Defaults to false.
+
 status.showUntrackedFiles::
 	By default, linkgit:git-status[1] and linkgit:git-commit[1] show
 	files which are not currently tracked by Git. Directories which
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index d70abc6afe3a..d47f198f15cd 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -32,6 +32,9 @@ OPTIONS
 --branch::
 	Show the branch and tracking info even in short-format.
 
+--show-stash::
+	Show the number of entries currently stashed away.
+
 --porcelain[=<version>]::
 	Give the output in an easy-to-parse format for scripts.
 	This is similar to the short output, but will remain stable
diff --git a/builtin/commit.c b/builtin/commit.c
index ef52457effc1..c089fb87e363 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1295,6 +1295,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
 		status_deferred_config.show_branch = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "status.showstash")) {
+		s->show_stash = git_config_bool(k, v);
+		return 0;
+	}
 	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
 		s->use_color = git_config_colorbool(k, v);
 		return 0;
@@ -1343,6 +1347,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 			    N_("show status concisely"), STATUS_FORMAT_SHORT),
 		OPT_BOOL('b', "branch", &s.show_branch,
 			 N_("show branch information")),
+		OPT_BOOL(0, "show-stash", &s.show_stash,
+			 N_("show stash information")),
 		{ OPTION_CALLBACK, 0, "porcelain", &status_format,
 		  N_("version"), N_("machine-readable output"),
 		  PARSE_OPT_OPTARG, opt_parse_porcelain },
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 79427840a4fa..7121a550c7ce 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1608,4 +1608,36 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
 	git config -f .gitmodules  --remove-section submodule.subname
 '
 
+test_expect_success 'show stash info with "--show-stash"' '
+	git reset --hard &&
+	git stash clear &&
+	echo 1 >file &&
+	git add file &&
+	git stash &&
+	git status >expected_default &&
+	git status --show-stash >expected_with_stash &&
+	test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
+'
+
+test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
+	git status --show-stash --no-show-stash >expected_without_stash &&
+	test_cmp expected_default expected_without_stash
+'
+
+test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
+	git -c status.showStash=false status --show-stash >actual &&
+	test_cmp expected_with_stash actual
+'
+
+test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
+	git -c status.showStash=true status --no-show-stash >actual &&
+	test_cmp expected_without_stash actual
+'
+
+test_expect_success 'no additionnal info if no stash entries' '
+	git stash clear &&
+	git -c status.showStash=true status >actual &&
+	test_cmp expected_without_stash actual
+'
+
 test_done
diff --git a/wt-status.c b/wt-status.c
index bf651f16fae8..7992a73902ae 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -137,6 +137,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->untracked.strdup_strings = 1;
 	s->ignored.strdup_strings = 1;
 	s->show_branch = -1;  /* unspecified */
+	s->show_stash = 0;
 	s->display_comment_prefix = 0;
 }
 
@@ -801,6 +802,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 entry",
+				    "Your stash currently has %d entries", 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;
@@ -1642,6 +1664,8 @@ static void wt_longstatus_print(struct wt_status *s)
 		} else
 			printf(_("nothing to commit, working tree clean\n"));
 	}
+	if(s->show_stash)
+		wt_longstatus_print_stash_summary(s);
 }
 
 static void wt_shortstatus_unmerged(struct string_list_item *it,
diff --git a/wt-status.h b/wt-status.h
index 8a3864783b03..d8ae2e590daf 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -77,6 +77,7 @@ struct wt_status {
 	unsigned colopts;
 	int null_termination;
 	int show_branch;
+	int show_stash;
 	int hints;
 
 	enum wt_status_format status_format;
-- 
2.9.4

← back to recent threads