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

Re: [RFC PATCH] stash: accept options also when subcommand 'save' is omitted

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 18, 2009, 13:01 UTC
Message-ID
<vpqws51l1hb.fsf@bauges.imag.fr>
In-Reply-To
<1250599567-31428-1-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
> This allows in particular 'git stash --keep-index' which is shorter than
> 'git stash save --keep-index', and not ambiguous.

Hmm, googling a bit, I just noticed that there's already something in pu: ea41cfc4f (Make 'git stash -k' a short form for 'git stash save --keep-index') which also does the trick, while adding a -k alias for --keep-index.

Not sure which hack is best between my
Show 6 quoted lines
> +case "$1" in
> +    -*)
> +	set "save" "$@"
> +	;;
> +esac
> +
And the proposed
 *)
-	if test $# -eq 0
-	then
-		save_stash &&
+	case $#,"$1" in
+	0,|1,-k|1,--keep-index)
+		save_stash "$@" &&
 		say '(To restore them type "git stash apply")'
-	else
+		;;
+	*)
 		usage
-	fi
+	esac
 	;;
 esac
Mine has at least two advantages:
* It won't require changing the code again when new options are added
  to 'git stash save'.
* It works with 'git stash -k -q' for example, while the other
  proposal checks that $# == 1, which won't work if there are more
  than one option.
But I may have missed its drawbacks ;-)

-- Matthieu

Previous: Matthieu MoyNext: Jeff King
Message 2 of 22 in “stash: accept options also when subcommand 'save' is omitted”
  1. stash: accept options also when subcommand 'save' is omittedMatthieu Moy, Aug 18, 2009
  2. Matthieu MoyAug 18, 2009
  3. Jeff KingAug 18, 2009
  4. Junio C HamanoAug 18, 2009
  5. 0/3 short syntaxes for 'git stash'Matthieu Moy, Aug 18, 2009
  6. 1/3 stash: accept -k as a shortcut for --keep-indexMatthieu Moy, Aug 18, 2009
  7. 2/3 stash: accept options also when subcommand 'save' is omittedMatthieu Moy, Aug 18, 2009
  8. 3/3 stash: reject stash name starting with a dash.Matthieu Moy, Aug 18, 2009
  9. Jeff KingAug 18, 2009
  10. Junio C HamanoAug 18, 2009
  11. Jeff KingAug 18, 2009
  12. Junio C HamanoAug 18, 2009
  13. Matthieu MoyAug 19, 2009
  14. Jeff KingAug 19, 2009
  15. Jeff KingAug 18, 2009
  16. Johannes SchindelinAug 18, 2009
  17. Matthieu MoyAug 18, 2009
  18. Johannes SchindelinAug 18, 2009
  19. Matthieu MoyAug 19, 2009
  20. Jeff KingAug 18, 2009
  21. Johannes SchindelinAug 18, 2009
  22. Jeff KingAug 18, 2009

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.