Skip to content

feat: add --base option to scope auto-scope to a git ref - #105

Merged
amannocci merged 1 commit into
mainfrom
feat/auto-scope-base-ref
Oct 20, 2026
Merged

amannocci merged 1 commit into
mainfrom
feat/auto-scope-base-ref

Conversation

@amannocci

Copy link
Copy Markdown
Member

🧑‍💻What is the change being made?

Adds a --base <ref> option to plan, apply, destroy, docs and migrate, usable together with --auto-scope. Changes are then taken relative to the merge base of <ref> and HEAD (git merge-base) instead of HEAD, so commits already made on the branch count, along with staged, unstaged and untracked changes. The shared-file mapping from #104 uses the same base. --base without --auto-scope, and an unknown or empty ref, are rejected with an explained error. The diff uses --no-renames so that both the source and the destination of a moved file are in scope, and the ref is passed to git after --.

❓ Why is the change being made?

--auto-scope compared the working tree to HEAD. On a CI checkout the tree is clean, so terranova plan -A selected no resource group and the job passed without planning anything. A configurable base lets CI run terranova plan -A --base origin/main against the files a pull request changed.

✅ How has this been tested?

Added integration tests in tests/it/test_helpers.py using real git repositories: committed changes picked up through the base, uncommitted changes included, shared dependencies mapped through the base, a renamed file selecting both groups, invalid refs (unknown, empty, option-like) rejected, and an empty ref without --auto-scope rejected. Added e2e tests for plan -A --base on a clean tree, and for --base without --auto-scope on plan and apply. The full suite passes (495 tests), and ruff and basedpyright are clean on the changed files. Commit boilerplate in the tests was merged into one commit_all helper.

📚 How has this been documented?

Added a bullet to the "How to scope a run to what changed" section of the README describing --base, including the need for full history on a CI checkout (fetch-depth: 0), plus a terranova plan -A --base origin/main example. The --base option has its own --help text, and the auto_scope_resource_dirs docstring was updated.

🔗 Related Issues

Partially addresses #103 (the base ref case). This PR is stacked on #104, which fixes the shared-file case, so it targets that branch until #104 merges. The opt-in expansion to groups that import from a changed group is not part of this PR, so the issue stays open.

Base automatically changed from fix/auto-scope-shared-dependencies to main October 16, 2026 17:42
--auto-scope only compared the working tree to HEAD, so a clean CI
checkout selected nothing. With --base <ref>, changes are taken relative
to the merge base of the ref and HEAD, including committed ones.
@amannocci
amannocci force-pushed the feat/auto-scope-base-ref branch from ae70070 to 1190a3b Compare October 17, 2026 10:24
@amannocci amannocci self-assigned this Oct 20, 2026
@amannocci
amannocci merged commit 58e9963 into main Oct 20, 2026
17 checks passed
@amannocci
amannocci deleted the feat/auto-scope-base-ref branch October 20, 2026 08:46
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.

1 participant