提交 dab9c5bc 编写于 作者: J Jingwen Owen Ou

Merge branch 'tgkokk-gh-push'

......@@ -60,6 +60,7 @@ var Branching = []*Command{
var Remote = []*Command{
cmdClone,
cmdFetch,
cmdPush,
cmdRemote,
}
......
package commands
import (
"github.com/jingweno/gh/git"
"github.com/jingweno/gh/utils"
"strings"
)
var cmdPush = &Command{
Run: push,
GitExtension: true,
Usage: "push REMOTE-1,REMOTE-2,...,REMOTE-N [REF]",
Short: "Upload data, tags and branches to a remote repository",
Long: `Push REF to each of REMOTE-1 through REMOTE-N by executing
multiple git-push(1) commands.`,
}
/*
$ gh push origin,staging,qa bert_timeout
> git push origin bert_timeout
> git push staging bert_timeout
> git push qa bert_timeout
$ gh push origin
> git push origin HEAD
*/
func push(command *Command, args *Args) {
if !args.IsParamsEmpty() || !strings.Contains(args.FirstParam(), ",") {
transformPushArgs(args)
}
}
func transformPushArgs(args *Args) {
refs := []string{}
if args.ParamsSize() > 1 {
refs = args.Params[1:]
}
remotes := strings.Split(args.FirstParam(), ",")
args.ReplaceParam(0, remotes[0])
if len(refs) == 0 {
head, err := git.Head()
utils.Check(err)
refs = []string{head.ShortName()}
args.AppendParams(refs...)
}
for _, remote := range remotes[1:] {
afterCmd := []string{"git", "push", remote}
afterCmd = append(afterCmd, refs...)
args.After(afterCmd...)
}
}
package commands
import (
"github.com/bmizerany/assert"
"regexp"
"testing"
)
func TestTransformPushArgs(t *testing.T) {
args := NewArgs([]string{"push", "origin,staging,qa", "bert_timeout"})
transformPushArgs(args)
cmds := args.Commands()
assert.Equal(t, 3, len(cmds))
assert.Equal(t, "git push origin bert_timeout", cmds[0].String())
assert.Equal(t, "git push staging bert_timeout", cmds[1].String())
args = NewArgs([]string{"push", "origin"})
transformPushArgs(args)
cmds = args.Commands()
assert.Equal(t, 1, len(cmds))
pushRegexp := regexp.MustCompile("git push origin .+")
assert.T(t, pushRegexp.MatchString(cmds[0].String()))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册