Skip to content

feat: add --auto-scope flag to scope commands to the current git diff - #72

Merged
amannocci merged 1 commit into
mainfrom
feat/auto-scope-git-diff
Sep 18, 2026
Merged

amannocci merged 1 commit into
mainfrom
feat/auto-scope-git-diff

Conversation

@amannocci

Copy link
Copy Markdown
Member

🧑‍💻What is the change being made?

Adds a --auto-scope/-A flag to plan, apply, destroy and docs. When set, it computes the files changed relative to HEAD (working tree + staged changes, plus untracked files) via a new Git bind, maps each changed file to its nearest ancestor resource-group directory, and scopes the command to just that set instead of requiring an explicit path argument. --auto-scope and an explicit path are mutually exclusive and raise a UsageError if combined. docs was 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/resources trees 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?

  • New unit tests in tests/it/test_helpers.py covering auto_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) and resolve_resource_dirs (mutual exclusion with path).
  • New e2e tests in tests/e2e/test_plan_command.py, test_apply_command.py, test_destroy_command.py and test_docs_command.py, using a throwaway git-managed copy of fixture trees to exercise --auto-scope end to end, including the docs rmtree-guard behavior.
  • uv run poe lint, uv run basedpyright, and uv run poe test all pass (328 tests).
  • Manual smoke testing against a scratch git-managed conf dir with real terraform, confirming correct scoping, the UsageError on 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 --help text (shared auto_scope_option in commands/helpers.py); this repo has no separate CLI reference doc to update.

🔗 Related Issues

Closes #65

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.
@amannocci amannocci self-assigned this Sep 18, 2026
@amannocci
amannocci merged commit 3afef8c into main Sep 18, 2026
14 checks passed
@amannocci
amannocci deleted the feat/auto-scope-git-diff branch September 18, 2026 13:39
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.

[Feature]: Auto-scope paths based on git diff

1 participant