# [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands

6 messages from 2007-12-03 to 2007-12-04. Participants: Kevin Leung, Junio C Hamano, Wayne Davison, Johannes Schindelin.
Thread: https://gitlist.dev/t/11106

## Kevin Leung, 2007-12-03 02:34

Subject: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <e66701d40712021834h64bf8d0y14f0e222d0f9a617@mail.gmail.com>
URL: https://gitlist.dev/e/e66701d40712021834h64bf8d0y14f0e222d0f9a617%40mail.gmail.com

```
The current git-stash behaviour is very error prone to typos. For example,
if you typed "git-stash llist", git-stash would think that you wanted to
save to a stash named "llist", but in fact, you meant "git-stash list".

Signed-off-by: Kevin Leung <kevinlsk@gmail.com>
---
 git-stash.sh |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 77c9421..a17cc25 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi

-USAGE='[ | list | show | apply | clear]'
+USAGE='[  | save | list | show | apply | clear ]'

 SUBDIRECTORY_OK=Yes
 . git-sh-setup
@@ -195,6 +195,10 @@ show)
        shift
        show_stash "$@"
        ;;
+save)
+       shift
+       save_stash "$@" && git-reset --hard
+       ;;
 apply)
        shift
        apply_stash "$@"
@@ -202,14 +206,12 @@ apply)
 clear)
        clear_stash
        ;;
-help | usage)
-       usage
-       ;;
 *)
-       if test $# -gt 0 && test "$1" = save
+       if test "$#" -eq "0"
        then
-               shift
+               save_stash && git-reset --hard
+       else
+               usage
        fi
-       save_stash "$*" && git-reset --hard
        ;;
 esac
-- 
1.5.3.7-dirty

```

## Junio C Hamano, 2007-12-03 02:48

Subject: Re: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <7vwsrwqysf.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwsrwqysf.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <e66701d40712021834h64bf8d0y14f0e222d0f9a617@mail.gmail.com>

```
"Kevin Leung" <kevinlsk@gmail.com> writes:

> The current git-stash behaviour is very error prone to typos. For example,
> if you typed "git-stash llist", git-stash would think that you wanted to
> save to a stash named "llist", but in fact, you meant "git-stash list".
>
> Signed-off-by: Kevin Leung <kevinlsk@gmail.com>

Thanks.  Looks good.  except...

> @@ -195,6 +195,10 @@ show)
>         shift
>         show_stash "$@"
>         ;;
> +save)
> +       shift
> +       save_stash "$@" && git-reset --hard
> +       ;;

... this should be "$*" as it was originally spelled.

Save this script in foo.sh and run "foo.sh a b c" to see what I mean.

#!/bin/sh

foo () {
	msg="$1"
	echo "Foo here <$1>"
}

foo "$@"
foo "$*"

```

## Kevin Leung, 2007-12-03 03:36

Subject: Re: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <e66701d40712021936p10ee73ddj9696d3a8b4092127@mail.gmail.com>
URL: https://gitlist.dev/e/e66701d40712021936p10ee73ddj9696d3a8b4092127%40mail.gmail.com
In-Reply-To: <7vwsrwqysf.fsf@gitster.siamese.dyndns.org>

```
The current git-stash behaviour is very error prone to typos. For example,
if you typed "git-stash llist", git-stash would think that you wanted to
save to a stash named "llist", but in fact, you meant "git-stash list".

Signed-off-by: Kevin Leung <kevinlsk@gmail.com>
---

 Thanks, Junio. It should be alright now.

 git-stash.sh |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 77c9421..844a3e5 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi

-USAGE='[ | list | show | apply | clear]'
+USAGE='[  | save | list | show | apply | clear ]'

 SUBDIRECTORY_OK=Yes
 . git-sh-setup
@@ -195,6 +195,10 @@ show)
        shift
        show_stash "$@"
        ;;
+save)
+       shift
+       save_stash "$*" && git-reset --hard
+       ;;
 apply)
        shift
        apply_stash "$@"
@@ -202,14 +206,12 @@ apply)
 clear)
        clear_stash
        ;;
-help | usage)
-       usage
-       ;;
 *)
-       if test $# -gt 0 && test "$1" = save
+       if test "$#" -eq "0"
        then
-               shift
+               save_stash && git-reset --hard
+       else
+               usage
        fi
-       save_stash "$*" && git-reset --hard
        ;;
 esac
-- 
1.5.3.7-dirty

```

## Wayne Davison, 2007-12-03 06:16

Subject: Re: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <20071203061617.GB1976@blorf.net>
URL: https://gitlist.dev/e/20071203061617.GB1976%40blorf.net
In-Reply-To: <e66701d40712021834h64bf8d0y14f0e222d0f9a617@mail.gmail.com>

```
On Mon, Dec 03, 2007 at 10:34:05AM +0800, Kevin Leung wrote:
> +USAGE='[  | save | list | show | apply | clear ]'

It seems strange to me that git stash is using sub-sub-command words
instead of options.  Would it make more sense to be more like git branch
and have a list be indicated by -l, etc.?

..wayne..

```

## Johannes Schindelin, 2007-12-03 10:25

Subject: Re: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <Pine.LNX.4.64.0712031023480.27959@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0712031023480.27959%40racer.site
In-Reply-To: <20071203061617.GB1976@blorf.net>

```
Hi,

On Sun, 2 Dec 2007, Wayne Davison wrote:

> On Mon, Dec 03, 2007 at 10:34:05AM +0800, Kevin Leung wrote:
> > +USAGE='[  | save | list | show | apply | clear ]'
> 
> It seems strange to me that git stash is using sub-sub-command words 
> instead of options.  Would it make more sense to be more like git branch 
> and have a list be indicated by -l, etc.?

But those are not really options, are they?  They are commands, which 
exclude each other.  And even if they are sub-sub-commands, why should we 
not rather fix "git branch" to support a sane syntax, too?

We could even put some general support into parse-options.[ch] for 
sub-commands.

Ciao,
Dscho

```

## Wayne Davison, 2007-12-04 15:28

Subject: Re: [PATCH] git-stash: Display help message if git-stash is run with wrong sub-commands
Message-ID: <20071204152827.GB24201@blorf.net>
URL: https://gitlist.dev/e/20071204152827.GB24201%40blorf.net
In-Reply-To: <Pine.LNX.4.64.0712031023480.27959@racer.site>

```
On Mon, Dec 03, 2007 at 10:25:17AM +0000, Johannes Schindelin wrote:
> But those are not really options, are they?  They are commands, which 
> exclude each other.

Option syntax is often used to represent exclusive commands, especially
when those commands need to be distinguished from free-form arg words.
The "git checkout" command is another example of this in git, and there
are plenty of non-git examples of such a use of option syntax around.
Such a syntax makes it easier to have a default action while still
taking a free-form arg.  I personally think that using option syntax
for its behavior choices would be preferable with git stash.

..wayne..

```
