Skip to content

Commit 849b44c

Browse files
committed
Merge branch 'lb/status-stash-count'
"git status" learned to optionally give how many stash entries the user has in its output. * lb/status-stash-count: glossary: define 'stash entry' status: add optional stash count information stash: update documentation to use 'stash entry'
2 parents e629a7d + 90f64f1 commit 849b44c

File tree

12 files changed

+115
-38
lines changed

12 files changed

+115
-38
lines changed

Documentation/config.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,7 @@ rebase.autoSquash::
26232623
If set to true enable `--autosquash` option by default.
26242624

26252625
rebase.autoStash::
2626-
When set to true, automatically create a temporary stash
2626+
When set to true, automatically create a temporary stash entry
26272627
before the operation begins, and apply it after the operation
26282628
ends. This means that you can run rebase on a dirty worktree.
26292629
However, use with care: the final stash application after a
@@ -2995,6 +2995,11 @@ status.displayCommentPrefix::
29952995
behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
29962996
Defaults to false.
29972997

2998+
status.showStash::
2999+
If set to true, linkgit:git-status[1] will display the number of
3000+
entries currently stashed away.
3001+
Defaults to false.
3002+
29983003
status.showUntrackedFiles::
29993004
By default, linkgit:git-status[1] and linkgit:git-commit[1] show
30003005
files which are not currently tracked by Git. Directories which
@@ -3032,12 +3037,12 @@ status.submoduleSummary::
30323037

30333038
stash.showPatch::
30343039
If this is set to true, the `git stash show` command without an
3035-
option will show the stash in patch form. Defaults to false.
3040+
option will show the stash entry in patch form. Defaults to false.
30363041
See description of 'show' command in linkgit:git-stash[1].
30373042

30383043
stash.showStat::
30393044
If this is set to true, the `git stash show` command without an
3040-
option will show diffstat of the stash. Defaults to true.
3045+
option will show diffstat of the stash entry. Defaults to true.
30413046
See description of 'show' command in linkgit:git-stash[1].
30423047

30433048
submodule.<name>.url::

Documentation/git-pull.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ unless you have read linkgit:git-rebase[1] carefully.
131131
--autostash::
132132
--no-autostash::
133133
Before starting rebase, stash local modifications away (see
134-
linkgit:git-stash[1]) if needed, and apply the stash when
134+
linkgit:git-stash[1]) if needed, and apply the stash entry when
135135
done. `--no-autostash` is useful to override the `rebase.autoStash`
136136
configuration variable (see linkgit:git-config[1]).
137137
+

Documentation/git-rebase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ used to override and disable this setting.
446446

447447
--autostash::
448448
--no-autostash::
449-
Automatically create a temporary stash before the operation
449+
Automatically create a temporary stash entry before the operation
450450
begins, and apply it after the operation ends. This means
451451
that you can run rebase on a dirty worktree. However, use
452452
with care: the final stash application after a successful

Documentation/git-stash.txt

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ OPTIONS
5151
save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
5252
push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--] [<pathspec>...]::
5353

54-
Save your local modifications to a new 'stash' and roll them
54+
Save your local modifications to a new 'stash entry' and roll them
5555
back to HEAD (in the working tree and in the index).
5656
The <message> part is optional and gives
5757
the description along with the stashed state.
5858
+
5959
For quickly making a snapshot, you can omit "push". In this mode,
6060
non-option arguments are not allowed to prevent a misspelled
61-
subcommand from making an unwanted stash. The two exceptions to this
61+
subcommand from making an unwanted stash entry. The two exceptions to this
6262
are `stash -p` which acts as alias for `stash push -p` and pathspecs,
6363
which are allowed after a double hyphen `--` for disambiguation.
6464
+
65-
When pathspec is given to 'git stash push', the new stash records the
65+
When pathspec is given to 'git stash push', the new stash entry records the
6666
modified states only for the files that match the pathspec. The index
6767
entries and working tree files are then rolled back to the state in
6868
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
8989

9090
list [<options>]::
9191

