mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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>
This commit is contained in:
parent
4274c698f4
commit
bbffd87d32
11
git-stash.sh
11
git-stash.sh
|
@ -300,6 +300,12 @@ push_stash () {
|
||||||
|
|
||||||
if test -z "$patch_mode"
|
if test -z "$patch_mode"
|
||||||
then
|
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
|
if test $# != 0
|
||||||
then
|
then
|
||||||
git reset -q -- "$@"
|
git reset -q -- "$@"
|
||||||
|
@ -309,11 +315,6 @@ push_stash () {
|
||||||
else
|
else
|
||||||
git reset --hard -q
|
git reset --hard -q
|
||||||
fi
|
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"
|
if test "$keep_index" = "t" && test -n "$i_tree"
|
||||||
then
|
then
|
||||||
|
|
|
@ -211,4 +211,21 @@ test_expect_success 'stash push with $IFS character' '
|
||||||
test_path_is_file bar
|
test_path_is_file bar
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat > .gitignore <<EOF
|
||||||
|
ignored
|
||||||
|
ignored.d/*
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'stash previously ignored file' '
|
||||||
|
git reset HEAD &&
|
||||||
|
git add .gitignore &&
|
||||||
|
git commit -m "Add .gitignore" &&
|
||||||
|
>ignored.d/foo &&
|
||||||
|
echo "!ignored.d/foo" >> .gitignore &&
|
||||||
|
git stash save --include-untracked &&
|
||||||
|
test_path_is_missing ignored.d/foo &&
|
||||||
|
git stash pop &&
|
||||||
|
test_path_is_file ignored.d/foo
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue