@@ -26,6 +26,7 @@ type RenameOptions struct {
2626 Config func () (config.Config , error )
2727 BaseRepo func () (ghrepo.Interface , error )
2828 Remotes func () (context.Remotes , error )
29+ HasRepoOverride bool
2930 newRepoSelector string
3031}
3132
@@ -40,7 +41,6 @@ func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co
4041 opts := & RenameOptions {
4142 IO : f .IOStreams ,
4243 HttpClient : f .HttpClient ,
43- BaseRepo : f .BaseRepo ,
4444 Remotes : f .Remotes ,
4545 Config : f .Config ,
4646 }
@@ -57,8 +57,10 @@ func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co
5757 With '-R', and two arguments the given repository is replaced with the new name` ),
5858 Args : cobra .MaximumNArgs (1 ),
5959 RunE : func (cmd * cobra.Command , args []string ) error {
60+ opts .BaseRepo = f .BaseRepo
61+ opts .HasRepoOverride = cmd .Flags ().Changed ("repo" )
62+
6063 if len (args ) > 0 {
61- opts .BaseRepo = f .BaseRepo
6264 opts .newRepoSelector = args [0 ]
6365 } else if ! opts .IO .CanPrompt () {
6466 return & cmdutil.FlagError {
@@ -87,17 +89,18 @@ func renameRun(opts *RenameOptions) error {
8789 var input renameRepo
8890 var newRepo ghrepo.Interface
8991 var baseRemote * context.Remote
92+ remoteUpdateError := false
9093 newRepoName := opts .newRepoSelector
9194
9295 currRepo , err := opts .BaseRepo ()
9396 if err != nil {
9497 return err
9598 }
9699
97- if opts . newRepoSelector == "" {
100+ if newRepoName == "" {
98101 err = prompt .SurveyAskOne (
99102 & survey.Input {
100- Message : "Rename current repo to: " ,
103+ Message : fmt . Sprintf ( "Rename %s to: " , currRepo . RepoOwner () + "/" + currRepo . RepoName ()) ,
101104 },
102105 & newRepoName ,
103106 )
@@ -120,39 +123,29 @@ func renameRun(opts *RenameOptions) error {
120123 return fmt .Errorf ("API called failed: %s, please check your parameters" , err )
121124 }
122125
123- if opts .newRepoSelector == "" {
126+ if ! opts .HasRepoOverride {
124127 cfg , err := opts .Config ()
125128 if err != nil {
126129 return err
127130 }
128-
129- protocol , err := cfg .Get (currRepo .RepoHost (), "git_protocol" )
130- if err != nil {
131- return err
132- }
133-
134- remotes , err := opts .Remotes ()
135- if err != nil {
136- return err
137- }
138-
139- baseRemote , err = remotes .FindByRepo (currRepo .RepoOwner (), currRepo .RepoName ())
140- if err != nil {
141- return err
142- }
143-
131+
132+ protocol , _ := cfg .Get (currRepo .RepoHost (), "git_protocol" )
133+ remotes , _ := opts .Remotes ()
134+ baseRemote , _ = remotes .FindByRepo (currRepo .RepoOwner (), currRepo .RepoName ())
144135 remoteURL := ghrepo .FormatRemoteURL (newRepo , protocol )
145136 err = git .UpdateRemoteURL (baseRemote .Name , remoteURL )
146137 if err != nil {
147- return err
138+ cs := opts .IO .ColorScheme ()
139+ remoteUpdateError = true
140+ fmt .Fprintf (opts .IO .ErrOut , "%s warning: unable to update remote '%s' \n " , cs .WarningIcon (), err )
148141 }
149142 }
150143
151144 if opts .IO .IsStdoutTTY () {
152145 cs := opts .IO .ColorScheme ()
153146 fmt .Fprintf (opts .IO .Out , "%s Renamed repository %s\n " , cs .SuccessIcon (), input .RepoOwner + "/" + input .Name )
154- if opts .newRepoSelector == "" {
155- fmt .Fprintf (opts .IO .Out , "%s Updated the %q remote" , cs .SuccessIcon (), baseRemote .Name )
147+ if ! opts .HasRepoOverride && ! remoteUpdateError {
148+ fmt .Fprintf (opts .IO .Out , "%s Updated the %q remote \n " , cs .SuccessIcon (), baseRemote .Name )
156149 }
157150 }
158151
0 commit comments