This commit is contained in:
Jingwen Owen Ou 2013-07-13 09:59:32 -07:00
Родитель cee5a49a3c
Коммит 855f9c65ad
2 изменённых файлов: 17 добавлений и 2 удалений

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

@ -40,21 +40,25 @@ func transformRemoteArgs(args *Args) {
if !match {
return
}
isPriavte := parseRemotePrivateFlag(args)
var err error
if name == "" {
name, err = utils.DirName()
utils.Check(err)
}
isPriavte := parseRemotePrivateFlag(args)
if owner == "origin" {
owner = github.CurrentConfig().FetchUser()
} else if args.ParamsSize() > 2 {
// `git remote add jingweno foo/bar`
args.RemoveParam(args.ParamsSize() - 1)
}
project := github.Project{Owner: owner, Name: name}
url := project.GitURL(name, owner, isPriavte)
args.RemoveParam(args.ParamsSize() - 1) // remove ownerWithName
args.AppendParams(url)
}

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

@ -1,6 +1,7 @@
package commands
import (
"fmt"
"github.com/bmizerany/assert"
"github.com/jingweno/gh/github"
"os"
@ -13,6 +14,8 @@ func TestTransformRemoteArgs(t *testing.T) {
args := NewArgs([]string{"remote", "add", "jingweno"})
transformRemoteArgs(args)
fmt.Println(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "jingweno", args.GetParam(1))
@ -49,4 +52,12 @@ func TestTransformRemoteArgs(t *testing.T) {
assert.Equal(t, "jingweno", args.GetParam(1))
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "git@github.com:jingweno/gh.git", args.GetParam(2))
args = NewArgs([]string{"remote", "add", "-p", "origin", "org/foo"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "origin", args.GetParam(1))
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "git@github.com:org/foo.git", args.GetParam(2))
}