Skip to content

Prevent absent files from being recorded in template.lock#373

Merged
tschm merged 2 commits intomainfrom
copilot/fix-template-lock-issue
Mar 7, 2026
Merged

Prevent absent files from being recorded in template.lock#373
tschm merged 2 commits intomainfrom
copilot/fix-template-lock-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 7, 2026

template.lock could list files under files: that don't exist in the target repo — e.g. when a 3-way merge conflict prevented a file from being written, or when a tracked file was manually deleted.

Changes

src/rhiza/commands/_sync_helpers.py

  • _write_lock now filters lock.files to paths that actually exist under target before persisting. Missing paths are dropped with a warning; the original TemplateLock object is never mutated (dataclasses.replace used for the filtered copy).
# Before: materialized files from upstream snapshot written verbatim
lock.to_yaml(tmp_path)

# After: only paths present on disk survive into the lock
existing_files = [f for f in lock.files if (target / f).exists()]
lock = dataclasses.replace(lock, files=existing_files)
lock.to_yaml(tmp_path)

tests/test_commands/test_sync.py

  • test_write_lock_yaml_format: creates the referenced file on disk (required now that absent files are filtered).
  • Three new cases added to TestLockFile: partial existence, all missing, and all present.
Original prompt

This section details on the original issue you should resolve

<issue_title>Files can be in template.lock without being in the repo</issue_title>
<issue_description>Make this impossible</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@tschm tschm marked this pull request as ready for review March 7, 2026 12:16
… entries

Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue where files can be in template.lock without being in the repo Prevent absent files from being recorded in template.lock Mar 7, 2026
Copilot finished work on behalf of tschm March 7, 2026 12:21
@tschm tschm merged commit 520bd82 into main Mar 7, 2026
1 check passed
@tschm tschm deleted the copilot/fix-template-lock-issue branch March 7, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files can be in template.lock without being in the repo

2 participants