]> git.ipfire.org Git - thirdparty/git.git/commit - t/t6423-merge-rename-directories.sh
merge-recursive: handle rename-to-self case
authorElijah Newren <newren@gmail.com>
Wed, 30 Jun 2021 17:30:00 +0000 (17:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Jun 2021 21:40:10 +0000 (14:40 -0700)
commit3585d0ea232b1a9c5498ab5785b11f61e93967c8
treec595242bf63f3cd4397cd1cd74c20838120c9e2d
parenta492d5331cb93d8293e72741b4fb9e1ec4ff294b
merge-recursive: handle rename-to-self case

Directory rename detection can cause transitive renames, e.g. if the two
different sides of history each do one half of:
    A/file -> B/file
    B/     -> C/
then directory rename detection transitively renames to give us
    A/file -> C/file

However, when C/ == A/, note that this gives us
    A/file -> A/file.

merge-recursive assumed that any rename D -> E would have D != E.  While
that is almost always true, the above is a special case where it is not.
So we cannot do things like delete the rename source, we cannot assume
that a file existing at path E implies a rename/add conflict and we have
to be careful about what stages end up in the output.

This change feels a bit hackish.  It took me surprisingly many hours to
find, and given merge-recursive's design causing it to attempt to
enumerate all combinations of edge and corner cases with special code
for each combination, I'm worried there are other similar fixes needed
elsewhere if we can just come up with the right special testcase.
Perhaps an audit would rule it out, but I have not the energy.
merge-recursive deserves to die, and since it is on its way out anyway,
fixing this particular bug narrowly will have to be good enough.

Reported-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-recursive.c
t/t6423-merge-rename-directories.sh