summaryrefslogtreecommitdiff
path: root/git-stash.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-07-07 13:38:06 -0700
committerJunio C Hamano <gitster@pobox.com>2007-07-07 13:38:06 -0700
commit6abe0f0383a9b77266810df0d1109b6d0783906e (patch)
treefbc1100c5d30e4a496fb1513017cb666fa371547 /git-stash.sh
parente3c76dbd0f7531eaed3ca8ec0000f03499839304 (diff)
parent150937c42591b0e9fb6c17f96c459d57b5f3bfdb (diff)
downloadgit-6abe0f0383a9b77266810df0d1109b6d0783906e.tar.gz
Merge branch 'js/stash'
* js/stash: Teach git-stash to "apply --index"
Diffstat (limited to 'git-stash.sh')
-rwxr-xr-xgit-stash.sh21
1 files changed, 20 insertions, 1 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 7b1638c68c..eac5551380 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -112,6 +112,13 @@ apply_stash () {
git diff-files --quiet ||
die 'Cannot restore on top of a dirty state'
+ unstash_index=
+ case "$1" in
+ --index)
+ unstash_index=t
+ shift
+ esac
+
# current index state
c_tree=$(git write-tree) ||
die 'Cannot apply a stash in the middle of a merge'
@@ -121,6 +128,15 @@ apply_stash () {
b_tree=$(git rev-parse --verify "$s^:") ||
die "$*: no valid stashed state found"
+ test -z "$unstash_index" || {
+ git diff --binary $s^2^..$s^2 | git apply --cached
+ test $? -ne 0 &&
+ die 'Conflicts in index. Try without --index.'
+ unstashed_index_tree=$(git-write-tree) ||
+ die 'Could not save index tree'
+ git reset
+ }
+
eval "
GITHEAD_$w_tree='Stashed changes' &&
GITHEAD_$c_tree='Updated upstream' &&
@@ -138,9 +154,12 @@ apply_stash () {
die "Cannot unstage modified files"
git-status
rm -f "$a"
+ test -z "$unstash_index" || git read-tree $unstashed_index_tree
else
# Merge conflict; keep the exit status from merge-recursive
- exit
+ status=$?
+ test -z "$unstash_index" || echo 'Index was not unstashed.' >&2
+ exit $status
fi
}