Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions cmd/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (

// forkCmd represents the fork command
var forkCmd = &cobra.Command{
Use: "fork [upstream-to-fork]",
Use: "fork [remote|upstream-to-fork]",
Short: "Fork a remote repository on GitLab and add as remote",
Long: ``,
Args: cobra.MaximumNArgs(1),
Expand All @@ -47,15 +47,33 @@ var forkCmd = &cobra.Command{
}
}

remote, project := "", ""
if len(args) == 1 {
forkToUpstream(args[0])
if ok, _ := git.IsRemote(args[0]); ok {
remote = args[0]
} else {
project = args[0]
}
}

if project != "" {
forkToUpstream(project)
return
}
forkFromOrigin()

if remote == "" {
remote = "origin"
}

project, err := git.PathWithNameSpace(remote)
if err != nil {
log.Fatal(err)
}
forkFromOrigin(project)
},
}

func forkFromOrigin() {
func forkFromOrigin(project string) {
// Check for custom target namespace
remote := lab.User()
if targetData.group != "" {
Expand All @@ -82,11 +100,6 @@ func forkFromOrigin() {
return
}

project, err := git.PathWithNameSpace("origin")
if err != nil {
log.Fatal(err)
}

forkRemoteURL, err := lab.Fork(project, forkOpts, useHTTP, waitFork)
if err != nil {
if err.Error() == "not finished" {
Expand Down