Open gdlxn-ibm opened 5 months ago
This problem looks to be an example of "unexpected" behavior that can occur when the new name in --path-rename <old_name:new_name>
already exists in the commit history.
In the above scenario, the path rename of f1
to f2
works as expected as f2
does not exist in the commit history at the time of the path rename. It simply replaces f1
with f2
in the second commit.
On the other hand, the path rename of f2
to f1
show "unexpected" behavior as f1
already exists in commits 3 and 4 at the time of the path rename. The path rename replaces f2
with f1
in the second commit, which then "collides" with the existing f1
in commits 3 and 4. In particular, the f1
delete in commit 4 causes f1
to be deleted.
@newren I'm not exactly sure what you intend to happen when the new name in --path-rename <old_name:new_name>
already exists in the commit history, though I suspect that it is working "as designed". Because of the potential for unexpected behavior, would it be possible to have --path-rename
issue a warning message if the new name already exists in the commit history? I would also suggest updating the --path-rename
documentation in the user manual with a warning about possible unexpected behavior when new name already exists in the commit history.
Yeah, working as expected. Unfortunately, attempting to determine if the new pathnames are in the commit history, within a relevant range of commits, is computationally quite expensive and can become challenging in terms of tracking the topology correctly. This can be even worse since the renaming can happen with --path-rename or --paths-from-file or --filename-callback and might be a prefix, or a glob, or a regex, or some more general function making it hard to even enumerate all the new names. I added a very simplistic check (basically only triggering if there was a commit which modified both the old and new filenames when users tried to rename one to the other -- in that case filter-repo will print a "File renaming caused colliding pathnames" error and abort). That can sometimes help users, but it leaves a lot of cases out because I don't think a more general one is really feasible.
I'd be very happy to take a patch to add a warning to the manual.
Using the
--replace-refs delete-no-add
workaround from Bug #401, I've found a scenario wheregit filter-repo --path-rename <source-path>:<target-path>
deletes the source path rather than renaming it to the target path as shown below.Create a new Git repository
Perform initial Git commit
Create and commit file f1
Rename file f1 to f2
Create and commit new f1 file
Delete and commit new f1 file
Rename file f2 to f1
Note that
git filter-repo --replace-refs delete-no-add --path-rename f2:f1 --force
incorrectly deleted filef2
rather than renaming it tof1