stash: teach quiet option
Teach stash pop, apply, save, and drop to be quiet when told. By using the quiet option (-q), these actions will be silent unless errors are encountered. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Jun 17, 2009 at 18:07 UTC
fcdd0e92d9d42b8fa4569d92ba1013bb0eedfcd8
3 files changed
+92
-24
Documentation/git-stash.txt
+8
-7
@@ -9,10 +9,11 @@ SYNOPSIS
9
--------
10
[verse]
11
'git stash' list [<options>]
12
-'git stash' ( show | drop ) [<stash>]
13
-'git stash' ( pop | apply ) [--index] [<stash>]
12
+'git stash' show [<stash>]
13
+'git stash' drop [-q|--quiet] [<stash>]
14
+'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
15
'git stash' branch <branchname> [<stash>]
15
-'git stash' [save [--keep-index] [<message>]]
16
+'git stash' [save [--keep-index] [-q|--quiet] [<message>]]
17
'git stash' clear
18
'git stash' create
19
@@ -41,7 +42,7 @@ is also possible).
42
OPTIONS
43
-------
44
44
-save [--keep-index] [<message>]::
45
+save [--keep-index] [-q|--quiet] [<message>]::
46
47
Save your local modifications to a new 'stash', and run `git reset
48
--hard` to revert them. This is the default action when no
@@ -75,7 +76,7 @@ show [<stash>]::
76
it will accept any format known to 'git-diff' (e.g., `git stash show
77
-p stash@\{1}` to view the second most recent stash in patch form).
78
78
-pop [<stash>]::
79
+pop [--index] [-q|--quiet] [<stash>]::
80
81
Remove a single stashed state from the stash list and apply it
82
on top of the current working tree state, i.e., do the inverse
@@ -93,7 +94,7 @@ longer apply the changes as they were originally).
94
+
95
When no `<stash>` is given, `stash@\{0}` is assumed.
96
96
-apply [--index] [<stash>]::
97
+apply [--index] [-q|--quiet] [<stash>]::
98
99
Like `pop`, but do not remove the state from the stash list.
100
@@ -115,7 +116,7 @@ clear::
116
Remove all the stashed states. Note that those states will then
117
be subject to pruning, and may be difficult or impossible to recover.
118
118
-drop [<stash>]::
119
+drop [-q|--quiet] [<stash>]::
120
121
Remove a single stashed state from the stash list. When no `<stash>`
122
is given, it removes the latest one. i.e. `stash@\{0}`
git-stash.sh
+61
-17
@@ -3,10 +3,11 @@
3
4
dashless=$(basename "$0" | sed -e 's/-/ /')
5
USAGE="list [<options>]
6
- or: $dashless ( show | drop ) [<stash>]
7
- or: $dashless ( pop | apply ) [--index] [<stash>]
6
+ or: $dashless show [<stash>]
7
+ or: $dashless drop [-q|--quiet] [<stash>]
8
+ or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
9
or: $dashless branch <branchname> [<stash>]
9
- or: $dashless [save [--keep-index] [<message>]]
10
+ or: $dashless [save [--keep-index] [-q|--quiet] [<message>]]
11
or: $dashless clear"
12
13
SUBDIRECTORY_OK=Yes
@@ -94,18 +95,28 @@ create_stash () {
95
96
save_stash () {
97
keep_index=
97
- case "$1" in
98
- --keep-index)
99
- keep_index=t
98
+ while test $# != 0
99
+ do
100
+ case "$1" in
101
+ --keep-index)
102
+ keep_index=t
103
+ ;;
104
+ -q|--quiet)
105
+ GIT_QUIET=t
106
+ ;;
107
+ *)
108
+ break
109
+ ;;
110
+ esac
111
shift
101
- esac
112
+ done
113
114
stash_msg="$*"
115
116
git update-index -q --refresh
117
if no_changes
118
then
108
- echo 'No local changes to save'
119
+ say 'No local changes to save'
120
exit 0
121
fi
122
test -f "$GIT_DIR/logs/$ref_stash" ||
@@ -118,9 +129,9 @@ save_stash () {
129
130
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
131
die "Cannot save the current status"
121
- printf 'Saved working directory and index state "%s"\n' "$stash_msg"
132
+ say Saved working directory and index state "$stash_msg"
133
123
- git reset --hard
134
+ git reset --hard ${GIT_QUIET:+-q}
135
136
if test -n "$keep_index" && test -n $i_tree
137
then
@@ -156,11 +167,22 @@ apply_stash () {
167
die 'Cannot apply to a dirty working tree, please stage your changes'
168
169
unstash_index=
159
- case "$1" in
160
- --index)
161
- unstash_index=t
170
+
171
+ while test $# != 0
172
+ do
173
+ case "$1" in
174
+ --index)
175
+ unstash_index=t
176
+ ;;
177
+ -q|--quiet)
178
+ GIT_QUIET=t
179
+ ;;
180
+ *)
181
+ break
182
+ ;;
183
+ esac
184
shift
163
- esac
185
+ done
186
187
# current index state
188
c_tree=$(git write-tree) ||
@@ -193,6 +215,10 @@ apply_stash () {
215
export GITHEAD_$w_tree GITHEAD_$c_tree GITHEAD_$b_tree
216
"
217
218
+ if test -n "$GIT_QUIET"
219
+ then
220
+ export GIT_MERGE_VERBOSITY=0
221
+ fi
222
if git-merge-recursive $b_tree -- $c_tree $w_tree
223
then
224
# No conflict
@@ -207,7 +233,12 @@ apply_stash () {
233
die "Cannot unstage modified files"
234
rm -f "$a"
235
fi
210
- git status || :
236
+ squelch=
237
+ if test -n "$GIT_QUIET"
238
+ then
239
+ squelch='>/dev/null 2>&1'
240
+ fi
241
+ eval "git status $squelch" || :
242
else
243
# Merge conflict; keep the exit status from merge-recursive
244
status=$?
@@ -222,6 +253,19 @@ apply_stash () {
253
drop_stash () {
254
have_stash || die 'No stash entries to drop'
255
256
+ while test $# != 0
257
+ do
258
+ case "$1" in
259
+ -q|--quiet)
260
+ GIT_QUIET=t
261
+ ;;
262
+ *)
263
+ break
264
+ ;;
265
+ esac
266
+ shift
267
+ done
268
+
269
if test $# = 0
270
then
271
set x "$ref_stash@{0}"
@@ -235,7 +279,7 @@ drop_stash () {
279
die "$*: not a valid stashed state"
280
281
git reflog delete --updateref --rewrite "$@" &&
238
- echo "Dropped $* ($s)" || die "$*: Could not drop stash entry"
282
+ say "Dropped $* ($s)" || die "$*: Could not drop stash entry"
283
284
# clear_stash if we just dropped the last stash entry
285
git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
@@ -312,7 +356,7 @@ branch)
356
if test $# -eq 0
357
then
358
save_stash &&
315
- echo '(To restore them type "git stash apply")'
359
+ say '(To restore them type "git stash apply")'
360
else
361
usage
362
fi
t/t3903-stash.sh
+23
@@ -177,4 +177,27 @@ test_expect_success 'stash branch' '
177
test 0 = $(git stash list | wc -l)
178
'
179
180
+test_expect_success 'apply -q is quiet' '
181
+ echo foo > file &&
182
+ git stash &&
183
+ git stash apply -q > output.out 2>&1 &&
184
+ test ! -s output.out
185
+'
186
+
187
+test_expect_success 'save -q is quiet' '
188
+ git stash save --quiet > output.out 2>&1 &&
189
+ test ! -s output.out
190
+'
191
+
192
+test_expect_success 'pop -q is quiet' '
193
+ git stash pop -q > output.out 2>&1 &&
194
+ test ! -s output.out
195
+'
196
+
197
+test_expect_success 'drop -q is quiet' '
198
+ git stash &&
199
+ git stash drop -q > output.out 2>&1 &&
200
+ test ! -s output.out
201
+'
202
+
203
test_done