Proposal: make gogit checkout worktree-aware — switch a branch held by another worktree with a single command
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Go
- Stelle
- 19
- Fork
- 3
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di LinuxSuRen/gogit
-
Docs: replace the real-looking access token in README examples and fix build status help textsForse già presa @linuxsuren-fs l’ha presa 6 giorni fa. Apertadocumentation good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
LinuxSuRen/gogit#90 ·
-
Bug: --token file://… content is not trimmed, trailing newline breaks authenticationForse già presa @linuxsuren-fs l’ha presa 6 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
LinuxSuRen/gogit#87 ·
-
Bug: gogit checkout robustness: remotes[0] panic, wrong error message, empty version output, non-idempotent 0444 writesForse già presa @linuxsuren-fs l’ha presa 6 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
LinuxSuRen/gogit#86 ·
-
Bug: gogit checkout fails on repositories whose default branch is not masterForse già presa @linuxsuren-fs l’ha presa 6 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
LinuxSuRen/gogit#85 ·
-
Bug: DingTalk notification builds JSON by string concatenation, echoes the token, leaks resp.Body and swallows errorsForse già presa @linuxsuren-fs l’ha presa 6 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
LinuxSuRen/gogit#84 ·
Tutte le issue di LinuxSuRen/gogit
Issue simili
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
erkamyaman/rust-anything#371 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
aminueza/terraform-provider-minio#1406 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
kubernetes/kubeadm#3339 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno