@@ -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 }
@@ -361,6 +356,15 @@ func repoFork(cmd *cobra.Command, args []string) error {
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+ toFork , err = ghrepo .FromURL (parsedURL )
365+ if err != nil {
366+ return fmt .Errorf ("did not understand argument: %w" , err )
367+ }
364368 } else {
365369 toFork = ghrepo .FromFullName (repoArg )
366370 if toFork .RepoName () == "" || toFork .RepoOwner () == "" {
@@ -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 , toFork , cloneDir )
462468 if err != nil {
463469 return err
464470 }
0 commit comments