forked from mislav/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.go
66 lines (51 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
56
57
58
59
60
61
62
63
64
65
66
package commands
import (
"strings"
"github.com/github/hub/v2/github"
"github.com/github/hub/v2/utils"
)
var cmdPush = &Command{
Run: push,
GitExtension: true,
Usage: "push <REMOTE>[,<REMOTE2>...] [<REF>]",
Long: `Push a git branch to each of the listed remotes.
## Examples:
$ hub push origin,staging,qa bert_timeout
> git push origin bert_timeout
> git push staging bert_timeout
> git push qa bert_timeout
$ hub push origin
> git push origin HEAD
## See also:
hub(1), git-push(1)
`,
}
func init() {
CmdRunner.Use(cmdPush)
}
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, err := github.LocalRepo()
utils.Check(err)
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...)
}
}