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

[PATCH 2/1] stash: recognize "--help" for subcommands

From
Jeff King <peff@peff.net>
Date
May 20, 2015, 18:17 UTC
Message-ID
<20150520181746.GC14561@peff.net>
In-Reply-To
<20150520180132.GB14561@peff.net>
On Wed, May 20, 2015 at 02:01:32PM -0400, Jeff King wrote:
> This takes away the immediate pain. We may also want to
> teach "--help" to the option. I guess we cannot do better
> than just having it run "git help stash" in all cases (i.e.,
> we have no way to get the help for a specific subcommand).
That actually turns out to be pretty painless...
-- >* --
Subject: stash: recognize "--help" for subcommands

If you run "git stash --help", you get the help for stash (this magic is done by the git wrapper itself). But if you run "git stash drop --help", you get an error. We cannot show help specific to "stash drop", of course, but we can at least give the user the normal stash manpage.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-stash.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/git-stash.sh b/git-stash.sh
index c6f492c..1f5ea87 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -219,6 +219,9 @@ save_stash () {
 		-a|--all)
 			untracked=all
 			;;
+		--help)
+			show_help
+			;;
 		--)
 			shift
 			break
@@ -307,6 +310,11 @@ show_stash () {
 	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}
@@ -373,6 +381,9 @@ parse_flags_and_rev()
 			--index)
 				INDEX_OPTION=--index
 			;;
+			--help)
+				show_help
+			;;
 			-*)
 				test "$ALLOW_UNKNOWN_FLAGS" = t ||
 					die "$(eval_gettext "unknown option: \$opt")"
-- 
2.4.1.396.g7ba6d7b
Previous: Jeff KingNext: Vincent Legoll
Message 3 of 5 in “[BUG, RFC] git stash drop --help”
  1. Vincent LegollMay 20, 2015
  2. stash: complain about unknown flagsJeff King, May 20, 2015
  3. 2/1 stash: recognize "--help" for subcommandsJeff King, May 20, 2015
  4. Vincent LegollNov 1, 2015
  5. Vincent LegollNov 1, 2015

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.