From: Junio C Hamano Date: Tue, 19 May 2015 20:17:52 +0000 (-0700) Subject: Merge branch 'jk/stash-require-clean-index' X-Git-Tag: v2.5.0-rc0~113 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/05c39674f35f33b6d2311da6c63268b9e7739840?hp=-c Merge branch 'jk/stash-require-clean-index' "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 --- 05c39674f35f33b6d2311da6c63268b9e7739840 diff --combined git-stash.sh index 6846b18dbc,cc28368b01..7911f30c63 --- a/git-stash.sh +++ b/git-stash.sh @@@ -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) ||