зеркало из https://github.com/mislav/hub.git
Merge branch 'tgkokk-gh-push'
This commit is contained in:
Коммит
dab9c5bc58
|
@ -60,6 +60,7 @@ var Branching = []*Command{
|
|||
var Remote = []*Command{
|
||||
cmdClone,
|
||||
cmdFetch,
|
||||
cmdPush,
|
||||
cmdRemote,
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
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...)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
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()))
|
||||
}
|
Загрузка…
Ссылка в новой задаче