{"thread":{"id":"11510","subject":"[PATCH] git-stash: add new 'drop' subcommand","startedAt":"2008-01-07T17:12:21Z","lastAt":"2008-01-07T17:12:21Z","messageCount":1,"participants":["Brandon Casey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64656","messageId":"47825D75.2020105@nrlssc.navy.mil","threadId":"11510","inReplyTo":null,"subject":"[PATCH] git-stash: add new 'drop' subcommand","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-01-07T17:12:21Z","receivedAt":"2008-01-07T17:12:21Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"This allows a single stash entry to be deleted. It takes an\noptional argument which is a stash reflog entry. If no\narguments are supplied, it drops the most recent stash entry.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n\n\nThis implements the suggested changes on top of latest next.\nWe can leave the discussion of naming and any other issues\nuntil after 1.5.4 so not to cause a distraction unless\npeople feel otherwise.\n\n-brandon\n\n\n Documentation/git-stash.txt |    7 ++++++-\n git-stash.sh                |   25 ++++++++++++++++++++++++-\n 2 files changed, 30 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 9889806..7afc8d3 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -8,7 +8,7 @@ git-stash - Stash the changes in a dirty working directory away\n SYNOPSIS\n --------\n [verse]\n-'git-stash' (list | show [<stash>] | apply [<stash>] | clear)\n+'git-stash' (list | show [<stash>] | apply [<stash>] | clear | drop [<stash>])\n 'git-stash' [save] [message...]\n \n DESCRIPTION\n@@ -81,6 +81,11 @@ clear::\n \tRemove all the stashed states. Note that those states will then\n \tbe subject to pruning, and may be difficult or impossible to recover.\n \n+drop [<stash>]::\n+\n+\tRemove a single stashed state from the stash list. When no `<stash>`\n+\tis given, it removes the latest one. i.e. `stash@\\{0}`\n+\n \n DISCUSSION\n ----------\ndiff --git a/git-stash.sh b/git-stash.sh\nindex b00f888..d6d77fa 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -1,7 +1,7 @@\n #!/bin/sh\n # Copyright (c) 2007, Nanako Shiraishi\n \n-USAGE='[  | save | list | show | apply | clear | create ]'\n+USAGE='[  | save | list | show | apply | clear | drop | create ]'\n \n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n@@ -196,6 +196,25 @@ apply_stash () {\n \tfi\n }\n \n+drop_stash () {\n+\thave_stash || die 'No stash entries to drop'\n+\n+\ttest $# = 0 && set -- \"$ref_stash@{0}\"\n+\n+\t# Verify supplied argument looks like a stash entry\n+\ts=$(git rev-parse --revs-only --no-flags \"$@\") &&\n+\tgit rev-parse --verify \"$s:\"   > /dev/null 2>&1 &&\n+\tgit rev-parse --verify \"$s^1:\" > /dev/null 2>&1 &&\n+\tgit rev-parse --verify \"$s^2:\" > /dev/null 2>&1 ||\n+\t\tdie \"$*: not a valid stashed state\"\n+\n+\tgit reflog delete \"$@\" && echo \"Dropped $* ($s)\" ||\n+\t\tdie \"$*: Could not drop stash entry\"\n+\n+\t# clear_stash if we just dropped the last stash entry\n+\tgit rev-parse --verify \"$ref_stash@{0}\" > /dev/null 2>&1 || clear_stash\n+}\n+\n # Main command set\n case \"$1\" in\n list)\n@@ -230,6 +249,10 @@ create)\n \tfi\n \tcreate_stash \"$*\" && echo \"$w_commit\"\n \t;;\n+drop)\n+\tshift\n+\tdrop_stash \"$@\"\n+\t;;\n *)\n \tif test $# -eq 0\n \tthen\n-- \n1.5.3.6\n"}]}