Code

xdiff-interface.c: strip newline (and cr) from line before pattern matching
[git.git] / git-stash.sh
index e4cb6c3e4bef5a714ff245624503a004d3c293e3..42f626f9d555f26f3e50441c0ab27de5cac19bf4 100755 (executable)
@@ -1,7 +1,13 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi
 
-USAGE='[  | save | list | show | apply | clear | drop | pop | create ]'
+dashless=$(basename "$0" | sed -e 's/-/ /')
+USAGE="list [<options>]
+   or: $dashless (show | drop | pop ) [<stash>]
+   or: $dashless apply [--index] [<stash>]
+   or: $dashless branch <branchname> [<stash>]
+   or: $dashless [save [--keep-index] [<message>]]
+   or: $dashless clear"
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
@@ -33,6 +39,7 @@ clear_stash () {
 create_stash () {
        stash_msg="$1"
 
+       git update-index -q --refresh
        if no_changes
        then
                exit 0
@@ -93,8 +100,9 @@ save_stash () {
                shift
        esac
 
-       stash_msg="$1"
+       stash_msg="$*"
 
+       git update-index -q --refresh
        if no_changes
        then
                echo 'No local changes to save'
@@ -136,7 +144,14 @@ show_stash () {
        then
                flags=--stat
        fi
-       s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@")
+
+       if test $# = 0
+       then
+               set x "$ref_stash@{0}"
+               shift
+       fi
+
+       s=$(git rev-parse --revs-only --no-flags "$@")
 
        w_commit=$(git rev-parse --verify "$s") &&
        b_commit=$(git rev-parse --verify "$s^") &&
@@ -144,8 +159,9 @@ show_stash () {
 }
 
 apply_stash () {
+       git update-index -q --refresh &&
        git diff-files --quiet --ignore-submodules ||
-               die 'Cannot restore on top of a dirty state'
+               die 'Cannot apply to a dirty working tree, please stage your changes'
 
        unstash_index=
        case "$1" in
@@ -154,13 +170,19 @@ apply_stash () {
                shift
        esac
 
+       if test $# = 0
+       then
+               set x "$ref_stash@{0}"
+               shift
+       fi
+
        # current index state
        c_tree=$(git write-tree) ||
                die 'Cannot apply a stash in the middle of a merge'
 
        # stash records the work tree, and is a merge between the
        # base commit (first parent) and the index tree (second parent).
-       s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@") &&
+       s=$(git rev-parse --revs-only --no-flags "$@") &&
        w_tree=$(git rev-parse --verify "$s:") &&
        b_tree=$(git rev-parse --verify "$s^1:") &&
        i_tree=$(git rev-parse --verify "$s^2:") ||
@@ -267,7 +289,7 @@ show)
        ;;
 save)
        shift
-       save_stash "$*"
+       save_stash "$@"
        ;;
 apply)
        shift