Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

gh repo rename: interactive prompt causes owner-prefix confusion, error message talks about transfers

未关闭 适合新手
#13,034 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
半天
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
github, go
领域
cli

调研方向

从 pkg/cmd/repo/rename/rename.go 开始,重点关注交互式提示和共享的仓库名称验证代码块。确认提示说明了带 owner 前缀的格式、相同 owner 的前缀得到一致处理、不同 owner 的输入提供了可执行的指导,并且现有的非交互路径不受影响。

由索引模型根据 Issue 内容生成。

描述

enhancement gh-repo stale

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cli/cli 的其他 Issue

查看 cli/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。