public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org,  Kristoffer Haugsbakk <code@khaugsbakk.name>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 1/2] builtin/mv: bail out when trying to move child and its parent
Date: Wed, 30 Apr 2025 15:21:42 -0700	[thread overview]
Message-ID: <xmqqmsbxz3wp.fsf@gitster.g> (raw)
In-Reply-To: <20250430-pks-mv-parent-child-conflict-v1-1-11a87c55ffb9@pks.im> (Patrick Steinhardt's message of "Wed, 30 Apr 2025 14:44:57 +0200")

Patrick Steinhardt <ps@pks.im> writes:

> @@ -368,8 +398,7 @@ int cmd_mv(int argc,
>  				strvec_push(&sources, path);
>  				strvec_push(&destinations, prefixed_path);
>  
> -				memset(modes + argc + j, 0, sizeof(enum update_mode));
> -				modes[argc + j] |= ce_skip_worktree(ce) ? SPARSE : INDEX;
> +				modes[argc + j] = MOVE_VIA_PARENT_DIR | (ce_skip_worktree(ce) ? SPARSE : INDEX);
>  				submodule_gitfiles[argc + j] = NULL;

OK, this is the part we both missed during the earlier round.

> +			if (hashmap_get_entry(&moved_dirs, &needle, ent, NULL))
> +				die(_("cannot move both '%s' and its parent directory '%s'"),
> +				    sources.v[i], pathbuf.buf);

OK.

> -test_expect_failure 'nonsense mv triggers assertion failure and partially updated index' '
> +test_expect_success 'moving file and its parent directory at the same time fails' '

The new title is much more descriptive.

> -	test_must_fail git mv a/a.txt a b &&
> -	git status --porcelain >actual &&
> -	grep "^A[ ]*a/a.txt$" actual
> +	cat >expect <<-EOF &&
> +	fatal: cannot move both ${SQ}a/a.txt${SQ} and its parent directory ${SQ}a${SQ}
> +	EOF
> +	test_must_fail git mv a/a.txt a b 2>err &&
> +	test_cmp expect err
> +'

Shouldn't we make sure that after failing "git mv" the paths and the
index entries stay as expected?

> +test_expect_success 'moving nested directory and its parent directory at the same time fails' '
> +	test_when_finished git reset --hard HEAD &&
> +	git reset --hard HEAD &&
> +	mkdir -p a/b/c &&
> +	>a/b/c/file.txt &&
> +	git add a &&
> +	mkdir target &&
> +	cat >expect <<-EOF &&
> +	fatal: cannot move both ${SQ}a/b/c${SQ} and its parent directory ${SQ}a${SQ}
> +	EOF
> +	test_must_fail git mv a/b/c a target 2>err &&
> +	test_cmp expect err
>  '

Ditto.

By the way I think "git mv a a/b" in the same scenario already
notices a problematic request, so it probably won't hit this
codepath but we shoudl already be covered.

Thanks.

  reply	other threads:[~2025-04-30 22:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 12:44 [PATCH 0/2] builtin/mv: bail out when trying to move child and its parent Patrick Steinhardt
2025-04-30 12:44 ` [PATCH 1/2] " Patrick Steinhardt
2025-04-30 22:21   ` Junio C Hamano [this message]
2025-05-02  8:07     ` Patrick Steinhardt
2025-04-30 12:44 ` [PATCH 2/2] builtin/mv: convert assert(3p) into `BUG()` Patrick Steinhardt
2025-04-30 18:45   ` Junio C Hamano
2025-04-30 23:10     ` Junio C Hamano
2025-05-02  8:06       ` Patrick Steinhardt
2025-05-02  9:44         ` Johannes Schindelin
2025-05-02 16:53           ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=xmqqmsbxz3wp.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox