Skip to content

feat: allow switching installed app branches - #543

Open
aakvatech wants to merge 42 commits into
frappe:developfrom
Aakvatech-Limited:feat/app-branch-switching
Open

aakvatech wants to merge 42 commits into
frappe:developfrom
Aakvatech-Limited:feat/app-branch-switching

Conversation

@aakvatech

Copy link
Copy Markdown
Contributor

Summary

Add first-class support for changing the branch of an installed app from the Pilot Admin UI.

Pilot already had an internal SwitchBranchTask, but there was no Admin UI/API workflow to use it. This PR exposes that functionality and makes branch switching robust for shallow and single-branch clones.

Changes

  • Add POST /apps/<name>/actions/switch-branch.

  • Add Change branch to installed app actions.

  • Load available remote branches using the existing Git branch endpoint.

  • Queue the existing SwitchBranchTask for the actual switch.

  • Add optional Force switch behavior to discard tracked and untracked local changes.

  • Fetch the target branch using an explicit remote-tracking refspec:

    +refs/heads/<branch>:refs/remotes/origin/<branch>
    
  • Keep .git/config synchronized after switching:

    • replace stale branch-specific remote.origin.fetch entries for single-branch clones;
    • preserve wildcard refs/heads/* fetch configuration for full clones;
    • set branch.<name>.remote = origin;
    • set branch.<name>.merge = refs/heads/<name>.
  • Persist the selected branch back to bench.toml.

  • Retain the existing validation, reinstall, asset build, and worker reload behavior.

  • Document the new API.

Why

Apps may move away from deprecated branches, while existing Pilot installations remain configured and checked out on the old branch.

For single-branch clones, simply running:

git fetch origin <branch>

may only populate FETCH_HEAD and leave the clone's persistent fetch configuration still pointing at the deprecated branch.

This can leave three states inconsistent:

Git checkout branch
        ↕
.git/config tracking/refspec
        ↕
bench.toml configured branch

This PR keeps all three synchronized through a single managed Pilot operation.

Safety

Normal branch switching preserves local changes using the existing stash behavior.

Force switching is explicit and permanently discards tracked and untracked working-tree changes before switching.

Tests

Added coverage for:

  • branch-switch API queueing;
  • invalid branch validation;
  • force propagation through SwitchBranchTask;
  • switching from a single-branch clone to a previously untracked remote branch;
  • .git/config refspec and upstream tracking updates;
  • preservation of wildcard fetch refspecs on full clones;
  • force switching with local tracked and untracked changes.

@aakvatech

Copy link
Copy Markdown
Contributor Author

Fixes #542

@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Adds app branch switching to the admin API and task system.

No new blocking finding was identified; the PR appears safe to merge under the resolved review threads.

Reviews (7) · Last reviewed commit: "test: cover same-commit branch switch ro..."

Comment thread pilot/core/app/repository.py
Comment thread pilot/core/app/repository.py
Comment thread admin/frontend/dashboard/src/components/apps/SwitchBranchDialog.vue Outdated
Comment thread admin/backend/api/v1/apps.py Outdated
Comment thread pilot/core/app/repository.py
Comment thread pilot/tasks/switch_branch.py Outdated
Comment thread pilot/tasks/switch_branch.py Outdated
Comment thread admin/backend/api/v1/apps.py
Comment thread pilot/core/app/repository.py
Comment thread pilot/tasks/switch_branch.py Outdated
Comment thread tests/admin/backend/api/test_apps_view.py
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