@matheusbsbs / matheus-bagliano / commits / e25d5f9c82
Fork 0

git-stash: add new 'drop' subcommand

This allows a single stash entry to be deleted. It takes an optional argument which is a stash reflog entry. If no arguments are supplied, it drops the most recent stash entry. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Feb 22, 2008 at 13:04 UTC e25d5f9c82ef6a676de616bd28751cdfbcd53b15
2 files changed +33 -2
Documentation/git-stash.txt
+6 -1
@@ -8,7 +8,7 @@ git-stash - Stash the changes in a dirty working directory away
8 SYNOPSIS
9 --------
10 [verse]
11 -'git-stash' (list | show [<stash>] | apply [<stash>] | clear)
11 +'git-stash' (list | show [<stash>] | apply [<stash>] | clear | drop [<stash>])
12 'git-stash' [save [<message>]]
13
14 DESCRIPTION
@@ -85,6 +85,11 @@ clear::
85 Remove all the stashed states. Note that those states will then
86 be subject to pruning, and may be difficult or impossible to recover.
87
88 +drop [<stash>]::
89 +
90 + Remove a single stashed state from the stash list. When no `<stash>`
91 + is given, it removes the latest one. i.e. `stash@\{0}`
92 +
93
94 DISCUSSION
95 ----------
git-stash.sh
+27 -1
@@ -1,7 +1,7 @@
1 #!/bin/sh
2 # Copyright (c) 2007, Nanako Shiraishi
3
4 -USAGE='[ | save | list | show | apply | clear | create ]'
4 +USAGE='[ | save | list | show | apply | clear | drop | create ]'
5
6 SUBDIRECTORY_OK=Yes
7 OPTIONS_SPEC=
@@ -196,6 +196,28 @@ apply_stash () {
196 fi
197 }
198
199 +drop_stash () {
200 + have_stash || die 'No stash entries to drop'
201 +
202 + if test $# = 0
203 + then
204 + set x "$ref_stash@{0}"
205 + shift
206 + fi
207 + # Verify supplied argument looks like a stash entry
208 + s=$(git rev-parse --revs-only --no-flags "$@") &&
209 + git rev-parse --verify "$s:" > /dev/null 2>&1 &&
210 + git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
211 + git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
212 + die "$*: not a valid stashed state"
213 +
214 + git reflog delete --updateref --rewrite "$@" &&
215 + echo "Dropped $* ($s)" || die "$*: Could not drop stash entry"
216 +
217 + # clear_stash if we just dropped the last stash entry
218 + git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
219 +}
220 +
221 # Main command set
222 case "$1" in
223 list)
@@ -230,6 +252,10 @@ create)
252 fi
253 create_stash "$*" && echo "$w_commit"
254 ;;
255 +drop)
256 + shift
257 + drop_stash "$@"
258 + ;;
259 *)
260 if test $# -eq 0
261 then