Re: [PATCH] unpack-trees: do not delete i-t-a entries in worktree even when forced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> Intent-to-add entries are basically "I may want to commit these files
> later, but for now they are untracked". As such, when the user does "git
> reset --hard <tree>", which removes i-t-a entries from the index, i-t-a
> entries in worktree should be kept as untracked.

Hmm, I can see that the control flow of "reset --hard" for an i-t-a
path does pass through this function, but it is not very obvious
to see how this will not negatively affect other uses of the
unpack-trees machinery (e.g. "checkout" and "merge", especially when
such a path needs to turn into a directory by getting removed).

>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  Lost two files today, luckily I had a backup.
>
>  t/t2203-add-intent.sh | 15 +++++++++++++++
>  unpack-trees.c        |  2 +-
>  2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh
> index 2a4a749..63086bf 100755
> --- a/t/t2203-add-intent.sh
> +++ b/t/t2203-add-intent.sh
> @@ -82,5 +82,20 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'reset --hard leaves on-disk ita entries alone' '
> +	git init keep-ita &&
> +	(
> +	cd keep-ita &&
> +	echo abc >abc &&
> +	echo def >def &&
> +	git add abc &&
> +	git commit -m abc &&
> +	git add -N def &&
> +	git reset --hard HEAD &&
> +	echo def >expected &&
> +	test_cmp expected def
> +	)
> +'
> +
>  test_done
>  
> diff --git a/unpack-trees.c b/unpack-trees.c
> index 9f55cc2..1a2271b 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -104,7 +104,7 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
>  {
>  	clear |= CE_HASHED;
>  
> -	if (set & CE_REMOVE)
> +	if ((set & CE_REMOVE) && !ce_intent_to_add(ce))
>  		set |= CE_WT_REMOVE;
>  
>  	ce->ce_flags = (ce->ce_flags & ~clear) | set;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]