Skip to content

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

Description

@amannocci

🚀 Feature Summary

Add a new flag (e.g. --auto-scope / -A) that automatically scopes the resource groups a command operates on to only those affected by the current git diff (working tree and staged changes vs HEAD), instead of requiring an explicit path argument.

🤔 Problem Statement

Commands like plan, apply, destroy, and docs accept an optional positional path to limit which resource groups (directories containing a manifest) are processed. In practice, users and CI pipelines often only want to act on the resource groups whose files were actually changed in the current branch/working tree. Today that requires manually figuring out and typing the right subpath, which is error-prone and doesn't scale well when changes span multiple unrelated directories.

💡 Proposed Solution

Introduce a flag that, when set, computes the set of changed files via git diff --name-only HEAD (including untracked files), maps each changed file to its containing resource-group directory (i.e. the nearest ancestor directory with a manifest), and intersects that set with the normal resource_dirs() discovery result before building the dependency graph / waves. This plugs in at the same point the existing path argument does today (src/terranova/commands/helpers.py), so no changes to graph/wave/executor logic are required. Only commands where "changed resource groups" is a meaningful concept would support the flag — ls and get would not.

🔄 Alternatives Considered

  • Requiring users to manually script git diff + pass paths themselves — already possible today, but repetitive and not discoverable.
  • Diffing against a configurable ref/branch (e.g. origin/main) instead of a fixed working-tree-vs-HEAD comparison — deferred as a possible follow-up, but out of scope for this issue to keep the initial implementation simple.

📈 Impact

CI pipelines and developers working across large conf/ trees benefit from faster, more targeted runs, and reduced risk of accidentally touching unrelated resource groups.

📝 Additional Context

Related code: src/terranova/commands/helpers.py (resource_dirs, find_all_resource_dirs), src/terranova/graph.py (build_dependency_graph, compute_waves), and per-command path arguments (e.g. src/terranova/commands/plan.py).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions