Skip to content

Commit 41ecd90

Browse files
authored
fix(updating): don't skip gitignored .rej files when converting to inline conflict markers (#2668)
1 parent c35042b commit 41ecd90

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

copier/_main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,12 +1529,16 @@ def _apply_update(self) -> None: # noqa: C901
15291529
conflicted = []
15301530
old_path = Path(old_copy)
15311531
new_path = Path(new_copy)
1532-
status = git("status", "--porcelain").strip().splitlines()
1532+
# `--ignored` so we still find .rej files when the
1533+
# destination has a `*.rej` ignore rule.
1534+
status = (
1535+
git("status", "--porcelain", "--ignored").strip().splitlines()
1536+
)
15331537
for line in status:
15341538
# Filter merge rejections (part 1/2)
1535-
if not line.startswith("?? "):
1539+
if not line.startswith(("?? ", "!! ")):
15361540
continue
1537-
# Remove "?? " prefix
1541+
# Remove prefix
15381542
fname = line[3:]
15391543
# Normalize name
15401544
fname = normalize_git_path(fname)

tests/test_updatediff.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ def function_two():
12841284
)
12851285

12861286

1287+
@pytest.mark.parametrize("gitignore_rej", [False, True])
12871288
@pytest.mark.parametrize(
12881289
"filename",
12891290
[
@@ -1297,6 +1298,7 @@ def function_two():
12971298
def test_conflicted_files_are_marked_unmerged(
12981299
tmp_path_factory: pytest.TempPathFactory,
12991300
filename: str,
1301+
gitignore_rej: bool,
13001302
) -> None:
13011303
# Template in v1 has a file with a single line;
13021304
# in v2 it changes that line.
@@ -1325,6 +1327,17 @@ def test_conflicted_files_are_marked_unmerged(
13251327
with local.cwd(dst):
13261328
git_init("hello project")
13271329

1330+
# Optionally gitignore .rej files. Inline-conflict resolution
1331+
# must still produce inline markers — the .rej is just an
1332+
# internal artifact of the resolution, never something the
1333+
# downstream user wants to see, so it's reasonable for them to
1334+
# ignore it. Regression for the case where copier's `git status
1335+
# --porcelain` invocation silently dropped ignored .rej files.
1336+
if gitignore_rej:
1337+
Path(".gitignore").write_text("*.rej\n")
1338+
git("add", ".gitignore")
1339+
git("commit", "-m", "ignore .rej files")
1340+
13281341
# After first commit, change the file, commit again
13291342
Path(filename).write_text("upstream version 1 + downstream")
13301343
git("commit", "-am", "updated file")

0 commit comments

Comments
 (0)