Skip to content

fix: wire branch selection and creation in git explorer#45

Merged
jmaxdev merged 3 commits intoTrixtyAI:mainfrom
matiaspalmac:fix/branch-selection
Apr 19, 2026
Merged

fix: wire branch selection and creation in git explorer#45
jmaxdev merged 3 commits intoTrixtyAI:mainfrom
matiaspalmac:fix/branch-selection

Conversation

@matiaspalmac
Copy link
Copy Markdown
Contributor

@matiaspalmac matiaspalmac commented Apr 19, 2026

Changes

El dropdown de ramas en el Git Explorer se renderizaba pero no tenía handlers, así que cambiar de rama era un no-op. La rama actual se estaba seteando con bl[0] (primera alfabética del git branch), no el HEAD real, por lo que el indicador podía mentir respecto al estado del working tree.

Backend (Rust):

  • apps/desktop/src-tauri/src/lib.rs: get_git_branches ahora devuelve { branches, current }. current se resuelve vía git symbolic-ref --short HEAD y cae a string vacío cuando HEAD está desacoplado, en vez de propagar un error. Se agregan git_checkout_branch(path, branch) y git_create_branch(path, branch), ambos usando git switch / git switch -c (2.23+, semántica específica de ramas — evita la ambigüedad de checkout con path-checkout). Ambos comandos validan el nombre con validate_branch_name, que rechaza nombres vacíos o que empiecen con - para cortar el vector de option-injection (--orphan, --detach, etc.).

Frontend:

  • apps/desktop/src/api/tauri.ts: ajusta el tipo de retorno de get_git_branches y agrega las firmas de los dos comandos nuevos.
  • apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx: refreshGit ya consume { branches, current } directamente; currentBranch queda como string vacío cuando HEAD está desacoplado en vez de caer a bl[0]. Se agregan handleCheckoutBranch y handleCreateBranch, se cablea onClick en cada item del listado y en el botón + de creación, y Enter en el input crea la rama. La rama activa se marca visualmente con y se expone como aria-current="true"; el botón + lleva aria-label. Los errores de git (uncommitted changes, nombre inválido, etc.) pasan por el flash existente.
  • Cuando currentBranch está vacío, el header del dropdown muestra git.branch.detached en itálica en vez del hardcoded "main" que había antes y que era igualmente engañoso.
  • apps/desktop/src/api/builtin.l10n.ts: agrega git.status.checkout_success y git.branch.detached (EN/ES).

Not in scope (by design):

  • No se expone un botón de borrado de ramas — queda para un issue aparte si se pide.
  • No se intenta resolver el estado de detached HEAD a un commit/tag (git rev-parse --short HEAD); mostrar el label explícito cubre el caso.

Issues

Copilot AI review requested due to automatic review settings April 19, 2026 05:41
The branch dropdown rendered branches but had no click handlers, so
switching branches did nothing. Current branch was set to the first
entry from `git branch` (alphabetical), not the actual HEAD, making
it appear out of sync with the working tree.

- get_git_branches now returns { branches, current } using
  `git symbolic-ref --short HEAD` for the real current branch
- Add git_checkout_branch and git_create_branch tauri commands
- Wire onClick on branch items and the create (+) button
- Mark the active branch in the dropdown

Closes TrixtyAI#35
@matiaspalmac matiaspalmac force-pushed the fix/branch-selection branch from 007cac7 to b0245fb Compare April 19, 2026 05:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Wires up branch selection and creation in the Git Explorer so the UI reflects the actual checked-out branch and users can switch/create branches from the dropdown.

Changes:

  • Extended get_git_branches to return both branches and the current (HEAD) branch.
  • Added new Tauri commands to checkout a branch and create+checkout a new branch.
  • Updated UI to make branch items clickable, support Enter / + for branch creation, and added a new localized success message.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
apps/desktop/src/api/tauri.ts Updates the typed invoke map for the new git branch APIs.
apps/desktop/src/api/builtin.l10n.ts Adds a localized “checkout success” message used by the UI.
apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx Hooks up branch switching/creation handlers and updates branch dropdown behavior.
apps/desktop/src-tauri/src/lib.rs Implements backend branch listing (incl. HEAD branch), checkout, and create branch commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx Outdated
Comment thread apps/desktop/src-tauri/src/lib.rs
Comment thread apps/desktop/src-tauri/src/lib.rs
Comment thread apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx Outdated
- Reject branch names starting with `-` to prevent option injection
  into `git switch` (e.g. `--orphan`, `--detach`).
- Use `git switch` / `git switch -c` instead of `git checkout` for
  clearer intent and no path-checkout ambiguity.
- Drop the `bl[0]` fallback for currentBranch so detached HEAD stays
  empty instead of impersonating the first branch alphabetically.
- Render `git.branch.detached` label when HEAD is detached, replacing
  the misleading hardcoded "main" fallback in the dropdown header.
- A11y: add `aria-current` on the active branch item and `aria-label`
  on the create-branch (+) icon button.
@jmaxdev jmaxdev merged commit 4179c74 into TrixtyAI:main Apr 19, 2026
4 checks passed
@matiaspalmac matiaspalmac deleted the fix/branch-selection branch April 20, 2026 22: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.

[Bug]: branch selection

3 participants