Skip to content

Hook to check stale file references - #174

Draft
cbachhuber wants to merge 5 commits into
masterfrom
162-check-stale-references
Draft

Hook to check stale file references#174
cbachhuber wants to merge 5 commits into
masterfrom
162-check-stale-references

Conversation

@cbachhuber

Copy link
Copy Markdown
Collaborator

Closes #162

Comment thread dev_tools/check_stale_references.py
Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
@cbachhuber
cbachhuber requested a lite review from Copilot August 11, 2026 04:10
Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
alternatives: list[str] = []
for i in range(len(segments)):
suffix = "/".join(segments[i:])
escaped_suffix = re.escape(suffix)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that checks the need for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The # noqa: S607 suppresses a ruff lint rule (partial executable path), not a runtime behavior — there's no test that would exercise it. It's now consolidated into the single _run_git() helper so there's only one suppression.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the re.escape part. Do we have a test for that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — added test_dot_in_extension_is_literal which asserts that fooXhpp does not match foo.hpp (without re.escape, the . would match any character).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new check-stale-references pre-commit hook intended to detect references to deleted/renamed files (by full repo-relative path and by basename) in the remaining tracked files, helping prevent broken cross-references after refactors.

Changes:

  • Introduces dev_tools.check_stale_references implementation and a console entrypoint (check-stale-references).
  • Adds test coverage for pattern-building, detection, and output formatting.
  • Wires the hook into .pre-commit-hooks.yaml and documents it in README.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
dev_tools/check_stale_references.py Implements stale-reference detection and printing for use as a pre-commit hook.
tests/test_check_stale_references.py Adds unit tests for matching behavior and reporting.
pyproject.toml Registers the new console script and adjusts Ruff test ignores.
.pre-commit-hooks.yaml Adds the new check-stale-references hook definition.
README.md Documents the new hook in the Tools section and TOC.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
Comment thread dev_tools/check_stale_references.py Outdated
cbachhuber and others added 4 commits August 11, 2026 01:47
…oundaries

- Replace Python file I/O with git grep for performance
- Extract _run_git() helper using subprocess.run(check=True)
- Simplify D/R branch in get_deleted_paths (both use parts[1])
- Add __str__ to StaleReference, remove print_stale_references
- Tighten regex boundaries to [\w.-] to reject foo.hpp.bak etc.
- Remove unused get_repo_root and get_tracked_files
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.

Local link verification in source code

2 participants