summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-06-16 14:33:43 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-06-16 14:33:43 -0700
commit659d4c8fb21902660acd52f9e77170e82774b9ff (patch)
tree394f52a2b8ef5bdbc867cefe13c264e407798b87
parentMerge branch 'mm/log-format-raw-doc' into maint (diff)
parentstash: recognize "--help" for subcommands (diff)
downloadtgif-659d4c8fb21902660acd52f9e77170e82774b9ff.tar.xz
Merge branch 'jk/stash-options' into maint
Make "git stash something --help" error out, so that users can safely say "git stash drop --help". * jk/stash-options: stash: recognize "--help" for subcommands stash: complain about unknown flags
-rwxr-xr-xgit-stash.sh17
-rwxr-xr-xt/t3903-stash.sh4
2 files changed, 20 insertions, 1 deletions
diff --git a/git-stash.sh b/git-stash.sh
index cc28368b01..0fddd5424b 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -219,6 +219,9 @@ save_stash () {
-a|--all)
untracked=all
;;
+ --help)
+ show_help
+ ;;
--)
shift
break
@@ -301,11 +304,17 @@ list_stash () {
}
show_stash () {
+ ALLOW_UNKNOWN_FLAGS=t
assert_stash_like "$@"
git diff ${FLAGS:---stat} $b_commit $w_commit
}
+show_help () {
+ exec git help stash
+ exit 1
+}
+
#
# Parses the remaining options looking for flags and
# at most one revision defaulting to ${ref_stash}@{0}
@@ -332,13 +341,14 @@ show_stash () {
#
# GIT_QUIET is set to t if -q is specified
# INDEX_OPTION is set to --index if --index is specified.
-# FLAGS is set to the remaining flags
+# FLAGS is set to the remaining flags (if allowed)
#
# dies if:
# * too many revisions specified
# * no revision is specified and there is no stash stack
# * a revision is specified which cannot be resolve to a SHA1
# * a non-existent stash reference is specified
+# * unknown flags were set and ALLOW_UNKNOWN_FLAGS is not "t"
#
parse_flags_and_rev()
@@ -371,7 +381,12 @@ parse_flags_and_rev()
--index)
INDEX_OPTION=--index
;;
+ --help)
+ show_help
+ ;;
-*)
+ test "$ALLOW_UNKNOWN_FLAGS" = t ||
+ die "$(eval_gettext "unknown option: \$opt")"
FLAGS="${FLAGS}${FLAGS:+ }$opt"
;;
esac
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 0746eeeff7..7396ca9911 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -100,6 +100,10 @@ test_expect_success 'unstashing in a subdirectory' '
)
'
+test_expect_success 'stash drop complains of extra options' '
+ test_must_fail git stash drop --foo
+'
+
test_expect_success 'drop top stash' '
git reset --hard &&
git stash list > stashlist1 &&