hub/commands/fork.go

35 строки
763 B
Go
Исходник Обычный вид История

2013-06-11 04:10:40 +04:00
package commands
import (
2013-06-11 18:46:48 +04:00
"fmt"
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
2013-06-11 04:10:40 +04:00
)
var cmdFork = &Command{
Run: fork,
Usage: "fork [--no-remote]",
Short: "Make a fork of a remote repository on GitHub and add as remote",
Long: `Forks the original project (referenced by "origin" remote) on GitHub and
adds a new remote for it under your username.
`,
}
var flagForkNoRemote bool
func init() {
cmdFork.Flag.BoolVar(&flagForkNoRemote, "no-remote", false, "")
}
2013-06-26 19:48:34 +04:00
func fork(cmd *Command, args *Args) {
2013-06-11 18:46:48 +04:00
gh := github.New()
project := gh.Project
2013-06-11 04:10:40 +04:00
2013-06-11 18:46:48 +04:00
newRemote, err := gh.ForkRepository(project.Name, project.Owner, flagForkNoRemote)
utils.Check(err)
2013-06-11 04:10:40 +04:00
2013-06-11 18:46:48 +04:00
if !flagForkNoRemote && newRemote != "" {
fmt.Printf("New remote: %s\n", newRemote)
}
2013-06-11 04:10:40 +04:00
}