aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-07-27 23:41:31 -0700
committerJunio C Hamano <gitster@pobox.com>2007-07-28 00:06:00 -0700
commitcbeaccc316affa2e0fb0b60f569d5da9bf444881 (patch)
treeba4eed2d1041ea5225b38ca3914e545f6d4c55da
parentf12e925ac23ad6169e046cfe05b8438a1611ad58 (diff)
downloadgit-cbeaccc316affa2e0fb0b60f569d5da9bf444881.tar.gz
git-cbeaccc316affa2e0fb0b60f569d5da9bf444881.tar.xz
Fix git-stash apply --index
Two bugs that made the command practically unusable were fixed with this. - A stash created with a clean index does not have any difference between the base tree and the index tree. Trying to apply the diff between them to the index would error out with "No changes". Even when the user asked to unstash with --index, do not bother with --index action if the base tree and the index tree match. - After successfully performing the working tree merge, the index was reloaded from an earlier state of unstashed index with "read-tree"; this left all the paths cache dirty. By moving the call to git-status after this read-tree, match the cached stat information in the index. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xgit-stash.sh23
1 files changed, 17 insertions, 6 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 0073e9df5..873e7be6a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -128,19 +128,24 @@ apply_stash () {
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 "$@") &&
w_tree=$(git rev-parse --verify "$s:") &&
- b_tree=$(git rev-parse --verify "$s^:") ||
+ b_tree=$(git rev-parse --verify "$s^1:") &&
+ i_tree=$(git rev-parse --verify "$s^2:") ||
die "$*: no valid stashed state found"
- test -z "$unstash_index" || {
+ unstashed_index_tree=
+ if test -n "$unstash_index" && test "$b_tree" != "$i_tree"
+ then
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
- }
+ fi
eval "
GITHEAD_$w_tree='Stashed changes' &&
@@ -157,13 +162,19 @@ apply_stash () {
git read-tree --reset $c_tree &&
git update-index --add --stdin <"$a" ||
die "Cannot unstage modified files"
- git-status
rm -f "$a"
- test -z "$unstash_index" || git read-tree $unstashed_index_tree
+ if test -n "$unstashed_index_tree"
+ then
+ git read-tree "$unstashed_index_tree"
+ fi
+ git status || :
else
# Merge conflict; keep the exit status from merge-recursive
status=$?
- test -z "$unstash_index" || echo 'Index was not unstashed.' >&2
+ if test -n "$unstash_index"
+ then
+ echo >&2 'Index was not unstashed.'
+ fi
exit $status
fi
}