threads / discuss / 33019

Better handling of erroneous git stash save "somemessage" --keep-index

Subject: Better handling of erroneous git stash save "somemessage" --keep-index

## tl;dr

5 messages between Feb 26, 2013 and Feb 26, 2013.

replies: 4people: 3as markdown or json

Gunnlaugur Thor Briem· Feb 26, 2013, 15:59 UTC · lore
Hi,
the command:
git stash save "some message" --keep-index

stashes everything, including the index, and adds the "--keep-index" to the message. The manual labor of separating index hunks from hunks to stash is lost. This is in version 1.8.1.3.

This is a user error, of course (per the man page, parameters are not accepted after the message). But it would be better handled by erroring out, with a message like "git stash save does not permit parameters after the stash message".

Cheers,
Gulli
Junio C Hamano· Feb 26, 2013, 16:10 UTC · re: Gunnlaugur Thor Briem · lore

Re: Better handling of erroneous git stash save "somemessage" --keep-index

Gunnlaugur Thor Briem <gunnlaugur@gmail.com> writes:
Show 12 quoted lines
> the command:
>
> git stash save "some message" --keep-index
>
> stashes everything, including the index, and adds the "--keep-index"
> to the message. The manual labor of separating index hunks from hunks
> to stash is lost. This is in version 1.8.1.3.
>
> This is a user error, of course (per the man page, parameters are not
> accepted after the message). But it would be better handled by
> erroring out, with a message like "git stash save does not permit
> parameters after the stash message".
Then the user cannot say
	git stash save some message that consists of multiple words

no? You may have a WIP to enhance the behaviour of one option and you might want to say

	git stash save wip: tweak behaviour of --keep-index
to save it away when switching to higher priority task.
Matthieu Moy· Feb 26, 2013, 16:21 UTC · re: Junio C Hamano · lore

Re: Better handling of erroneous git stash save "somemessage" --keep-index

Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> Gunnlaugur Thor Briem <gunnlaugur@gmail.com> writes:
>
>> the command:
>>
>> git stash save "some message" --keep-index
>>
>> stashes everything, including the index, and adds the "--keep-index"
>> to the message. The manual labor of separating index hunks from hunks
>> to stash is lost. This is in version 1.8.1.3.

Not lost, it's saved as part of the stash. "git stash pop --index" will restore it.

Show 10 quoted lines
>> This is a user error, of course (per the man page, parameters are not
>> accepted after the message). But it would be better handled by
>> erroring out, with a message like "git stash save does not permit
>> parameters after the stash message".
>
> Then the user cannot say
>
> 	git stash save some message that consists of multiple words
>
> no?

I didn't even know that multi-words messages would be allowed this way. That seems to me to be really weird indeed.

I can't say
  git commit -m multi word message

so why would people want to omit quotes for "git stash" is a total mystery. That said, we can't deny it right now, to preserve backward compatibility.

My feeling is that "git stash save" should learn a "-m, --message" option analogous to the one of "git commit", and then the "message on the command-line" syntax could be deprecated.

(One nice side effect would be that in the very long term, we may want to allow "git stash save -- <pathspecs>" to do a limited stash)

But maybe it's not worth the effort, I don't know.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Junio C Hamano· Feb 26, 2013, 17:00 UTC · re: Matthieu Moy · lore

Re: Better handling of erroneous git stash save "somemessage" --keep-index

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> I didn't even know that multi-words messages would be allowed this way.
> That seems to me to be really weird indeed.

Yeah, but it is understandable why it was done that way, considering taht the whole point of "stash" is to save away quickly for higher priority interrupt. IIRC, earlier iterations of the command did not even require you to say "save", i.e.

	git stash wip: futzing with --keep-index
would have been a perfectly good invocation.
Show 8 quoted lines
> My feeling is that "git stash save" should learn a "-m, --message"
> option analogous to the one of "git commit", and then the "message on
> the command-line" syntax could be deprecated.
>
> (One nice side effect would be that in the very long term, we may want
> to allow "git stash save -- <pathspecs>" to do a limited stash)
>
> But maybe it's not worth the effort, I don't know.
Yeah, if the user wants to be more elaborate perhaps
	git checkout -b temp
        git commit -m 'whatever message' -a
	git checkout -

would suffice; "stash" is for smaller changes in a very tentative nature that do not deserve such a long command sequence, so requiring "-m" may make the command less useful.

Gunnlaugur Thor Briem· Feb 26, 2013, 16:46 UTC · re: Junio C Hamano · lore

Re: Better handling of erroneous git stash save "somemessage" --keep-index

On Tue, Feb 26, 2013 at 4:10 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> Then the user cannot say
>
>         git stash save some message that consists of multiple words
>
> no?  You may have a WIP to enhance the behaviour of one option and
> you might want to say
>
>         git stash save wip: tweak behaviour of --keep-index
>
> to save it away when switching to higher priority task.

In this case (which must be rarer than --keep-index intended as a parameter) the user gets the error message, the problem is pretty clear, and the workaround is very easy, quote the message:

        git stash save "wip: tweak behaviour of --keep-index"
... which also is more conventional on the command line.

To minimize the behavior change, it could apply solely for the case of known parameters to this command (like --keep-index), so that:

        git stash save wip: tweak behaviour of --froob-nob

would still work like before. That's less consistent, but then again, this is just a matter of catching very likely errors to avoid lost work.

Expressing a multi-word message without quotes on the command line is unconventional (in general, though maybe not in the use of git-stash) so it seems reasonable to let that usage be the one that gets inconvenienced.

-Gulli
(Sorry about the initial reply to you alone Junio)

← back to recent threads