Renaming a stacked branch with `git branch -m` strands the stack: metadata keeps the old name
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- git, go
- Área
- cli, developer-experience
Línea de trabajo
Comienza en cmd/utils.go con el error del branch actual y luego sigue resolveStack, FindAllStacksForBranch y Stack.Contains en internal/stack/stack.go. Revisa el uso de git.BranchExists y el manejo de renombrados en internal/modify/apply.go, incluida la reparación basada en el reflog descrita en el issue. El trabajo estará terminado cuando un branch renombrado externamente se diagnostique y pueda repararse o eliminarse sin requerir un número de stack.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
gh stack matches the current branch against .git/gh-stack by exact string
(resolveStack → FindAllStacksForBranch → Stack.Contains, cmd/utils.go:395,
internal/stack/stack.go:241). Renaming a stacked branch with git branch -m is not
observed, so the stack file keeps pointing at a name that no longer exists and every
stack command bails out with the same generic message.
gh stack modify already renames a branch in git and in the stack file together
(internal/modify/apply.go:190-228, verified: both .git/gh-stack and the git branch are
updated), so the invariant is understood. This issue is about a rename performed outside
gh-stack, which is how most people rename a branch.
Related but distinct: #137 reaches the same stranded state through sync --prune
(branch deleted, stack entry left behind), and #193 is the same family of "git operations
performed outside gh-stack aren't observed".
Reproduction
Requires an origin remote, but the repository need not exist.
git init repro && cd repro
git commit --allow-empty -m initial
git remote add origin https://github.com/you/does-not-exist.git
git switch -c feat/test
git commit --allow-empty -m wip
gh stack init feat/test # ✓ Adopted 1 branch: main ← feat/test
gh stack view --short # ✓ works
git branch -m feat/test-1
gh stack view # ✗ broken from here on
gh stack init with no arguments errors with "interactive input required", so the branch
name is passed explicitly to keep the repro scriptable.
Observed
.git/gh-stack is byte-identical before and after the rename; it still records
"branch": "feat/test".
| Command | Output |
|---|---|
gh stack view |
✗ current branch "feat/test-1" is not part of a stack |
gh stack add feat/test-2 |
same |
gh stack unstack / unstack --local |
same |
gh stack checkout feat/test (old name) |
✗ failed to checkout feat/test: failed to run git: error: pathspec 'feat/test' did not match any file(s) known to git |
gh stack checkout feat/test-1 (new name) |
✗ no locally tracked stack found for "feat/test-1" |
gh stack unstack <n> --local would remove the entry, but a stack that has not been
submitted has no stack number (Number int \json:"number,omitempty"``,
internal/stack/stack.go:46), so it cannot be targeted:
$ gh stack unstack 1 --local
✗ stack #1 is not tracked locally
With no gh stack list (#150) and an interactive-only checkout picker, the ways out are
renaming the branch back (verified: this fully restores the stack) or editing
.git/gh-stack by hand.
Expected
-
Diagnose instead of denying. Before printing "is not part of a stack"
(cmd/utils.go:234-243), check whether a recorded stack references a branch that no
longer exists.git.BranchExistsis already used throughout (cmd/sync.go:413,
cmd/modify.go:315, …).checkoutshould also stop surfacing git's raw
pathspec ... did not matcherror. -
Leave an escape hatch. Removing or repairing a stack whose branches are missing
should not require a stack number — this is the part #137 also runs into. -
Offer to repair. git records the rename in the reflog:
feat/test-1@{0}: Branch: renamed refs/heads/feat/test to refs/heads/feat/test-1so the stack file can be updated after confirming with the user. Reflog entries expire,
so this complements 1 rather than replacing it.
I have a patch implementing 1 and 3 and will open a PR referencing this issue.
Environment
gh stackv0.1.0- macOS 24.6.0 (Darwin, arm64)
- Lenguaje dominante
- Go
- Estrellas
- 1.5k
- Forks
- 73
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 7
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 github/gh-stack
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
feature request topic: cli - general
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
feature request topic: auto-merge
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
bug topic: docs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
Todos los issues de github/gh-stack
Issues similares
-
textual definition
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
geneontology/go-ontology#32653 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
-
needs design
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Priority/High ready-for-agent Severity/Major Type/Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100