]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-ort: fix slightly overzealous assertion for rename-to-self
authorElijah Newren <newren@gmail.com>
Thu, 6 Mar 2025 15:30:27 +0000 (15:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Mar 2025 17:38:20 +0000 (09:38 -0800)
merge-ort has a number of sanity checks on the file it is processing in
process_renames().  One of these sanity checks was slightly overzealous
because it indirectly assumed that a renamed file always ended up at a
different path than where it started.  That is normally an entirely fair
assumption, but directory rename detection can make things interesting.

As a quick refresher, if one side of history renames directory A/ -> B/,
and the other side of history adds new files to A/, then directory
rename detection notices and suggests moving those new files to B/.  A
similar thing is done for paths renamed into A/, causing them to be
transitively renamed into B/.  But, if the file originally came from B/,
then this can end up causing a file to be renamed back to itself.

It turns out the rest of the code following this assertion handled the
case fine; the assertion was just an extra sanity check, not a rigid
precondition.  Therefore, simply adjust the assertion to pass under this
special case as well.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-ort.c
t/t6423-merge-rename-directories.sh

index 46e78c3ffa68e62dec08e8619800fcae28a9dd9d..b0ff2236af03d98cbebdecaa28e697abae27424a 100644 (file)
@@ -3048,7 +3048,8 @@ static int process_renames(struct merge_options *opt,
                        }
                }
 
-               assert(source_deleted || oldinfo->filemask & old_sidemask);
+               assert(source_deleted || oldinfo->filemask & old_sidemask ||
+                      !strcmp(pair->one->path, pair->two->path));
 
                /* Need to check for special types of rename conflicts... */
                if (collision && !source_deleted) {
index 7b8d79f56c19d76e2718c1bbc9322a4fd0db40ef..79d889b94cbcf34bc8af5256066cf332f7527e0d 100755 (executable)
@@ -5391,7 +5391,7 @@ test_setup_12n () {
        )
 }
 
-test_expect_failure '12n: Directory rename transitively makes rename back to self' '
+test_expect_success '12n: Directory rename transitively makes rename back to self' '
        test_setup_12n &&
        (
                cd 12n &&