feat: add --auto-scope flag to scope commands to the current git diff - #72
Merged
Merged
Conversation
Adds --auto-scope/-A to plan, apply, destroy and docs so they operate only on resource groups affected by the current git diff (working tree and staged changes vs HEAD, plus untracked files), instead of requiring an explicit path. Closes #65.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧑💻What is the change being made?
Adds a
--auto-scope/-Aflag toplan,apply,destroyanddocs. When set, it computes the files changed relative toHEAD(working tree + staged changes, plus untracked files) via a newGitbind, maps each changed file to its nearest ancestor resource-group directory, and scopes the command to just that set instead of requiring an explicitpathargument.--auto-scopeand an explicitpathare mutually exclusive and raise aUsageErrorif combined.docswas also refactored to route through the shared resource-dir discovery (resolve_resource_dirs) instead of its own inline directory walk, and its docs-dir cleanup no longer wipes the whole output tree on a scoped run.❓ Why is the change being made?
CI pipelines and developers working across large
conf/resourcestrees currently have to manually figure out and type the right subpath to limit which resource groups a command touches. This is repetitive and error-prone once a branch spans multiple unrelated directories. Scoping automatically to "whatever changed in this diff" removes that manual step.✅ How has this been tested?
tests/it/test_helpers.pycoveringauto_scope_resource_dirs(staged/unstaged/untracked changes, nested files mapping to their owning group, changes outside the resources dir being ignored, no-changes, not-a-git-repo) andresolve_resource_dirs(mutual exclusion withpath).tests/e2e/test_plan_command.py,test_apply_command.py,test_destroy_command.pyandtest_docs_command.py, using a throwaway git-managed copy of fixture trees to exercise--auto-scopeend to end, including thedocsrmtree-guard behavior.uv run poe lint,uv run basedpyright, anduv run poe testall pass (328 tests).terraform, confirming correct scoping, theUsageErroron combined flags, and a clean error message when run outside a git repository.📚 How has this been documented?
The flag is self-documenting via its
--helptext (sharedauto_scope_optionincommands/helpers.py); this repo has no separate CLI reference doc to update.🔗 Related Issues
Closes #65