@@ -2,13 +2,14 @@ package cmd
22
33import (
44 "fmt"
5+ "strconv"
6+
57 "github.com/barrettj12/jit/common"
68 "github.com/barrettj12/jit/common/git"
79 "github.com/barrettj12/jit/common/path"
810 "github.com/barrettj12/jit/common/types"
911 "github.com/barrettj12/jit/common/url"
1012 "github.com/spf13/cobra"
11- "strconv"
1213)
1314
1415var cloneDocs = `
@@ -45,12 +46,12 @@ func newCloneCmd() *cobra.Command {
4546// Clone clones the provided repo, using the workflow described in
4647// https://morgan.cugerone.com/blog/how-to-use-git-worktree-and-in-a-clean-way/
4748func Clone (cmd * cobra.Command , args []string ) error {
48- githubRepo := url .GitHubURL (args ... )
49- user := githubRepo .Owner ()
49+ repoURL := url .URL (args ... )
50+ user := repoURL .Owner ()
5051 if user == "" {
5152 return fmt .Errorf ("must specify a user to clone repo from" )
5253 }
53- repo := githubRepo .RepoName ()
54+ repo := repoURL .RepoName ()
5455 if repo == "" {
5556 return fmt .Errorf ("must specify a repo to clone" )
5657 }
@@ -64,7 +65,7 @@ func Clone(cmd *cobra.Command, args []string) error {
6465 // Clone the repo
6566 remote := types .RemoteName (user )
6667 err = git .Clone (git.CloneArgs {
67- Repo : githubRepo ,
68+ Repo : repoURL ,
6869 CloneDir : path .GitFolderPath (cloneDir ),
6970 Bare : true ,
7071 OriginName : remote ,
@@ -97,11 +98,14 @@ Create new branches using
9798
9899 var shouldFork bool
99100 if forkFlagVal == "" {
100- // The user did not specify when typing the command whether we should
101- // fork the repo or not. Ask them.
102- shouldFork , err = confirm ("Create a fork" )
103- if err != nil {
104- return err
101+ // Only ask to fork if this is a GitHub repo
102+ if repoURL .HostedBy () == url .GitHub {
103+ // The user did not specify when typing the command whether we should
104+ // fork the repo or not. Ask them.
105+ shouldFork , err = confirm ("Create a fork" )
106+ if err != nil {
107+ return err
108+ }
105109 }
106110 } else {
107111 shouldFork , err = strconv .ParseBool (forkFlagVal )
@@ -111,9 +115,13 @@ Create new branches using
111115 }
112116
113117 if shouldFork {
114- err = fork (cloneDir , user , repo )
115- if err != nil {
116- return err
118+ if repoURL .HostedBy () == url .GitHub {
119+ err = fork (cloneDir , user , repo )
120+ if err != nil {
121+ return err
122+ }
123+ } else {
124+ fmt .Printf ("WARNING: don't know how to fork for repo type %q, skipping\n " , repoURL .HostedBy ())
117125 }
118126 }
119127
0 commit comments