Merge branch 'jk/stash-require-clean-index'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2015 20:17:52 +0000 (13:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2015 20:17:52 +0000 (13:17 -0700)
"git stash pop/apply" forgot to make sure that not just the working
tree is clean but also the index is clean. The latter is important
as a stash application can conflict and the index will be used for
conflict resolution.

* jk/stash-require-clean-index:
stash: require a clean index to apply
t3903: avoid applying onto dirty index
t3903: stop hard-coding commit sha1s

1  2 
git-stash.sh
diff --combined git-stash.sh
index 6846b18dbc007a8b08c6f5a77fe568fb8625c28f,cc28368b01fc218f32ae98c21cce4d7f84c68eb0..7911f30c631fe58d6e5655f5213cae4e72ef99e1
@@@ -20,7 -20,7 +20,7 @@@ require_work_tre
  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 +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 &&
@@@ -259,7 -259,7 +259,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
@@@ -442,6 -442,8 +442,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) ||