fix: wire branch selection and creation in git explorer#45
Merged
jmaxdev merged 3 commits intoTrixtyAI:mainfrom Apr 19, 2026
Merged
fix: wire branch selection and creation in git explorer#45jmaxdev merged 3 commits intoTrixtyAI:mainfrom
jmaxdev merged 3 commits intoTrixtyAI:mainfrom
Conversation
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
007cac7 to
b0245fb
Compare
There was a problem hiding this comment.
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_branchesto return bothbranchesand thecurrent(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.
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 delgit 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_branchesahora devuelve{ branches, current }.currentse resuelve víagit symbolic-ref --short HEADy cae a string vacío cuando HEAD está desacoplado, en vez de propagar un error. Se agregangit_checkout_branch(path, branch)ygit_create_branch(path, branch), ambos usandogit switch/git switch -c(2.23+, semántica específica de ramas — evita la ambigüedad decheckoutcon path-checkout). Ambos comandos validan el nombre convalidate_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 deget_git_branchesy agrega las firmas de los dos comandos nuevos.apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx:refreshGitya consume{ branches, current }directamente;currentBranchqueda como string vacío cuando HEAD está desacoplado en vez de caer abl[0]. Se agreganhandleCheckoutBranchyhandleCreateBranch, se cableaonClicken 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 comoaria-current="true"; el botón+llevaaria-label. Los errores de git (uncommitted changes, nombre inválido, etc.) pasan por elflashexistente.currentBranchestá vacío, el header del dropdown muestragit.branch.detacheden itálica en vez del hardcoded"main"que había antes y que era igualmente engañoso.apps/desktop/src/api/builtin.l10n.ts: agregagit.status.checkout_successygit.branch.detached(EN/ES).Not in scope (by design):
git rev-parse --short HEAD); mostrar el label explícito cubre el caso.Issues