gh repo rename: interactive prompt causes owner-prefix confusion, error message talks about transfers
还没有人认领这个 Issue。
评估
调研方向
从 pkg/cmd/repo/rename/rename.go 开始,重点关注交互式提示和共享的仓库名称验证代码块。确认提示说明了带 owner 前缀的格式、相同 owner 的前缀得到一致处理、不同 owner 的输入提供了可执行的指导,并且现有的非交互路径不受影响。
由索引模型根据 Issue 内容生成。
描述
gh repo rename interactive prompt causes owner-prefix confusion
Description
When renaming a repository interactively, the prompt shows the current repository's full name
(owner/repo) in a format that naturally leads users to type the new name in the same format
(owner/new-name). However, the command only accepts the bare name (new-name).
The resulting error message is misleading: it warns about transferring the repository to a new
owner, which is unrelated to what the user was trying to do.
Steps to reproduce
$ gh repo rename
Rename digitalby/raycast-input-layout-switch-poc to: digitalby/raycast-input-layout-switch
error: New repository name cannot contain '/' character - to transfer a repository to a new owner,
see <https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>.
Expected behavior
One of:
- The prompt should hint at the expected format, so users don't type the owner prefix in the
first place. - Or, if the user types their own owner prefix, the command should strip it and proceed - since
the intent is unambiguous. - The error message, when shown, should explain what to type instead of pointing to a
repository-transfer doc page.
Actual behavior
The user gets an error that talks about repository transfers, with no indication of what the
correct input format is.
Proposed fix
Three-part change to pkg/cmd/repo/rename/rename.go:
1. Reword the prompt
// Before
opts.Prompter.Input(fmt.Sprintf("Rename %s to:", ghrepo.FullName(currRepo)), "")
// After
opts.Prompter.Input(fmt.Sprintf("New name for %s (without owner prefix):", ghrepo.FullName(currRepo)), "")
2. Smart-strip the same-owner prefix instead of rejecting it
// Before
if strings.Contains(newRepoName, "/") {
return fmt.Errorf("New repository name cannot contain '/' character - ...")
}
// After
if strings.Contains(newRepoName, "/") {
parts := strings.SplitN(newRepoName, "/", 2)
if strings.EqualFold(parts[0], currRepo.RepoOwner()) {
// User typed their own owner prefix - strip it and proceed
newRepoName = parts[1]
fmt.Fprintf(opts.IO.ErrOut, "! Owner prefix %q stripped - renaming to %q\n", parts[0], newRepoName)
} else {
return fmt.Errorf(
"to rename, enter only the new repository name without an owner prefix.\n" +
"To transfer this repository to a different owner, visit GitHub.com:\n" +
"<https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>",
)
}
}
3. Result
Same-owner prefix:
$ gh repo rename
New name for digitalby/poc (without owner prefix): digitalby/new-name
! Owner prefix "digitalby/" stripped - renaming to "new-name"
Renamed repository digitalby/poc to digitalby/new-name
Different-owner prefix (clear, actionable error):
$ gh repo rename
New name for digitalby/poc (without owner prefix): otherorg/new-name
error: to rename, enter only the new repository name without an owner prefix.
To transfer this repository to a different owner, visit GitHub.com:
<https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>
Notes
- The non-interactive path (
gh repo rename new-name) is unaffected - it works correctly today. - The same validation block handles both interactive and argument-provided names, so the fix
covers both paths. - Owner comparison uses case-insensitive matching (
strings.EqualFold) since GitHub usernames
are case-insensitive. - This was previously partially addressed by PR #10044 (help text) and PR #10364 (slash validation),
but the interactive UX gap remains.
- 主要语言
- Go
- 星标
- 46.3k
- 派生
- 9.1k
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 76
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cli/cli 的其他 Issue
-
enhancement
难度 1/5 1 小时以内 新手友好度 92/100
-
more-info-needed needs-triage
难度 1/5 1 小时以内 新手友好度 78/100
-
bug gh-pr priority-2
难度 2/5 1-3 小时 新手友好度 84/100
-
bug gh-pr priority-2
难度 2/5 1-3 小时 新手友好度 88/100
-
bug gh-auth priority-3
难度 2/5 1-3 小时 新手友好度 78/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
santhosh-tekuri/jsonschema#276 ·