Skip to content

Commit 922c234

Browse files
authored
[automerge] Rework restoring of changes to ignored files (#24)
Using the `git ls-files` to list deleted files that are unmmerged did not work consitently in the previous solution. This updates the `restore_changes_to_ignored_files` function to first deal with any no-deleted unmerged conflicts, making it easier to identify conflicting files that were deleted by us to be fed into `git rm`.
1 parent 5e4f882 commit 922c234

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arm-software/ci/automerge.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ def run_cmd(self, args: list[str], check: bool = True) -> str:
5050
def restore_changes_to_ignored_files(git_repo: Git, ignore_list: list[str]) -> None:
5151
if not ignore_list:
5252
return
53-
# Make sure any files deleted by us stay deleted.
54-
# Note that any deleted files in the working tree at this point are conflicts
55-
ls_files_output = git_repo.run_cmd(["ls-files", "--deleted", "--deduplicate"] + ignore_list)
53+
# First, deal with any conflicting changes to files in the ignore list,
54+
# keeping the version from the destination branch
55+
git_repo.run_cmd(["restore", "--ours", "--worktree"] + ignore_list)
56+
# Next, any files still unmerged are the ones deleted on the destination branch.
57+
# Make sure they stay deleted.
58+
ls_files_output = git_repo.run_cmd(["diff", "--name-only", "--diff-filter=U", "--"] + ignore_list)
5659
deleted_by_us = ls_files_output.splitlines()
5760
if deleted_by_us:
5861
git_repo.run_cmd(["rm"] + deleted_by_us)
59-
# Next, restore ignored files in the index
60-
git_repo.run_cmd(["restore", "--staged"] + ignore_list)
61-
# And finally, restore ignored files in the working tree
62-
git_repo.run_cmd(["restore", "--ours", "--worktree"] + ignore_list)
62+
# Finally, restore all other ignored files
63+
git_repo.run_cmd(["restore", "--staged", "--worktree"] + ignore_list)
6364

6465

6566
def has_unresolved_conflicts(git_repo: Git) -> bool:

0 commit comments

Comments
 (0)