-
Notifications
You must be signed in to change notification settings - Fork 8.2k
gh repo rename: interactive prompt causes owner-prefix confusion, error message talks about transfers #13034
Copy link
Copy link
Open
Labels
enhancementa request to improve CLIa request to improve CLIgh-reporelating to the gh repo commandrelating to the gh repo command
Description
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
gh repo renamehelp text clarifies new repo name should not include owner #10044 (help text) and PR Error whengh repo renameis used with a new repo name that contains an owner #10364 (slash validation),
but the interactive UX gap remains.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementa request to improve CLIa request to improve CLIgh-reporelating to the gh repo commandrelating to the gh repo command
Type
Fields
Give feedbackNo fields configured for issues without a type.