Skip to content

Add manual delete git branch#8618

Open
solababs wants to merge 4 commits intosb-13032026-delete-git-branch-after-merge-ifc-2336from
sb-13032026-manual-delete-branch-ifc-2336
Open

Add manual delete git branch#8618
solababs wants to merge 4 commits intosb-13032026-delete-git-branch-after-merge-ifc-2336from
sb-13032026-manual-delete-branch-ifc-2336

Conversation

@solababs
Copy link
Contributor

@solababs solababs commented Mar 16, 2026

Why

There is no way to trigger Git branch deletion on-demand when manually deleting an Infrahub branch — the automatic delete_git_branch_after_merge setting only applies to the merge flow. A user who merges without the config enabled, or who wants per-branch control, has no option today.

This PR adds delete_from_git: Boolean to the BranchDelete GraphQL mutation so callers can opt into Git branch deletion at call time, regardless of the global config.

What changed

  • backend/infrahub/graphql/mutations/branch.py — new BranchDeleteInput type with name and delete_from_git: Boolean (default false). BranchDelete now uses BranchDeleteInput instead of BranchNameInput, and passes delete_from_git through to both the execute_workflow and submit_workflow call sites.
  • backend/infrahub/core/branch/tasks.pydelete_branch() flow now accepts delete_from_git: bool = False. The should_delete_git condition becomes (config.SETTINGS.main.delete_git_branch_after_merge or delete_from_git) and obj.sync_with_git — either the global setting or the explicit flag triggers Git deletion.
  • backend/tests/functional/branch/test_delete_git_branch.py — 2 new tests appended to the existing class: delete_from_git=True with config disabled triggers GIT_REPOSITORIES_DELETE_BRANCH; delete_from_git=False with config disabled does not.

BranchNameInput is unchanged and still used by other mutations — no existing callers of BranchDelete are broken since delete_from_git defaults to false.

Suggested review order

  1. backend/infrahub/graphql/mutations/branch.pyBranchDeleteInput + updated mutate()
  2. backend/infrahub/core/branch/tasks.py — updated delete_branch() signature and condition
  3. backend/tests/functional/branch/test_delete_git_branch.py — 2 new tests at the bottom

How to review

  • Confirm bool(data.delete_from_git) is the right coercion — GraphQL Boolean with default_value=False should always produce a bool, but the explicit cast is a safe guard.
  • The or condition in should_delete_git means either the global config or the per-call flag can enable Git deletion. Verify this is intentional and matches FR-008/FR-009.
  • BranchNameInput is intentionally kept unchanged — other mutations (BranchMerge, etc.) still use it.

How to test

uv run pytest backend/tests/functional/branch/test_delete_git_branch.py -v

Manual flow:

  1. With delete_git_branch_after_merge = false (default), call BranchDelete with delete_from_git: true on a sync_with_git=True branch — Git branch should be deleted.
  2. Call BranchDelete with delete_from_git: false on a sync_with_git=True branch — Git branch should be retained.
  3. Omit delete_from_git entirely — existing behaviour unchanged.

Impact & rollout

  • Backward compatibility: No breaking changes. delete_from_git is optional and defaults to false; existing BranchDelete callers are unaffected.
  • Config/env changes: No config changes.
  • Deployment notes: Safe to deploy. Fully opt-in.

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (4)
  • main
  • stable
  • develop
  • release-.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9221d38-1d54-4016-bebe-8536b3a0f7a1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Mar 16, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 16, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing sb-13032026-manual-delete-branch-ifc-2336 (bce6bdc) with sb-13032026-delete-git-branch-after-merge-ifc-2336 (5001ed7)

Open in CodSpeed

@solababs solababs marked this pull request as ready for review March 17, 2026 12:19
@solababs solababs requested a review from a team as a code owner March 17, 2026 12:19
@solababs solababs requested a review from a team as a code owner March 17, 2026 12:27
@github-actions github-actions bot added the group/frontend Issue related to the frontend (React) label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants