Skip to contentSkip to conversation

add stash count information to git-status command

PATCH Superseded Liam Beguin 3 participants 16 messages Jun 16, 2017 – Jun 19, 2017 Documentation

lore
Share & tools
lore
#0 lore raw

cover 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. 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(-)
Signature · 1 line
2.9.4
#1 lore raw

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.

---
 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(-)
Documentation/config.txt +3 -3
index f6278a5ae6a1..23b807065d92 100644
@@ -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::
Documentation/git-pull.txt +1 -1
index e414185f5a6a..9db5e08f4a63 100644
@@ -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]).
 +
Documentation/git-rebase.txt +1 -1
index 53f4e144444a..a5afd602d8eb 100644
@@ -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
Documentation/git-stash.txt +25 -24

112 lines not on this page · raw message

Documentation/gitcli.txt +1 -1
index dfe7d8372723..9f13266a6851 100644
@@ -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.
 
git-stash.sh +3 -3
index 2fb651b2b8d9..0dfa4785f361 100755
@@ -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
 }
Signature · 1 line
2.9.4
#4 lore raw

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

In reply to Liam Beguin

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

---
 Documentation/config.txt |  5 +++++
 wt-status.c              | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
Documentation/config.txt +5 -0
index 23b807065d92..e83b0f641574 100644
@@ -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
wt-status.c +24 -0
index bf651f16fae8..7114eec123c8 100644
@@ -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,
Signature · 1 line
2.9.4
#7 lore raw

PATCH 3/3 glossary: define stash entries

In reply to Liam Beguin

Add glossary entry for "stash entries".

---
 Documentation/glossary-content.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/glossary-content.txt +4 -0
index 6e991c246915..026f66e7240a 100644
@@ -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
Signature · 1 line
2.9.4
#2 lore raw

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

In reply to Liam Beguin
Quoted 2 lines · Liam Beguin

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:

git-stash.sh parse_flags_and_rev() · line 485

Quoted 11 lines
git-stash.sh +1 -1
index 2fb651b2b8d9..0dfa4785f361 100755
@@ -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

#5 lore raw

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

In reply to Liam Beguin

wt-status.c static void wt_longstatus_print(struct wt_status *s) · line 1669

Quoted 7 lines · Liam Beguin
wt-status.c +2 -0
@@ -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

#8 lore raw

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

In reply to Liam Beguin

Documentation/glossary-content.txt The most notable example is `HEAD`. · line 575

Quoted 11 lines · Liam Beguin
Documentation/glossary-content.txt +3 -0
index 6e991c246915..026f66e7240a 100644
@@ -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

#9 lore raw
In reply to Liam Beguin
Quoted 8 lines · Liam Beguin

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

#10 lore raw

Hi,

Quoted 5 lines · Jeff King
Quoted 3 lines · Liam Beguin

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

Quoted 8 lines
Quoted 5 lines

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.

Quoted 3 lines

-Peff

- Liam

#3 lore raw

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

In reply to Liam Beguin
Quoted 13 lines · Liam Beguin

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

---

Documentation/git-stash.txt +0 -0
index 70191d06b69e..59979ad31dfe 100644
@@ -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>...]::
 

Documentation/git-stash.txt OPTIONS · line 61

Quoted 10 lines
Documentation/git-stash.txt +2 -2
-	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.

Documentation/git-stash.txt The `--patch` option implies `--keep-index`. You can use · line 94

Quoted 7 lines
Documentation/git-stash.txt +2 -2
 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.

Documentation/git-stash.txt The `--patch` option implies `--keep-index`. You can use · line 95

Quoted 2 lines
Documentation/git-stash.txt +1 -1
-	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.

Documentation/git-stash.txt command to control what is shown and how. See linkgit:git-log[1]. · line 108

Quoted 7 lines
Documentation/git-stash.txt +1 -2
@@ -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...

Documentation/git-stash.txt command to control what is shown and how. See linkgit:git-log[1]. · line 109

Quoted 1 line
Documentation/git-stash.txt +1 -0
+	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".

Documentation/git-stash.txt branch <branchname> [<stash>]:: · line 154

Quoted 10 lines
Documentation/git-stash.txt +3 -3
@@ -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'.

Documentation/git-stash.txt branch <branchname> [<stash>]:: · line 157

Quoted 3 lines
Documentation/git-stash.txt +1 -1
 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'.

Documentation/git-stash.txt branch <branchname> [<stash>]:: · line 163

Quoted 4 lines
Documentation/git-stash.txt +1 -1
 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.

#6 lore raw

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

In reply to Jeff King
Quoted 12 lines · Jeff King

wt-status.c static void wt_longstatus_print(struct wt_status *s) · line 1669

Quoted 7 lines · Liam Beguin
wt-status.c +2 -0
@@ -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.

#14 lore raw

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

In reply to Liam Beguin
---
 Documentation/glossary-content.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/glossary-content.txt +4 -0
index 6e991c246915..b71b943b12ed 100644
@@ -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
Signature · 1 line
2.9.4
#12 lore raw

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

In reply to Liam Beguin

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

---
 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(-)
Documentation/config.txt +3 -3
index f6278a5ae6a1..23b807065d92 100644
@@ -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::
Documentation/git-pull.txt +1 -1
index e414185f5a6a..9db5e08f4a63 100644
@@ -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]).
 +
Documentation/git-rebase.txt +1 -1
index 53f4e144444a..a5afd602d8eb 100644
@@ -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
Documentation/git-stash.txt +31 -29

118 lines not on this page · raw message

Documentation/gitcli.txt +1 -1
index dfe7d8372723..9f13266a6851 100644
@@ -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.
 
git-stash.sh +3 -3
index 2fb651b2b8d9..68be4146bd2a 100755
@@ -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
 }
Signature · 1 line
2.9.4
#13 lore raw

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

In reply to Liam Beguin

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

---
 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(+)
Documentation/config.txt +5 -0
index 23b807065d92..e83b0f641574 100644
@@ -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
Documentation/git-status.txt +3 -0
index d70abc6afe3a..d47f198f15cd 100644
@@ -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
builtin/commit.c +6 -0
index ef52457effc1..c089fb87e363 100644
@@ -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 },
t/t7508-status.sh +32 -0
index 79427840a4fa..7121a550c7ce 100755
@@ -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
wt-status.c +24 -0
index bf651f16fae8..7992a73902ae 100644
@@ -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,
wt-status.h +1 -0
index 8a3864783b03..d8ae2e590daf 100644
@@ -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;
Signature · 1 line
2.9.4
#11 lore raw

v2 cover add stash count information to git-status command

In reply to Liam Beguin

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:

Documentation/git-stash.txt +12 -11
index 59979ad31dfe..00f95fee1faf 100644
@@ -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::
 
Documentation/git-status.txt +3 -0
index d70abc6afe3a..d47f198f15cd 100644
@@ -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
Documentation/glossary-content.txt +2 -2
index 026f66e7240a..b71b943b12ed 100644
@@ -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
builtin/commit.c +6 -0
index ef52457effc1..c089fb87e363 100644
@@ -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 },
git-stash.sh +1 -1
index 0dfa4785f361..68be4146bd2a 100755
@@ -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)
t/t7508-status.sh +32 -0
index 79427840a4fa..7121a550c7ce 100755
@@ -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
wt-status.c +2 -2
index 7114eec123c8..7992a73902ae 100644
@@ -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);
 }
 
wt-status.h +1 -0
index 8a3864783b03..d8ae2e590daf 100644
@@ -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;
Signature · 1 line
2.9.4