Code

Don't dereference NULL upon lookup failure.
[git.git] / git-stash.sh
index dd155568d96771b2dcd62ecae0cc2c050169bf52..06cb177ec6c10d21f128390edc5bfedfa05db9a9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi
 
-USAGE='[ | list | show | apply | clear]'
+USAGE='[  | save | list | show | apply | clear | create ]'
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
@@ -15,7 +15,7 @@ trap 'rm -f "$TMP-*"' 0
 ref_stash=refs/stash
 
 no_changes () {
-       git diff-index --quiet --cached HEAD &&
+       git diff-index --quiet --cached HEAD -- &&
        git diff-files --quiet
 }
 
@@ -99,7 +99,7 @@ save_stash () {
 
        git update-ref -m "$stash_msg" $ref_stash $w_commit ||
                die "Cannot save the current status"
-       printf >&2 'Saved "%s"\n' "$stash_msg"
+       printf >&2 'Saved working directory and index state "%s"\n' "$stash_msg"
 }
 
 have_stash () {
@@ -207,6 +207,10 @@ show)
        shift
        show_stash "$@"
        ;;
+save)
+       shift
+       save_stash "$*" && git-reset --hard
+       ;;
 apply)
        shift
        apply_stash "$@"
@@ -221,14 +225,14 @@ create)
        fi
        create_stash "$*" && echo "$w_commit"
        ;;
-help | usage)
-       usage
-       ;;
 *)
-       if test $# -gt 0 && test "$1" = save
+       if test $# -eq 0
        then
-               shift
+               save_stash &&
+               echo >&2 '(To restore them type "git stash apply")' &&
+               git-reset --hard
+       else
+               usage
        fi
-       save_stash "$*" && git-reset --hard
        ;;
 esac