git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-stash: add new 'drop' subcommand

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2008, 01:47 UTC
Message-ID
<7vtzltf3gg.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<477EDDD4.5060509@nrlssc.navy.mil>
Brandon Casey <casey@nrlssc.navy.mil> writes:
> I'm not sure if there is a proper way to get 'stash@{0}' from
> 'refs/stash' so I kept my usage of that former string outside
> of the drop_stash() function.

Doesn't "$refs_stash@{0}" (which would give refs/stash@{0} not stash@{0}) work for you?

Show 10 quoted lines
> diff --git a/git-stash.sh b/git-stash.sh
> index 06cb177..a789a53 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -1,7 +1,7 @@
>  #!/bin/sh
>  # Copyright (c) 2007, Nanako Shiraishi
>  
> -USAGE='[  | save | list | show | apply | clear | create ]'
> +USAGE='[  | save | list | show | apply | clear | create | drop ]'
Might want to put drop next to clear, but that is minor.
Show 15 quoted lines
> +drop_stash () {
> +	if ! have_stash
> +	then
> +		echo >&2 'No stash entries to drop'
> +		exit 0
> +	fi
> +
> +	# Verify supplied argument looks like a stash entry
> +	s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@") &&
> +	git rev-parse --verify "$s:"   > /dev/null 2>&1 &&
> +	git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
> +	git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
> +		die "$*: not a valid stashed state"
> +
> +	git reflog delete "$@" && echo "Dropped $@ ($s)" ||
The second $@ is inconsistent with the next line's use of $*; intentional?
> +		die "$*: Could not drop stash entry"
> +}
Show 8 quoted lines
> +drop)
> +	shift
> +	if test $# = 0
> +	then
> +		set -- "stash@{0}"
> +	fi
> +	drop_stash "$@" &&
> +	(git rev-parse --verify "stash@{0}" > /dev/null 2>&1 || clear_stash)
Curious.
 (1) Why not do the clearing inside drop_stash?
 (2) Why is clearning necessary in the first place (iow,
     shouldn't "reflog delete" take care of that)?
Other than that, nicely done.
Previous: Brandon CaseyNext: Brandon Casey
Message 2 of 8 in “git-stash: add new 'drop' subcommand”
  1. git-stash: add new 'drop' subcommandBrandon Casey, Jan 5, 2008
  2. Junio C HamanoJan 5, 2008
  3. Brandon CaseyJan 5, 2008
  4. Jeff KingJan 5, 2008
  5. JM IbanezJan 5, 2008
  6. git-stash clear: refuse to work with extra parameter for nowJunio C Hamano, Jan 5, 2008
  7. Jeff KingJan 5, 2008
  8. Marco CostalbaJan 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.