summaryrefslogtreecommitdiffstats
path: root/pkg/commands/sync.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-10-19 22:41:19 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-10-20 09:29:17 +1100
commit5ee559b89660cb850040ce41fee242514a09ba8b (patch)
treedbcbb0d5452294bb813ec0c002ca47bd86f5bed3 /pkg/commands/sync.go
parentca7252ef8ee26affdc2c74f05c9c20196a8d571b (diff)
fix issue where upstream origin and branch were quoted together
fix issue where upstream origin and branch were quoted together
Diffstat (limited to 'pkg/commands/sync.go')
-rw-r--r--pkg/commands/sync.go43
1 files changed, 31 insertions, 12 deletions
diff --git a/pkg/commands/sync.go b/pkg/commands/sync.go
index 583987625..4fc7d73bb 100644
--- a/pkg/commands/sync.go
+++ b/pkg/commands/sync.go
@@ -3,27 +3,46 @@ package commands
import (
"fmt"
"sync"
+
+ "github.com/go-errors/errors"
)
// Push pushes to a branch
-func (c *GitCommand) Push(branchName string, force bool, upstream string, args string, promptUserForCredential func(string) string) error {
- followTagsFlag := "--follow-tags"
- if c.GetConfigValue("push.followTags") == "false" {
- followTagsFlag = ""
+type PushOpts struct {
+ Force bool
+ UpstreamRemote string
+ UpstreamBranch string
+ SetUpstream bool
+ PromptUserForCredential func(string) string
+}
+
+func (c *GitCommand) Push(opts PushOpts) error {
+ cmd := "git push"
+
+ if c.GetConfigValue("push.followTags") != "false" {
+ cmd += " --follow-tags"
}
- forceFlag := ""
- if force {
- forceFlag = "--force-with-lease"
+ if opts.Force {
+ cmd += " --force-with-lease"
}
- setUpstreamArg := ""
- if upstream != "" {
- setUpstreamArg = "--set-upstream " + c.OSCommand.Quote(upstream)
+ if opts.SetUpstream {
+ cmd += " --set-upstream"
+ }
+
+ if opts.UpstreamRemote != "" {
+ cmd += " " + c.OSCommand.Quote(opts.UpstreamRemote)
+ }
+
+ if opts.UpstreamBranch != "" {
+ if opts.UpstreamRemote == "" {
+ return errors.New(c.Tr.MustSpecifyOriginError)
+ }
+ cmd += " " + c.OSCommand.Quote(opts.UpstreamBranch)
}
- cmd := fmt.Sprintf("git push %s %s %s %s", followTagsFlag, forceFlag, setUpstreamArg, args)
- return c.OSCommand.DetectUnamePass(cmd, promptUserForCredential)
+ return c.OSCommand.DetectUnamePass(cmd, opts.PromptUserForCredential)
}
type FetchOptions struct {