Proposal: make gogit checkout worktree-aware — switch a branch held by another worktree with a single command
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start in cmd/checkout.go around runE (the remotes[0] panic at line 100) and trace how the checkout target is opened. Reproduce both behaviors from the body: silent double-checkout in the main worktree and the panic inside a linked worktree, then inspect how .git/worktrees/*/HEAD can be read directly or whether the go-git bump in #76 helps. Done means acceptance scenarios 1-4 pass and the default error names the holding worktree before switching.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Background
With git worktree, a branch may only be checked out in one worktree at a time. Switching to a branch that another worktree holds is refused by native git:
$ git checkout feature
fatal: 'feature' is already checked out at '/path/to/wt-feature'
Getting unblocked today takes multiple manual steps: walk to the other worktree and git switch --detach, come back and retry — or use git checkout --ignore-other-worktrees, which drops the safety and leaves two worktrees on the same branch (risk of divergent commits), or git worktree add yet another directory.
gogit checkout aims to be the friendly front door for branch/tag/PR checkouts, so it would be great if it could resolve this situation with a single command.
What gogit does today (verified on master 198a18f)
Both behaviors are problematic:
-
In the main worktree it silently breaks the invariant.
gogit checkout --branch featuresucceeds withSwitched to branch 'feature'even while another worktree still holdsfeature:/tmp/wt-test/main 4971cf4 [feature] /tmp/wt-test/wt-feature 4971cf4 [feature]go-git does not implement the per-worktree exclusivity check, so gogit creates exactly the state that
--ignore-other-worktreesproduces — two worktrees that can commit independently to the same branch — without any warning. -
Inside a linked worktree it does not work at all. Running
gogit checkout --branch masterinside the worktree directory (where.gitis a file, not a directory) panics:panic: runtime error: index out of range [0] with length 0 github.com/linuxsuren/gogit/cmd.(*checkoutOption).runE(...) cmd/checkout.go:100(that line is the
remotes[0]access also tracked in #86; in a linked worktree go-git opens the worktree gitdir without the main config, so the remote list is empty).
Proposal
Make gogit checkout worktree-aware — one command, safe by default:
-
Detection: before switching, read
.git/worktrees/*/HEAD(or the go-git equivalent) to find whether the target branch is already checked out elsewhere. -
Default: fail with an actionable message instead of silently breaking the invariant, e.g.
branch 'feature' is already checked out at /path/to/wt-feature hint: retry with --detach-other to detach it there and switch here, or use --worktree to open it in a new worktree -
One-command escape hatches:
--detach-other(name up for discussion): detach HEAD in the holding worktree (same commit, working tree untouched), then switch here — the safe version of--ignore-other-worktrees;--worktree <dir>: create and enter a linked worktree for the target branch in one step (git worktree add <dir> <branch>equivalent), which is the workflow git actually recommends.
-
Fix running inside a linked worktree: resolve the
.gitfile pointer sogogit checkoutworks from a worktree directory, not only from the main checkout.
Implementation notes
- go-git v5.4.2 has very limited worktree support; the go-git bump pending in #76 may help, otherwise the
.git/worktrees/*/HEADfiles can be read directly. - #86 (
remotes[0]panic) needs fixing regardless for worktree dirs.
Acceptance scenarios
Using a repo with main on master and a linked worktree on feature:
gogit checkout --branch featureinmain→ clear error with the other worktree's path (no silent double checkout)gogit checkout --branch feature --detach-otherinmain→ switches here; the other worktree is left detached at the same commitgogit checkout --branch feature --worktree ../wt2→ new linked worktree created and reportedgogit checkout --branch masterinside a linked worktree → works instead of panicking
- Lenguaje dominante
- Go
- Estrellas
- 19
- Forks
- 3
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de LinuxSuRen/gogit
-
Docs: replace the real-looking access token in README examples and fix build status help textsPosiblemente ocupada @linuxsuren-fs la tomó hace 7 días. Abiertodocumentation good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
LinuxSuRen/gogit#90 ·
-
Bug: --token file://… content is not trimmed, trailing newline breaks authenticationPosiblemente ocupada @linuxsuren-fs la tomó hace 7 días. Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
LinuxSuRen/gogit#87 ·
-
Bug: gogit checkout robustness: remotes[0] panic, wrong error message, empty version output, non-idempotent 0444 writesPosiblemente ocupada @linuxsuren-fs la tomó hace 7 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
LinuxSuRen/gogit#86 ·
-
Bug: gogit checkout fails on repositories whose default branch is not masterPosiblemente ocupada @linuxsuren-fs la tomó hace 7 días. Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
LinuxSuRen/gogit#85 ·
-
Bug: DingTalk notification builds JSON by string concatenation, echoes the token, leaks resp.Body and swallows errorsPosiblemente ocupada @linuxsuren-fs la tomó hace 7 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
LinuxSuRen/gogit#84 ·
Todos los issues de LinuxSuRen/gogit
Issues similares
-
Generated cask uses deprecated `postflight` stanza; Homebrew 7 warns on every commandPosiblemente ocupada @k4kratik la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sachincool/cruft#4 ·
-
help wanted kind/good-first-issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
knative/func#4191 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
VictoriaMetrics/VictoriaLogs#1965 ·
Los mantenedores suelen responder en 1 día
-
kind/bug sig/ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
kubermatic/dashboard#8540 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Sign-off cards drift between formats; write down one card formatPosiblemente ocupada @keyxmakerx la tomó hoy. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
keyxmakerx/Chronicle#2795 ·
Los mantenedores suelen responder en 1 día