git-svn: wrap long lines in a few places
[gitweb.git] / git-stash.sh
index 92531a2951ea29d3a826ad162e709f8701b14bac..5ad2c4b7a33cf1be24ee85f17c8738ca05b98db0 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi
 
-USAGE='[  | save | list | show | apply | clear | drop | pop | create ]'
+USAGE='[  | save | list | show | apply | clear | drop | pop | create | branch ]'
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
@@ -93,7 +93,7 @@ save_stash () {
                shift
        esac
 
-       stash_msg="$1"
+       stash_msg="$*"
 
        if no_changes
        then
@@ -233,6 +233,23 @@ drop_stash () {
        git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
 }
 
+apply_to_branch () {
+       have_stash || die 'Nothing to apply'
+
+       test -n "$1" || die 'No branch name specified'
+       branch=$1
+
+       if test -z "$2"
+       then
+               set x "$ref_stash@{0}"
+       fi
+       stash=$2
+
+       git-checkout -b $branch $stash^ &&
+       apply_stash --index $stash &&
+       drop_stash $stash
+}
+
 # Main command set
 case "$1" in
 list)
@@ -250,7 +267,7 @@ show)
        ;;
 save)
        shift
-       save_stash "$*"
+       save_stash "$@"
        ;;
 apply)
        shift
@@ -279,6 +296,10 @@ pop)
                drop_stash "$@"
        fi
        ;;
+branch)
+       shift
+       apply_to_branch "$@"
+       ;;
 *)
        if test $# -eq 0
        then