@@ -127,7 +127,7 @@ func runClone(cloneURL string, args []string) (target string, err error) {
127127func repoClone (cmd * cobra.Command , args []string ) error {
128128 cloneURL := args [0 ]
129129 if ! strings .Contains (cloneURL , ":" ) {
130- cloneURL = fmt . Sprintf ( "https://github.com/%s.git" , cloneURL )
130+ cloneURL = formatRemoteURL ( cmd , cloneURL )
131131 }
132132
133133 var repo ghrepo.Interface
@@ -158,7 +158,7 @@ func repoClone(cmd *cobra.Command, args []string) error {
158158 }
159159
160160 if parentRepo != nil {
161- err := addUpstreamRemote (parentRepo , cloneDir )
161+ err := addUpstreamRemote (cmd , parentRepo , cloneDir )
162162 if err != nil {
163163 return err
164164 }
@@ -167,9 +167,8 @@ func repoClone(cmd *cobra.Command, args []string) error {
167167 return nil
168168}
169169
170- func addUpstreamRemote (parentRepo ghrepo.Interface , cloneDir string ) error {
171- // TODO: support SSH remote URLs
172- upstreamURL := fmt .Sprintf ("https://github.com/%s.git" , ghrepo .FullName (parentRepo ))
170+ func addUpstreamRemote (cmd * cobra.Command , parentRepo ghrepo.Interface , cloneDir string ) error {
171+ upstreamURL := formatRemoteURL (cmd , ghrepo .FullName (parentRepo ))
173172
174173 cloneCmd := git .GitCommand ("-C" , cloneDir , "remote" , "add" , "-f" , "upstream" , upstreamURL )
175174 cloneCmd .Stdout = os .Stdout
@@ -267,14 +266,10 @@ func repoCreate(cmd *cobra.Command, args []string) error {
267266 fmt .Fprintln (out , repo .URL )
268267 }
269268
270- remoteURL := repo . URL + ".git"
269+ remoteURL := formatRemoteURL ( cmd , ghrepo . FullName ( repo ))
271270
272271 if projectDirErr == nil {
273- // TODO: use git.AddRemote
274- remoteAdd := git .GitCommand ("remote" , "add" , "origin" , remoteURL )
275- remoteAdd .Stdout = os .Stdout
276- remoteAdd .Stderr = os .Stderr
277- err = run .PrepareCmd (remoteAdd ).Run ()
272+ _ , err = git .AddRemote ("origin" , remoteURL )
278273 if err != nil {
279274 return err
280275 }
@@ -338,15 +333,15 @@ func repoFork(cmd *cobra.Command, args []string) error {
338333 return fmt .Errorf ("unable to create client: %w" , err )
339334 }
340335
341- var toFork ghrepo.Interface
336+ var repoToFork ghrepo.Interface
342337 inParent := false // whether or not we're forking the repo we're currently "in"
343338 if len (args ) == 0 {
344339 baseRepo , err := determineBaseRepo (cmd , ctx )
345340 if err != nil {
346341 return fmt .Errorf ("unable to determine base repository: %w" , err )
347342 }
348343 inParent = true
349- toFork = baseRepo
344+ repoToFork = baseRepo
350345 } else {
351346 repoArg := args [0 ]
352347
@@ -356,14 +351,23 @@ func repoFork(cmd *cobra.Command, args []string) error {
356351 return fmt .Errorf ("did not understand argument: %w" , err )
357352 }
358353
359- toFork , err = ghrepo .FromURL (parsedURL )
354+ repoToFork , err = ghrepo .FromURL (parsedURL )
360355 if err != nil {
361356 return fmt .Errorf ("did not understand argument: %w" , err )
362357 }
363358
359+ } else if strings .HasPrefix (repoArg , "git@" ) {
360+ parsedURL , err := git .ParseURL (repoArg )
361+ if err != nil {
362+ return fmt .Errorf ("did not understand argument: %w" , err )
363+ }
364+ repoToFork , err = ghrepo .FromURL (parsedURL )
365+ if err != nil {
366+ return fmt .Errorf ("did not understand argument: %w" , err )
367+ }
364368 } else {
365- toFork = ghrepo .FromFullName (repoArg )
366- if toFork .RepoName () == "" || toFork .RepoOwner () == "" {
369+ repoToFork = ghrepo .FromFullName (repoArg )
370+ if repoToFork .RepoName () == "" || repoToFork .RepoOwner () == "" {
367371 return fmt .Errorf ("could not parse owner or repo name from %s" , repoArg )
368372 }
369373 }
@@ -372,12 +376,12 @@ func repoFork(cmd *cobra.Command, args []string) error {
372376 greenCheck := utils .Green ("✓" )
373377 out := colorableOut (cmd )
374378 s := utils .Spinner (out )
375- loading := utils .Gray ("Forking " ) + utils .Bold (utils .Gray (ghrepo .FullName (toFork ))) + utils .Gray ("..." )
379+ loading := utils .Gray ("Forking " ) + utils .Bold (utils .Gray (ghrepo .FullName (repoToFork ))) + utils .Gray ("..." )
376380 s .Suffix = " " + loading
377381 s .FinalMSG = utils .Gray (fmt .Sprintf ("- %s\n " , loading ))
378382 s .Start ()
379383
380- forkedRepo , err := api .ForkRepo (apiClient , toFork )
384+ forkedRepo , err := api .ForkRepo (apiClient , repoToFork )
381385 if err != nil {
382386 s .Stop ()
383387 return fmt .Errorf ("failed to fork: %w" , err )
@@ -437,7 +441,9 @@ func repoFork(cmd *cobra.Command, args []string) error {
437441 fmt .Fprintf (out , "%s Renamed %s remote to %s\n " , greenCheck , utils .Bold (remoteName ), utils .Bold (renameTarget ))
438442 }
439443
440- _ , err = git .AddRemote (remoteName , forkedRepo .CloneURL )
444+ forkedRepoCloneURL := formatRemoteURL (cmd , ghrepo .FullName (forkedRepo ))
445+
446+ _ , err = git .AddRemote (remoteName , forkedRepoCloneURL )
441447 if err != nil {
442448 return fmt .Errorf ("failed to add remote: %w" , err )
443449 }
@@ -458,7 +464,7 @@ func repoFork(cmd *cobra.Command, args []string) error {
458464 return fmt .Errorf ("failed to clone fork: %w" , err )
459465 }
460466
461- err = addUpstreamRemote (toFork , cloneDir )
467+ err = addUpstreamRemote (cmd , repoToFork , cloneDir )
462468 if err != nil {
463469 return err
464470 }
0 commit comments