92-
List the stashes that you currently have. Each 'stash' is listed
93-
with its name (e.g. `stash@{0}` is the latest stash, `stash@{1}` is
92+
List the stash entries that you currently have. Each 'stash entry' is
93+
listed with its name (e.g. `stash@{0}` is the latest entry, `stash@{1}` is
9494
the one before, etc.), the name of the branch that was current when the
95-
stash was made, and a short description of the commit the stash was
95+
entry was made, and a short description of the commit the entry was
9696
based on.
9797
+
9898
----------------------------------------------------------------
@@ -105,11 +105,12 @@ command to control what is shown and how. See linkgit:git-log[1].
105105

106106
show [<stash>]::
107107

108-
Show the changes recorded in the stash as a diff between the
109-
stashed state and its original parent. When no `<stash>` is given,
110-
shows the latest one. By default, the command shows the diffstat, but
111-
it will accept any format known to 'git diff' (e.g., `git stash show
112-
-p stash@{1}` to view the second most recent stash in patch form).
108+
Show the changes recorded in the stash entry as a diff between the
109+
stashed contents and the commit back when the stash entry was first
110+
created. When no `<stash>` is given, it shows the latest one.
111+
By default, the command shows the diffstat, but it will accept any
112+
format known to 'git diff' (e.g., `git stash show -p stash@{1}`
113+
to view the second most recent entry in patch form).
113114
You can use stash.showStat and/or stash.showPatch config variables
114115
to change the default behavior.
115116

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

156157
clear::
157-
Remove all the stashed states. Note that those states will then
158+
Remove all the stash entries. Note that those entries will then
158159
be subject to pruning, and may be impossible to recover (see
159160
'Examples' below for a possible strategy).
160161

161162
drop [-q|--quiet] [<stash>]::
162163

163-
Remove a single stashed state from the stash list. When no `<stash>`
164-
is given, it removes the latest one. i.e. `stash@{0}`, otherwise
165-
`<stash>` must be a valid stash log reference of the form
166-
`stash@{<revision>}`.
164+
Remove a single stash entry from the list of stash entries.
165+
When no `<stash>` is given, it removes the latest one.
166+
i.e. `stash@{0}`, otherwise `<stash>` must be a valid stash
167+
log reference of the form `stash@{<revision>}`.
167168

168169
create::
169170

170-
Create a stash (which is a regular commit object) and return its
171-
object name, without storing it anywhere in the ref namespace.
171+
Create a stash entry (which is a regular commit object) and
172+
return its object name, without storing it anywhere in the ref
173+
namespace.
172174
This is intended to be useful for scripts. It is probably not
173175
the command you want to use; see "save" above.
174176

@@ -182,10 +184,10 @@ store::
182184
DISCUSSION
183185
----------
184186

185-
A stash is represented as a commit whose tree records the state of the
186-
working directory, and its first parent is the commit at `HEAD` when
187-
the stash was created. The tree of the second parent records the
188-
state of the index when the stash is made, and it is made a child of
187+
A stash entry is represented as a commit whose tree records the state
188+
of the working directory, and its first parent is the commit at `HEAD`
189+
when the entry was created. The tree of the second parent records the
190+
state of the index when the entry is made, and it is made a child of
189191
the `HEAD` commit. The ancestry graph looks like this:
190192

191193
.----W
@@ -269,12 +271,12 @@ $ edit/build/test remaining parts
269271
$ git commit foo -m 'Remaining parts'
270272
----------------------------------------------------------------
271273

272-
Recovering stashes that were cleared/dropped erroneously::
274+
Recovering stash entries that were cleared/dropped erroneously::
273275

274-
If you mistakenly drop or clear stashes, they cannot be recovered
276+
If you mistakenly drop or clear stash entries, they cannot be recovered
275277
through the normal safety mechanisms. However, you can try the
276-
following incantation to get a list of stashes that are still in your
277-
repository, but not reachable any more:
278+
following incantation to get a list of stash entries that are still in
279+
your repository, but not reachable any more:
278280
+
279281
----------------------------------------------------------------
280282
git fsck --unreachable |

Documentation/git-status.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ OPTIONS
3232
--branch::
3333
Show the branch and tracking info even in short-format.
3434

35+
--show-stash::
36+
Show the number of entries currently stashed away.
37+
3538
--porcelain[=<version>]::
3639
Give the output in an easy-to-parse format for scripts.
3740
This is similar to the short output, but will remain stable

Documentation/gitcli.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ different things.
194194
* The `--index` option is used to ask a command that
195195
usually works on files in the working tree to *also*
196196
affect the index. For example, `git stash apply` usually
197-
merges changes recorded in a stash to the working tree,
197+
merges changes recorded in a stash entry to the working tree,
198198
but with the `--index` option, it also merges changes to
199199
the index as well.
200200

Documentation/glossary-content.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ The most notable example is `HEAD`.
570570
is created by giving the `--depth` option to linkgit:git-clone[1], and
571571
its history can be later deepened with linkgit:git-fetch[1].
572572

573+
[[def_stash]]stash entry::
574+
An <<def_object,object>> used to temporarily store the contents of a
575+
<<def_dirty,dirty>> working directory and the index for future reuse.
576+
573577
[[def_submodule]]submodule::
574578
A <<def_repository,repository>> that holds the history of a
575579
separate project inside another repository (the latter of

builtin/commit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
12971297
status_deferred_config.show_branch = git_config_bool(k, v);
12981298
return 0;
12991299
}
1300+
if (!strcmp(k, "status.showstash")) {
1301+
s->show_stash = git_config_bool(k, v);
1302+
return 0;
1303+
}
13001304
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
13011305
s->use_color = git_config_colorbool(k, v);
13021306
return 0;
@@ -1345,6 +1349,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13451349
N_("show status concisely"), STATUS_FORMAT_SHORT),
13461350
OPT_BOOL('b', "branch", &s.show_branch,
13471351
N_("show branch information")),
1352+
OPT_BOOL(0, "show-stash", &s.show_stash,
1353+
N_("show stash information")),
13481354
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
13491355
N_("version"), N_("machine-readable output"),
13501356
PARSE_OPT_OPTARG, opt_parse_porcelain },

git-stash.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ parse_flags_and_rev()
484484

485485
case $# in
486486
0)
487-
have_stash || die "$(gettext "No stash found.")"
487+
have_stash || die "$(gettext "No stash entries found.")"
488488
set -- ${ref_stash}@{0}
489489
;;
490490
1)
@@ -576,7 +576,7 @@ apply_stash () {
576576
GIT_INDEX_FILE="$TMPindex" git-read-tree "$u_tree" &&
577577
GIT_INDEX_FILE="$TMPindex" git checkout-index --all &&
578578
rm -f "$TMPindex" ||
579-
die "$(gettext "Could not restore untracked files from stash")"
579+
die "$(gettext "Could not restore untracked files from stash entry")"
580580
fi
581581

582582
eval "
@@ -630,7 +630,7 @@ pop_stash() {
630630
drop_stash "$@"
631631
else
632632
status=$?
633-
say "$(gettext "The stash is kept in case you need it again.")"
633+
say "$(gettext "The stash entry is kept in case you need it again.")"
634634
exit $status
635635
fi
636636
}

t/t7508-status.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,4 +1608,36 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
16081608
git config -f .gitmodules --remove-section submodule.subname
16091609
'
16101610

1611+
test_expect_success 'show stash info with "--show-stash"' '
1612+
git reset --hard &&
1613+
git stash clear &&
1614+
echo 1 >file &&
1615+
git add file &&
1616+
git stash &&
1617+
git status >expected_default &&
1618+
git status --show-stash >expected_with_stash &&
1619+
test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
1620+
'
1621+
1622+
test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
1623+
git status --show-stash --no-show-stash >expected_without_stash &&
1624+
test_cmp expected_default expected_without_stash
1625+
'
1626+
1627+
test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
1628+
git -c status.showStash=false status --show-stash >actual &&
1629+
test_cmp expected_with_stash actual
1630+
'
1631+
1632+
test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
1633+
git -c status.showStash=true status --no-show-stash >actual &&
1634+
test_cmp expected_without_stash actual
1635+
'
1636+
1637+
test_expect_success 'no additionnal info if no stash entries' '
1638+
git stash clear &&
1639+
git -c status.showStash=true status >actual &&
1640+
test_cmp expected_without_stash actual
1641+
'
1642+
16111643
test_done

0 commit comments

Comments
 (0)