Re: stash --dwim safety

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: stash --dwim safety

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:47:20

Junio C Hamano [off-list ref] writes:
It turns out that the rework was simple enough, so I did it myself.  Among
his 3 patch series, an equivalent to the first one ("save -keep" can be
written as "save -k" for brevity) were already in, and the second one
(default to "save" if we see any option before command word) was unsafe
without the third one (reject unknown option to "save"), so it ended up as
a single patch that is a combination of the latter two patches.
Thanks, lack of time on my side to work on this, sorry.

I was actually thinking of being a little more paranoid to prevent
accidental "stash save": we could refuse to create a named stash when
the "save" command is not given. The case I hadn't thought of was "git
stash -q apply", which has 99% chances of being a typo for "git stash
apply -q", and which would mean "create a stash named apply, quietly".
+# The default command is "save"
+case "$1" in
+-*)
+	set "save" "$@"
+	;;
+esac
So, that could become something like

default_to_save=t
for arg in "$@"; do
	case "$arg" in
	-*)
		;;
	*)
		default_to_save=
	esac
done

if [ "$default_to_save" = t ]; then
	set "save" "$@"
fi

(untested)

-- 
Matthieu

Re: stash --dwim safety

From: Jeff King <hidden>
Date: 2016-06-15 22:47:20

On Tue, Sep 01, 2009 at 08:27:20AM +0200, Matthieu Moy wrote:
I was actually thinking of being a little more paranoid to prevent
accidental "stash save": we could refuse to create a named stash when
the "save" command is not given. The case I hadn't thought of was "git
stash -q apply", which has 99% chances of being a typo for "git stash
apply -q", and which would mean "create a stash named apply, quietly".
I like that. I think it addresses Dscho's concern with mistakes causing
an unexpected stash, and it is actually more consistent with the current
rule (that named stashes need an explicit 'save'). IOW, it is actually a
bit confusing that "git stash foo" doesn't work, but "git stash -k foo"
does.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help