]> git.ipfire.org Git - thirdparty/git.git/commit - t/t3903-stash.sh
stash: eliminate crude option parsing
authorAlexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Mon, 17 Feb 2020 17:25:21 +0000 (17:25 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Feb 2020 18:56:49 +0000 (10:56 -0800)
commit8c3713cede71e4741dac546f787734627329f55b
tree41eddf353ac3f6cbeca3e81c86536278712cb58a
parent3f3d8068f577ccbf11a9343fbfec3b7c679a6772
stash: eliminate crude option parsing

Eliminate crude option parsing and rely on real parsing instead, because
1) Crude parsing is crude, for example it's not capable of
   handling things like `git stash -m Message`
2) Adding options in two places is inconvenient and prone to bugs

As a side result, the case of `git stash -m Message` gets fixed.
Also give a good error message instead of just throwing usage at user.

----

Some review of what's been happening to this code:

Before [1], `git-stash.sh` only verified that all args begin with `-` :

# The default command is "push" if nothing but options are given
seen_non_option=
for opt
do
case "$opt" in
--) break ;;
-*) ;;
*) seen_non_option=t; break ;;
esac
done

Later, [1] introduced the duplicate code I'm now removing, also making
the previous test more strict by white-listing options.

----

[1] Commit 40af1468 ("stash: convert `stash--helper.c` into `stash.c`" 2019-02-26)

Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/stash.c
t/t3903-stash.sh