git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Cc: <git@vger.kernel.org>, <sam@whiteoctober.co.uk>
Subject: Re: [PATCH] stash: clean untracked files before reset
Date: Fri, 11 Aug 2017 15:11:14 -0700	[thread overview]
Message-ID: <xmqq60dtzrel.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <b87007d1-eb5a-f092-9e03-5c6549044b42@morey-chaisemartin.com> (Nicolas Morey-Chaisemartin's message of "Fri, 11 Aug 2017 19:14:43 +0200")

Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> writes:

> 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.
>
> Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
> Reported-by: Sam Partington <sam@whiteoctober.co.uk>

These two lines are the other way around; a report/finding was made
and then you wrote a fix, which is signed-off by you.

I tried to think of a scenario where it is more desirable to use the
contents of the .gitignore file before modification gets stash away,
but I came up empty, so let's hope that this change will not make
50% people happier while making the other 50% sadder.

> ---
>  git-stash.sh                       | 11 ++++++-----
>  t/t3905-stash-include-untracked.sh | 18 ++++++++++++++++++
>  2 files changed, 24 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
> diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
> index 193adc7b6..c1f84d3d5 100755
> --- a/t/t3905-stash-include-untracked.sh
> +++ b/t/t3905-stash-include-untracked.sh
> @@ -211,4 +211,22 @@ test_expect_success 'stash push with $IFS character' '
>  	test_path_is_file bar
>  '
>  
> +cat > .gitignore <<EOF
> +ignored
> +ignored.d/*
> +EOF
> +
> +test_expect_success 'stash previously ignored file' '
> +which git &&

I will remove this line while queuing, though.

> +	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

Will queue.  Thanks.


  reply	other threads:[~2017-08-11 22:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-11 15:55 Bug when stashing previously-ignored file plus associated .gitignore change Sam Partington
2017-08-11 17:14 ` [PATCH] stash: clean untracked files before reset Nicolas Morey-Chaisemartin
2017-08-11 22:11   ` Junio C Hamano [this message]
2017-08-14  4:47 ` Bug when stashing previously-ignored file plus associated .gitignore change Kevin Daudt
2017-08-14  7:38   ` Sam Partington

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq60dtzrel.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=nicolas@morey-chaisemartin.com \
    --cc=sam@whiteoctober.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).