Merge pull request #10364 from timrogers/timrogers/fix-10034
Error when `gh repo rename` is used with a new repo name that contains an owner
This commit is contained in:
commit
9255658ccc
3 changed files with 30 additions and 0 deletions
9
acceptance/testdata/repo/repo-rename-transfer-ownership.txtar
vendored
Normal file
9
acceptance/testdata/repo/repo-rename-transfer-ownership.txtar
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Attempt to rename the repo with a slash in the name
|
||||
! exec gh repo rename $ORG/new-name --repo=$ORG/$SCRIPT_NAME-$RANDOM_STRING --yes
|
||||
stderr 'New repository name cannot contain '/' character - to transfer a repository to a new owner, you must follow additional steps on GitHub.com. For more information on transferring repository ownership, see <https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>.'
|
||||
|
||||
# Defer repo deletion
|
||||
defer gh repo delete $ORG/$SCRIPT_NAME-$RANDOM_STRING --yes
|
||||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/cli/cli/v2/api"
|
||||
|
|
@ -124,6 +125,10 @@ func renameRun(opts *RenameOptions) error {
|
|||
}
|
||||
}
|
||||
|
||||
if strings.Contains(newRepoName, "/") {
|
||||
return fmt.Errorf("New repository name cannot contain '/' character - to transfer a repository to a new owner, you must follow additional steps on GitHub.com. For more information on transferring repository ownership, see <https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>.")
|
||||
}
|
||||
|
||||
if opts.DoConfirm {
|
||||
var confirmed bool
|
||||
if confirmed, err = opts.Prompter.Confirm(fmt.Sprintf(
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ func TestRenameRun(t *testing.T) {
|
|||
promptStubs func(*prompter.MockPrompter)
|
||||
wantOut string
|
||||
tty bool
|
||||
wantErr bool
|
||||
errMsg string
|
||||
}{
|
||||
{
|
||||
name: "none argument",
|
||||
|
|
@ -217,6 +219,16 @@ func TestRenameRun(t *testing.T) {
|
|||
},
|
||||
wantOut: "",
|
||||
},
|
||||
|
||||
{
|
||||
name: "error on name with slash",
|
||||
tty: true,
|
||||
opts: RenameOptions{
|
||||
newRepoSelector: "org/new-name",
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "New repository name cannot contain '/' character - to transfer a repository to a new owner, you must follow additional steps on GitHub.com. For more information on transferring repository ownership, see <https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository>.",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testCases {
|
||||
|
|
@ -268,6 +280,10 @@ func TestRenameRun(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer reg.Verify(t)
|
||||
err := renameRun(&tt.opts)
|
||||
if tt.wantErr {
|
||||
assert.EqualError(t, err, tt.errMsg)
|
||||
return
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.wantOut, stdout.String())
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue