Subject: Re: [PATCH 1/2] builtin/mv: bail out when trying to move child and its parent

From: Patrick Steinhardt <[email-masked]>
Date: Fri, 2 May 2025 10:07:38 +0200

On Wed, Apr 30, 2025 at 03:21:42PM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <[email-masked]> writes:
> > -	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.

This might've been a good idea, but I see that the series has already
been merged to `next`. So I'll refrain from improving the tests.

Thanks!

Patrick