# [PATCH] stash clear: allow -v/--verbose to be passed

2 messages from 2015-01-13 to 2015-01-13. Participants: Alexander Kuleshov, Junio C Hamano.
Thread: https://gitlist.dev/t/38355

## Alexander Kuleshov, 2015-01-13 17:54

Subject: [PATCH] stash clear: allow -v/--verbose to be passed
Message-ID: <1421171677-12215-1-git-send-email-kuleshovmail@gmail.com>
URL: https://gitlist.dev/e/1421171677-12215-1-git-send-email-kuleshovmail%40gmail.com

```
Added new option -v/--verbose to 'git stash clear' for verbose output.

For example:

    $ git stash clear -v
    Removed stash@{0}: WIP on stash-clear-verbose: 0ae1f56 Merge branch 'bp/diff-relative-config' into pu
    Removed stash@{1}: WIP on stash-clear-verbose: 0ae1f56 Merge branch 'bp/diff-relative-config' into pu
    Removed stash@{2}: WIP on stash-clear-verbose: 0ae1f56 Merge branch 'bp/diff-relative-config' into pu
    Removed stash@{3}: WIP on master: addfb21 Git 2.3.0-rc0

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 Documentation/git-stash.txt |  4 ++--
 git-stash.sh                | 15 ++++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 375213f..f5b3dd8 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -15,7 +15,7 @@ SYNOPSIS
 'git stash' branch <branchname> [<stash>]
 'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
 	     [-u|--include-untracked] [-a|--all] [<message>]]
-'git stash' clear
+'git stash' clear [-v|--verbose]
 'git stash' create [<message>]
 'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
 
@@ -136,7 +136,7 @@ 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.
 
-clear::
+clear [-v|--verbose]::
 	Remove all the stashed states. Note that those states will then
 	be subject to pruning, and may be impossible to recover (see
 	'Examples' below for a possible strategy).
diff --git a/git-stash.sh b/git-stash.sh
index 6846b18..9f16289 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -9,7 +9,7 @@ USAGE="list [<options>]
    or: $dashless branch <branchname> [<stash>]
    or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
 		       [-u|--include-untracked] [-a|--all] [<message>]]
-   or: $dashless clear"
+   or: $dashless clear [-v|--verbose]"
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
@@ -46,12 +46,17 @@ untracked_files () {
 }
 
 clear_stash () {
-	if test $# != 0
-	then
-		die "$(gettext "git stash clear with parameters is unimplemented")"
-	fi
 	if current=$(git rev-parse --verify --quiet $ref_stash)
 	then
+		case "$1" in
+			-v|--verbose)
+			    shift
+			    git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash -- | sed -e 's/^/Removed /g'
+			    ;;
+			*)
+			    break
+			    ;;
+		esac
 		git update-ref -d $ref_stash $current
 	fi
 }
-- 
2.3.0.rc0.239.g0ae1f56.dirty

```

## Junio C Hamano, 2015-01-13 18:51

Subject: Re: [PATCH] stash clear: allow -v/--verbose to be passed
Message-ID: <xmqqy4p6cy4k.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqy4p6cy4k.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1421171677-12215-1-git-send-email-kuleshovmail@gmail.com>

```
Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> Added new option -v/--verbose to 'git stash clear' for verbose output.

Why?

I would sort-of understand if it were "git stash clear --confirm"
that internally runs "git stash list" and then asks "Are you sure
(Y/n)?"  and then finally clears [*1*], but what value does it add
to the system to be able to see what you lost and cannot recover
anymore after the damage is done?

Note that I am not advocating adding "clear --confirm" here (that is
what I mean by "sort-of understand"); the users can do that "Do I
really want to discard these?" themselves.


[Footnote]

*1* Or perhaps copying the stash to boneyard/stash before removing
them so that they can "undo" once.

```
