Merge branch 'ld/p4-editor-multi-words'
[gitweb.git] / git-stash.sh
index f540127da3b211250c7a09451726edada71ba8f1..1f5ea877d719715760d42a3ee1d0950a1adaf9fc 100755 (executable)
@@ -20,7 +20,7 @@ require_work_tree
 cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
-TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$
+TMPindex=${GIT_INDEX_FILE-"$(git rev-parse --git-path index)"}.stash.$$
 trap 'rm -f "$TMP-"* "$TMPindex"' 0
 
 ref_stash=refs/stash
@@ -184,7 +184,7 @@ store_stash () {
        fi
 
        # Make sure the reflog for stash is kept.
-       : >>"$GIT_DIR/logs/$ref_stash"
+       : >>"$(git rev-parse --git-path logs/$ref_stash)"
        git update-ref -m "$stash_msg" $ref_stash $w_commit
        ret=$?
        test $ret != 0 && test -z $quiet &&
@@ -219,6 +219,9 @@ save_stash () {
                -a|--all)
                        untracked=all
                        ;;
+               --help)
+                       show_help
+                       ;;
                --)
                        shift
                        break
@@ -259,7 +262,7 @@ save_stash () {
                say "$(gettext "No local changes to save")"
                exit 0
        fi
-       test -f "$GIT_DIR/logs/$ref_stash" ||
+       test -f "$(git rev-parse --git-path logs/$ref_stash)" ||
                clear_stash || die "$(gettext "Cannot initialize stash")"
 
        create_stash "$stash_msg" $untracked
@@ -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")"
@@ -446,6 +457,8 @@ apply_stash () {
        assert_stash_like "$@"
 
        git update-index -q --refresh || die "$(gettext "unable to refresh index")"
+       git diff-index --cached --quiet --ignore-submodules HEAD -- ||
+               die "$(gettext "Cannot apply stash: Your index contains uncommitted changes.")"
 
        # current index state
        c_tree=$(git write-tree) ||