fetch: work around "transport-take-over" hack
[gitweb.git] / git-stash.sh
index bbefdf64244063f4708f381b8a772466d64e90e5..85c9e2c0817c171d67f7458a0764df8d31fb10ad 100755 (executable)
@@ -156,10 +156,46 @@ create_stash () {
        die "$(gettext "Cannot record working tree state")"
 }
 
+store_stash () {
+       while test $# != 0
+       do
+               case "$1" in
+               -m|--message)
+                       shift
+                       stash_msg="$1"
+                       ;;
+               -q|--quiet)
+                       quiet=t
+                       ;;
+               *)
+                       break
+                       ;;
+               esac
+               shift
+       done
+       test $# = 1 ||
+       die "$(eval_gettext "\"$dashless store\" requires one <commit> argument")"
+
+       w_commit="$1"
+       if test -z "$stash_msg"
+       then
+               stash_msg="Created via \"git stash store\"."
+       fi
+
+       # Make sure the reflog for stash is kept.
+       : >>"$GIT_DIR/logs/$ref_stash"
+       git update-ref -m "$stash_msg" $ref_stash $w_commit
+       ret=$?
+       test $ret != 0 && test -z $quiet &&
+       die "$(eval_gettext "Cannot update \$ref_stash with \$w_commit")"
+       return $ret
+}
+
 save_stash () {
        keep_index=
        patch_mode=
        untracked=
+       force=
        while test $# != 0
        do
                case "$1" in
@@ -180,6 +216,9 @@ save_stash () {
                -u|--include-untracked)
                        untracked=untracked
                        ;;
+               -f|--force)
+                       force=t
+                       ;;
                -a|--all)
                        untracked=all
                        ;;
@@ -223,16 +262,20 @@ save_stash () {
                say "$(gettext "No local changes to save")"
                exit 0
        fi
+       if test -z "$untracked$force" &&
+          test -n "$(git ls-files --killed | head -n 1)"
+       then
+               say "$(gettext "The following untracked files would NOT be saved but need to be removed by stash save:")"
+               test -n "$GIT_QUIET" || git ls-files --killed | sed 's/^/\t/'
+               say "$(gettext "Aborting. Consider using either the --force or --include-untracked option.")" >&2
+               exit 1
+       fi
        test -f "$GIT_DIR/logs/$ref_stash" ||
                clear_stash || die "$(gettext "Cannot initialize stash")"
 
        create_stash "$stash_msg" $untracked
-
-       # Make sure the reflog for stash is kept.
-       : >>"$GIT_DIR/logs/$ref_stash"
-
-       git update-ref -m "$stash_msg" $ref_stash $w_commit ||
-               die "$(gettext "Cannot save the current status")"
+       store_stash -m "$stash_msg" -q $w_commit ||
+       die "$(gettext "Cannot save the current status")"
        say Saved working directory and index state "$stash_msg"
 
        if test -z "$patch_mode"
@@ -546,12 +589,13 @@ clear)
        clear_stash "$@"
        ;;
 create)
-       if test $# -gt 0 && test "$1" = create
-       then
-               shift
-       fi
+       shift
        create_stash "$*" && echo "$w_commit"
        ;;
+store)
+       shift
+       store_stash "$@"
+       ;;
 drop)
        shift
        drop_stash "$@"