aboutsummaryrefslogtreecommitdiff
path: root/git-stash.sh
diff options
context:
space:
mode:
authorNicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>2017-08-11 19:14:43 +0200
committerJunio C Hamano <gitster@pobox.com>2017-08-11 15:11:30 -0700
commitbbffd87d3223b2f5782918eab2e011931bdffdcc (patch)
tree40778074d3005a0839646e54ac5d5c15d220befc /git-stash.sh
parent4274c698f46a9bc45834c4904e7e113450c042fb (diff)
downloadgit-bbffd87d3223b2f5782918eab2e011931bdffdcc.tar.gz
git-bbffd87d3223b2f5782918eab2e011931bdffdcc.tar.xz
stash: clean untracked files before reset
If calling git stash -u on a repo that contains a file that is not ignored any more due to a current modification of the gitignore file, this file is stashed but not remove from the working tree. This is due to git-stash first doing a reset --hard which clears the .gitignore file modification and the call git clean, leaving the file untouched. This causes git stash pop to fail due to the file existing. This patch simply switches the order between cleaning and resetting and adds a test for this usecase. Reported-by: Sam Partington <sam@whiteoctober.co.uk> Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-stash.sh')
-rwxr-xr-xgit-stash.sh11
1 files changed, 6 insertions, 5 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 9b6c2da7b..39083b4d9 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -300,6 +300,12 @@ push_stash () {
if test -z "$patch_mode"
then
+ test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
+ if test -n "$untracked"
+ then
+ git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
+ fi
+
if test $# != 0
then
git reset -q -- "$@"
@@ -309,11 +315,6 @@ push_stash () {
else
git reset --hard -q
fi
- test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
- if test -n "$untracked"
- then
- git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
- fi
if test "$keep_index" = "t" && test -n "$i_tree"
then