{"thread":{"id":"11479","subject":"[PATCH] git-stash: add new 'drop' subcommand","startedAt":"2008-01-05T01:31:00Z","lastAt":"2008-01-05T12:36:25Z","messageCount":8,"participants":["Brandon Casey","Junio C Hamano","Jeff King","JM Ibanez","Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64487","messageId":"477EDDD4.5060509@nrlssc.navy.mil","threadId":"11479","inReplyTo":"1199495198-26270-1-git-send-email-casey@nrlssc.navy.mil","subject":"[PATCH] git-stash: add new 'drop' subcommand","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-01-05T01:31:00Z","receivedAt":"2008-01-05T01:31:00Z","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, stash@{0} is used.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n\n\nThus far I haven't been a big user of git stash, but I plan to\nuse it more and I expect to use 'drop' more often than\n'clear'. I expect in the common case there will be a single\nstash, and 'drop' will be sufficient. For the case where there\nare many stashes and I want to remove one, 'drop' is required.\n'git stash clear' will become a command that I give special\nattention to just like 'rm -f *'.\n\nI'm not sure if there is a proper way to get 'stash@{0}' from\n'refs/stash' so I kept my usage of that former string outside\nof the drop_stash() function.\n\nComments welcome, especially if there is a more appropriate\nway to do this.\n\n-brandon\n\n\n Documentation/git-stash.txt |    7 ++++++-\n git-stash.sh                |   29 ++++++++++++++++++++++++++++-\n 2 files changed, 34 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex c0147b9..b89eadb 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 06cb177..a789a53 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 | create | drop ]'\n \n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n@@ -192,6 +192,24 @@ apply_stash () {\n \tfi\n }\n \n+drop_stash () {\n+\tif ! have_stash\n+\tthen\n+\t\techo >&2 'No stash entries to drop'\n+\t\texit 0\n+\tfi\n+\n+\t# Verify supplied argument looks like a stash entry\n+\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\") &&\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+\n # Main command set\n case \"$1\" in\n list)\n@@ -225,6 +243,15 @@ create)\n \tfi\n \tcreate_stash \"$*\" && echo \"$w_commit\"\n \t;;\n+drop)\n+\tshift\n+\tif test $# = 0\n+\tthen\n+\t\tset -- \"stash@{0}\"\n+\tfi\n+\tdrop_stash \"$@\" &&\n+\t(git rev-parse --verify \"stash@{0}\" > /dev/null 2>&1 || clear_stash)\n+\t;;\n *)\n \tif test $# -eq 0\n \tthen\n-- \n1.5.4.rc2.1119.g6fdf-dirty\n"},{"id":"64489","messageId":"7vtzltf3gg.fsf@gitster.siamese.dyndns.org","threadId":"11479","inReplyTo":"477EDDD4.5060509@nrlssc.navy.mil","subject":"Re: [PATCH] git-stash: add new 'drop' subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-05T01:47:43Z","receivedAt":"2008-01-05T01:47:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <casey@nrlssc.navy.mil> writes:\n\n> I'm not sure if there is a proper way to get 'stash@{0}' from\n> 'refs/stash' so I kept my usage of that former string outside\n> of the drop_stash() function.\n\nDoesn't \"$refs_stash@{0}\" (which would give refs/stash@{0} not\nstash@{0}) work for you?\n\n> diff --git a/git-stash.sh b/git-stash.sh\n> index 06cb177..a789a53 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 | create | drop ]'\n\nMight want to put drop next to clear, but that is minor.\n\n> +drop_stash () {\n> +\tif ! have_stash\n> +\tthen\n> +\t\techo >&2 'No stash entries to drop'\n> +\t\texit 0\n> +\tfi\n> +\n> +\t# Verify supplied argument looks like a stash entry\n> +\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\") &&\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\nThe second $@ is inconsistent with the next line's use of $*; intentional?\n\n> +\t\tdie \"$*: Could not drop stash entry\"\n> +}\n\n> +drop)\n> +\tshift\n> +\tif test $# = 0\n> +\tthen\n> +\t\tset -- \"stash@{0}\"\n> +\tfi\n> +\tdrop_stash \"$@\" &&\n> +\t(git rev-parse --verify \"stash@{0}\" > /dev/null 2>&1 || clear_stash)\n\nCurious.\n\n (1) Why not do the clearing inside drop_stash?\n\n (2) Why is clearning necessary in the first place (iow,\n     shouldn't \"reflog delete\" take care of that)?\n\nOther than that, nicely done.\n"},{"id":"64498","messageId":"20080105035118.GB26892@coredump.intra.peff.net","threadId":"11479","inReplyTo":"477EDDD4.5060509@nrlssc.navy.mil","subject":"Re: [PATCH] git-stash: add new 'drop' subcommand","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-05T03:51:18Z","receivedAt":"2008-01-05T03:51:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jan 04, 2008 at 07:31:00PM -0600, Brandon Casey wrote:\n\n> Thus far I haven't been a big user of git stash, but I plan to\n> use it more and I expect to use 'drop' more often than\n> 'clear'. I expect in the common case there will be a single\n\nThere was some discussion of a sensible name, but I don't recall seeing\na resolution on this: why not \"clear stash@{0}\" to clear one, and\n\"clear\" to clear all? Otherwise, I foresee \"git stash clear stash@{0}\"\nfollowed by \"oops, I just deleted all of my stashes.\"\n\nI guess you get \"git stash drop\" as a synonym for \"git stash drop\nstash@{0}\" this way, but it just seems mean to users to make them\nremember which of \"drop\" and \"clear\" does what they want.\n\n-Peff\n"},{"id":"64500","messageId":"loom.20080105T053356-853@post.gmane.org","threadId":"11479","inReplyTo":"7vtzltf3gg.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-stash: add new 'drop' subcommand","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2008-01-05T05:46:49Z","receivedAt":"2008-01-05T05:46:49Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Junio C Hamano <gitster <at> pobox.com> writes:\n\n> \n> Brandon Casey <casey <at> nrlssc.navy.mil> writes:\n> \n> > I'm not sure if there is a proper way to get 'stash@{0}' from\n> > 'refs/stash' so I kept my usage of that former string outside\n> > of the drop_stash() function.\n> \n> Doesn't \"$refs_stash@{0}\" (which would give refs/stash@{0} not\n> stash@{0}) work for you?\n\nyep that works. much nicer.\n\n> > diff --git a/git-stash.sh b/git-stash.sh\n> > -USAGE='[  | save | list | show | apply | clear | create ]'\n> > +USAGE='[  | save | list | show | apply | clear | create | drop ]'\n> \n> Might want to put drop next to clear, but that is minor.\n\nno problem.\n\n\n> > +\tgit reflog delete \"$@\" && echo \"Dropped $@ ($s)\" ||\n> \n> The second $@ is inconsistent with the next line's use of $*; intentional?\n\nnot intentional.\n\n> > +\t\tset -- \"stash@{0}\"\n> > +\tfi\n> > +\tdrop_stash \"$@\" &&\n> > +\t(git rev-parse --verify \"stash@{0}\" > /dev/null 2>&1 || clear_stash)\n> \n> Curious.\n> \n>  (1) Why not do the clearing inside drop_stash?\n\nonly because I didn't like stash@{0} notation and didn't want it\nburied inside a function.\n\n> \n>  (2) Why is clearning necessary in the first place (iow,\n>      shouldn't \"reflog delete\" take care of that)?\n\nclear_stash additionally deletes refs/stash and logs/refs/stash at least.\n\n-brandon\n"},{"id":"64517","messageId":"871w8woc77.fsf@adler.orangeandbronze.com","threadId":"11479","inReplyTo":"20080105035118.GB26892@coredump.intra.peff.net","subject":"Re: [PATCH] git-stash: add new 'drop' subcommand","fromName":"JM Ibanez","fromEmail":"jm@orangeandbronze.com","sentAt":"2008-01-05T09:26:20Z","receivedAt":"2008-01-05T09:26:20Z","isPatch":true,"sender":{"key":"jm@orangeandbronze.com","avatar":null},"body":"Jeff King <peff@peff.net> writes:\n\n> On Fri, Jan 04, 2008 at 07:31:00PM -0600, Brandon Casey wrote:\n>\n>> Thus far I haven't been a big user of git stash, but I plan to\n>> use it more and I expect to use 'drop' more often than\n>> 'clear'. I expect in the common case there will be a single\n>\n> There was some discussion of a sensible name, but I don't recall seeing\n> a resolution on this: why not \"clear stash@{0}\" to clear one, and\n> \"clear\" to clear all? Otherwise, I foresee \"git stash clear stash@{0}\"\n> followed by \"oops, I just deleted all of my stashes.\"\n\nI actually got hit by this. I didn't know that stash clear affected all\nstashes and lost quite a bit of work that way (I use stash to store\nvarious test database configs for a tree I work with, and so lost all of\nthem when trying to remove one particular stash).\n\n> I guess you get \"git stash drop\" as a synonym for \"git stash drop\n> stash@{0}\" this way, but it just seems mean to users to make them\n> remember which of \"drop\" and \"clear\" does what they want.\n\nI have to agree with this.\n\n-- \nJM Ibanez\nSoftware Architect\nOrange & Bronze Software Labs, Ltd. Co.\n\njm@orangeandbronze.com\nhttp://software.orangeandbronze.com/\n"},{"id":"64519","messageId":"7vy7b4bon9.fsf_-_@gitster.siamese.dyndns.org","threadId":"11479","inReplyTo":"871w8woc77.fsf@adler.orangeandbronze.com","subject":"[PATCH] git-stash clear: refuse to work with extra parameter for now","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-05T09:35:54Z","receivedAt":"2008-01-05T09:35:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Because it is so tempting to expect \"git stash clear stash@{4}\"\nto remove the fourth element in the stash while leaving other\nelements intact, we should not blindly throw away everything.\n\nThis may change when we start using \"git reflog delete\" to\nselectively nuke a single (or multiple, for that matter) stash\nentries when such a command is given.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\nJM Ibanez <jm@orangeandbronze.com> writes:\n\n> Jeff King <peff@peff.net> writes:\n> ...\n>> There was some discussion of a sensible name, but I don't recall seeing\n>> a resolution on this: why not \"clear stash@{0}\" to clear one, and\n>> \"clear\" to clear all? Otherwise, I foresee \"git stash clear stash@{0}\"\n>> followed by \"oops, I just deleted all of my stashes.\"\n>\n> I actually got hit by this. I didn't know that stash clear affected all\n> stashes and lost quite a bit of work that way (I use stash to store\n> various test database configs for a tree I work with, and so lost all of\n> them when trying to remove one particular stash).\n\nI think something along this line may be necessary to\nfutureproof our users. \n\n git-stash.sh |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 06cb177..80036ef 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -20,6 +20,10 @@ no_changes () {\n }\n \n clear_stash () {\n+\tif test $# != 0\n+\tthen\n+\t\tdie \"git stash clear with parameters unimplemented $@\"\n+\tfi\n \tif current=$(git rev-parse --verify $ref_stash 2>/dev/null)\n \tthen\n \t\tgit update-ref -d $ref_stash $current\n@@ -216,7 +220,7 @@ apply)\n \tapply_stash \"$@\"\n \t;;\n clear)\n-\tclear_stash\n+\tclear_stash \"$@\"\n \t;;\n create)\n \tif test $# -gt 0 && test \"$1\" = create\n"},{"id":"64522","messageId":"20080105100028.GB31220@coredump.intra.peff.net","threadId":"11479","inReplyTo":"7vy7b4bon9.fsf_-_@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-stash clear: refuse to work with extra parameter for now","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-05T10:00:28Z","receivedAt":"2008-01-05T10:00:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jan 05, 2008 at 01:35:54AM -0800, Junio C Hamano wrote:\n\n> I think something along this line may be necessary to\n> futureproof our users. \n\nI think it not only futureproofs, but it helps those who misunderstand\n(or don't read) the documentation from accidentally losing work.\n\nAcked-by: Jeff King <peff@peff.net>\n\n-Peff\n"},{"id":"64528","messageId":"e5bfff550801050436k61760cv9cf5c04c537907d6@mail.gmail.com","threadId":"11479","inReplyTo":"477EDDD4.5060509@nrlssc.navy.mil","subject":"Re: [PATCH] git-stash: add new 'drop' subcommand","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-05T12:36:25Z","receivedAt":"2008-01-05T12:36:25Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On Jan 5, 2008 2:31 AM, Brandon Casey <casey@nrlssc.navy.mil> wrote:\n>\n>\n> +drop_stash () {\n> +       if ! have_stash\n> +       then\n> +               echo >&2 'No stash entries to drop'\n> +               exit 0\n> +       fi\n\nPlease, or\n\n> +               echo >&2 'No stash entries to drop'\n> +               exit 1\n\nor\n\n> +               echo 'No stash entries to drop'\n> +               exit 0\n\nI would prefer the latter.\n\nThanks\nMarco\n"}]}