2013-06-13 18:11:05 +04:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2013-06-18 00:35:02 +04:00
|
|
|
"github.com/jingweno/gh/git"
|
2013-06-13 18:11:05 +04:00
|
|
|
"github.com/jingweno/gh/github"
|
|
|
|
"github.com/jingweno/gh/utils"
|
|
|
|
)
|
|
|
|
|
2013-06-14 21:05:47 +04:00
|
|
|
var cmdRemote = &Command{
|
|
|
|
Run: remote,
|
2013-06-17 21:19:54 +04:00
|
|
|
Usage: "remote [-p] OPTIONS USER[/REPOSITORY]",
|
|
|
|
Short: "View and manage a set of remote repositories",
|
|
|
|
Long: `Add remote "git://github.com/USER/REPOSITORY.git" as with
|
|
|
|
git-remote(1). When /REPOSITORY is omitted, the basename of the
|
|
|
|
current working directory is used. With -p, use private remote
|
|
|
|
"git@github.com:USER/REPOSITORY.git". If USER is "origin"
|
|
|
|
then uses your GitHub login.
|
2013-06-13 18:11:05 +04:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
2013-06-18 00:35:02 +04:00
|
|
|
/**
|
|
|
|
$ gh remote add jingweno
|
|
|
|
> git remote add jingweno git://github.com/jingweno/THIS_REPO.git
|
2013-06-14 19:18:00 +04:00
|
|
|
|
2013-06-18 00:35:02 +04:00
|
|
|
$ gh remote add -p jingweno
|
|
|
|
> git remote add jingweno git@github.com:jingweno/THIS_REPO.git
|
2013-06-13 18:11:05 +04:00
|
|
|
|
2013-06-18 00:35:02 +04:00
|
|
|
$ gh remote add origin
|
|
|
|
> git remote add origin
|
|
|
|
git://github.com/YOUR_LOGIN/THIS_REPO.git
|
|
|
|
**/
|
2013-06-14 21:05:47 +04:00
|
|
|
func remote(command *Command, args []string) {
|
2013-06-18 00:35:02 +04:00
|
|
|
if len(args) >= 1 && (args[0] == "add" || args[0] == "set-url") {
|
|
|
|
args = transformRemoteArgs(args)
|
2013-06-13 18:11:05 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 00:35:02 +04:00
|
|
|
err := git.ExecRemote(args)
|
|
|
|
utils.Check(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func transformRemoteArgs(args []string) (newArgs []string) {
|
|
|
|
args, isPriavte := parseRemotePrivateFlag(args)
|
|
|
|
newArgs, owner := removeItem(args, len(args)-1)
|
2013-06-13 18:11:05 +04:00
|
|
|
|
|
|
|
gh := github.New()
|
2013-06-18 00:35:02 +04:00
|
|
|
url := gh.ExpandRemoteUrl(owner, isPriavte)
|
|
|
|
|
|
|
|
return append(newArgs, owner, url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseRemotePrivateFlag(args []string) ([]string, bool) {
|
|
|
|
for i, arg := range args {
|
|
|
|
if arg == "-p" {
|
|
|
|
args, _ = removeItem(args, i)
|
|
|
|
return args, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return args, false
|
2013-06-13 18:11:05 +04:00
|
|
|
}
|