Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@digitalby

Description

@digitalby
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIa request to improve CLIgh-reporelating to the gh repo commandrelating to the gh repo command

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.