threads / patch / 38355

patchstash clear: allow -v/--verbose to be passed

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

## tl;dr

2 messages between Jan 13, 2015 and Jan 13, 2015. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Alexander Kuleshov· Jan 13, 2015, 17:54 UTC · lore
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(-)
Show changes to 2 files +12 −7

Documentation/git-stash.txt, git-stash.sh

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· Jan 13, 2015, 18:51 UTC · re: Alexander Kuleshov · lore

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

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.

← back to recent threads