forked from owenthereal/gh
/
push.go
55 lines (47 loc) · 1.25 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package commands
import (
"github.com/jingweno/gh/github"
"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 {
localRepo := github.LocalRepo()
head, err := localRepo.CurrentBranch()
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...)
}
}