2525
2626// forkCmd represents the fork command
2727var forkCmd = & cobra.Command {
28- Use : "fork [upstream-to-fork]" ,
28+ Use : "fork [remote| upstream-to-fork]" ,
2929 Short : "Fork a remote repository on GitLab and add as remote" ,
3030 Long : `` ,
3131 Args : cobra .MaximumNArgs (1 ),
@@ -47,15 +47,33 @@ var forkCmd = &cobra.Command{
4747 }
4848 }
4949
50+ remote , project := "" , ""
5051 if len (args ) == 1 {
51- forkToUpstream (args [0 ])
52+ if ok , _ := git .IsRemote (args [0 ]); ok {
53+ remote = args [0 ]
54+ } else {
55+ project = args [0 ]
56+ }
57+ }
58+
59+ if project != "" {
60+ forkToUpstream (project )
5261 return
5362 }
54- forkFromOrigin ()
63+
64+ if remote == "" {
65+ remote = "origin"
66+ }
67+
68+ project , err := git .PathWithNameSpace (remote )
69+ if err != nil {
70+ log .Fatal (err )
71+ }
72+ forkFromOrigin (project )
5573 },
5674}
5775
58- func forkFromOrigin () {
76+ func forkFromOrigin (project string ) {
5977 // Check for custom target namespace
6078 remote := lab .User ()
6179 if targetData .group != "" {
@@ -82,11 +100,6 @@ func forkFromOrigin() {
82100 return
83101 }
84102
85- project , err := git .PathWithNameSpace ("origin" )
86- if err != nil {
87- log .Fatal (err )
88- }
89-
90103 forkRemoteURL , err := lab .Fork (project , forkOpts , useHTTP , waitFork )
91104 if err != nil {
92105 if err .Error () == "not finished" {
0 commit comments