Skip to content

fix: open the child repository PR when Copier leaves conflicts - #41

Merged
mjun0812 merged 1 commit into
mainfrom
fix/child-update-conflicts
Sep 8, 2026
Merged

mjun0812 merged 1 commit into
mainfrom
fix/child-update-conflicts

Conversation

@mjun0812

@mjun0812 mjun0812 commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Overview and Background

The v2.0.1 tag got past the interactive-prompt failure fixed in #40, and then failed one step later:

[command] git checkout --progress -B 393b6e0a-... HEAD --
error: you need to resolve your current index first
README.md: needs merge

copier update succeeded, but README.md in the child repository could not be merged automatically. Copier writes such files with inline conflict markers and leaves them unmerged in the index, then exits 0. peter-evans/create-pull-request starts by creating its branch with git checkout -B, which refuses to run while the index has unmerged entries, so no pull request was opened and the whole update was lost.

While reproducing this I also found that the change-detection step used git diff --quiet, which does not see untracked files. An update that only adds files (this release adds .agents/, .claude/ and .codex/) would have been reported as "no changes" and skipped.

Related Issues

None. Follow-up to #40, same workflow.

Implementation Approach

  • Keep Copier's default inline conflict markers rather than switching to --conflict rej. I tested both against the real child repository: with rej the index stays clean, but the merged file silently loses the rejected hunk and a README.md.rej file is committed alongside it. Inline markers keep both versions visible in the diff and cannot be merged by accident without someone noticing.
  • After the update, collect unmerged paths with git diff --name-only --diff-filter=U and git add -A so the branch can be created. The conflict markers travel into the pull request, where a person resolves them.
  • Make that impossible to miss: the paths go into the job log as ::warning:: annotations, the pull request title gains a (resolve conflicts) suffix, and the body gains a section naming each conflicting file. The body text is built as a multi-line step output, because GitHub expression string literals cannot contain newlines.
  • Detect changes with git status --porcelain instead of git diff --quiet.

Changes

  • .github/workflows/trigger-template-update.yml: stage and report conflicts in the update step; conditional title suffix and conflict section in the pull request; change detection via git status.

Impact

  • A conflicting update now reaches the child repository as a pull request that says what needs resolving, instead of failing the workflow and delivering nothing.
  • An update consisting only of new files is no longer skipped.
  • No change to the template, the generated project, or the Release workflow.

Validation Results

Extracted both run scripts from the workflow with a YAML parser and ran them against a real clone of mjun0812/python-project-template updated to v2.0.1, which reproduces the conflict.

Conflict case:

::warning::Conflict left for manual resolution in README.md
conflicts=true
conflict_note<<CONFLICT_NOTE_EOF
### Conflicts to resolve

Copier could not merge these files. They are committed with conflict markers
(`<<<<<<<`, `=======`, `>>>>>>>`); resolve every marker before merging.

- `README.md`
CONFLICT_NOTE_EOF

unmerged left: []
git checkout -B pr-test HEAD --    # checkout OK  (the command that failed in CI)
has_changes=true

No-conflict and no-change cases, after committing the update:

conflicts=false
has_changes=false

Add-only case, with a single untracked file present:

new check:  has_changes=true
old check:  has_changes=false   # the behavior being fixed

- Stage files Copier could not merge; it writes them with inline
  conflict markers and leaves them unmerged, which made the pull
  request action fail on git checkout -B and dropped the whole update
- Name the conflicting files in the pull request title, body and job
  log so the markers are resolved before the update is merged
- Detect changes with git status instead of git diff, so an update that
  only adds files is no longer reported as no change
@mjun0812 mjun0812 added the bug Something isn't working label Sep 8, 2026
@mjun0812 mjun0812 self-assigned this Sep 8, 2026
@mjun0812
mjun0812 merged commit bf179f1 into main Sep 8, 2026
7 checks passed
@mjun0812
mjun0812 deleted the fix/child-update-conflicts branch September 8, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant