Merge branch 'tgkokk-gh-submodule'

This commit is contained in:
Jingwen Owen Ou 2013-07-20 07:32:41 -07:00
Родитель 393a61ed79 8f6020074a
Коммит 7a404f6681
4 изменённых файлов: 88 добавлений и 2 удалений

Просмотреть файл

@ -41,8 +41,17 @@ func transformCloneArgs(args *Args) {
isSSH := parseClonePrivateFlag(args)
hasValueRegxp := regexp.MustCompile("^(--(upload-pack|template|depth|origin|branch|reference|name)|-[ubo])$")
nameWithOwnerRegexp := regexp.MustCompile(NameWithOwnerRe)
var skipNext bool
for i, a := range args.Params {
if hasValueRegxp.MatchString(a) {
if skipNext {
skipNext = false
continue
}
if strings.HasPrefix(a, "-") {
if hasValueRegxp.MatchString(a) {
skipNext = true
}
continue
}
@ -53,7 +62,7 @@ func transformCloneArgs(args *Args) {
if nameWithOwnerRegexp.MatchString(a) && !isDir(a) {
name, owner := parseCloneNameAndOwner(a)
config := github.CurrentConfig()
isSSH = isSSH || owner == config.User
isSSH = isSSH || args.Command != "submodule" && owner == config.User
if owner == "" {
owner = config.User
isSSH = true

Просмотреть файл

@ -63,6 +63,7 @@ var Remote = []*Command{
cmdFetch,
cmdPush,
cmdRemote,
cmdSubmodule,
}
var GitHub = []*Command{

38
commands/submodule.go Normal file
Просмотреть файл

@ -0,0 +1,38 @@
package commands
var cmdSubmodule = &Command{
Run: submodule,
GitExtension: true,
Usage: "submodule add [-p] OPTIONS [USER/]REPOSITORY DIRECTORY",
Short: "Initialize, update or inspect submodules",
Long: `Submodule repository "git://github.com/USER/REPOSITORY.git" into
DIRECTORY as with git-submodule(1). When USER/ is omitted,
assumes your GitHub login. With -p, use private remote
"git@github.com:USER/REPOSITORY.git".`,
}
/**
$ gh submodule add jingweno/gh vendor/gh
> git submodule add git://github.com/jingweno/gh.git vendor/gh
$ gh submodule add -p jingweno/gh vendor/gh
> git submodule add git@github.com:jingweno/gh.git vendor/gh
$ gh submodule add -b gh --name gh jingweno/gh vendor/gh
> git submodule add -b gh --name gh git://github.com/jingweno/gh.git vendor/gh
**/
func submodule(command *Command, args *Args) {
if !args.IsParamsEmpty() {
transformSubmoduleArgs(args)
}
}
func transformSubmoduleArgs(args *Args) {
if args.FirstParam() != "add" {
return
}
args.RemoveParam(0)
transformCloneArgs(args)
args.InsertParam(0, "add")
}

Просмотреть файл

@ -0,0 +1,38 @@
package commands
import (
"github.com/bmizerany/assert"
"github.com/jingweno/gh/github"
"os"
"path/filepath"
"testing"
)
func TestTransformSubmoduleArgs(t *testing.T) {
github.DefaultConfigFile = "./test_support/submodule_gh"
config := github.Config{User: "jingweno", Token: "123"}
github.SaveConfig(&config)
defer os.RemoveAll(filepath.Dir(github.DefaultConfigFile))
args := NewArgs([]string{"submodule", "add", "jingweno/gh", "vendor/gh"})
transformSubmoduleArgs(args)
cmds := args.Commands()
assert.Equal(t, 1, len(cmds))
assert.Equal(t, "git submodule add git://github.com/jingweno/gh.git vendor/gh", cmds[0].String())
args = NewArgs([]string{"submodule", "add", "-p", "jingweno/gh",
"vendor/gh"})
transformSubmoduleArgs(args)
cmds = args.Commands()
assert.Equal(t, 1, len(cmds))
assert.Equal(t, "git submodule add git@github.com:jingweno/gh.git vendor/gh", cmds[0].String())
args = NewArgs([]string{"submodule", "add", "-b", "gh", "--name", "gh", "jingweno/gh", "vendor/gh"})
transformSubmoduleArgs(args)
cmds = args.Commands()
assert.Equal(t, 1, len(cmds))
assert.Equal(t, "git submodule add -b gh --name gh git://github.com/jingweno/gh.git vendor/gh", cmds[0].String())
}