summaryrefslogtreecommitdiffstats
path: root/pkg/commands/branches.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/branches.go')
-rw-r--r--pkg/commands/branches.go48
1 files changed, 27 insertions, 21 deletions
diff --git a/pkg/commands/branches.go b/pkg/commands/branches.go
index 3f6820c09..cc513a974 100644
--- a/pkg/commands/branches.go
+++ b/pkg/commands/branches.go
@@ -11,19 +11,19 @@ import (
// NewBranch create new branch
func (c *GitCommand) NewBranch(name string, base string) error {
- return c.RunCommand("git checkout -b %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(base))
+ return c.Run(c.NewCmdObj(fmt.Sprintf("git checkout -b %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(base))))
}
// CurrentBranchName get the current branch name and displayname.
// the first returned string is the name and the second is the displayname
// e.g. name is 123asdf and displayname is '(HEAD detached at 123asdf)'
func (c *GitCommand) CurrentBranchName() (string, string, error) {
- branchName, err := c.RunCommandWithOutput("git symbolic-ref --short HEAD")
+ branchName, err := c.RunWithOutput(c.NewCmdObj("git symbolic-ref --short HEAD"))
if err == nil && branchName != "HEAD\n" {
trimmedBranchName := strings.TrimSpace(branchName)
return trimmedBranchName, trimmedBranchName, nil
}
- output, err := c.RunCommandWithOutput("git branch --contains")
+ output, err := c.RunWithOutput(c.NewCmdObj("git branch --contains"))
if err != nil {
return "", "", err
}
@@ -47,7 +47,7 @@ func (c *GitCommand) DeleteBranch(branch string, force bool) error {
command = "git branch -D"
}
- return c.OSCommand.RunCommand("%s %s", command, c.OSCommand.Quote(branch))
+ return c.OSCommand.Run(c.OSCommand.NewCmdObj(fmt.Sprintf("%s %s", command, c.OSCommand.Quote(branch))))
}
// Checkout checks out a branch (or commit), with --force if you set the force arg to true
@@ -61,36 +61,42 @@ func (c *GitCommand) Checkout(branch string, options CheckoutOptions) error {
if options.Force {
forceArg = " --force"
}
- return c.OSCommand.RunCommandWithOptions(fmt.Sprintf("git checkout%s %s", forceArg, c.OSCommand.Quote(branch)), oscommands.RunCommandOptions{EnvVars: options.EnvVars})
+
+ cmdObj := c.NewCmdObj(fmt.Sprintf("git checkout%s %s", forceArg, c.OSCommand.Quote(branch))).
+ // prevents git from prompting us for input which would freeze the program
+ // TODO: see if this is actually needed here
+ AddEnvVars("GIT_TERMINAL_PROMPT=0").
+ AddEnvVars(options.EnvVars...)
+
+ return c.OSCommand.Run(cmdObj)
}
// GetBranchGraph gets the color-formatted graph of the log for the given branch
// Currently it limits the result to 100 commits, but when we get async stuff
// working we can do lazy loading
func (c *GitCommand) GetBranchGraph(branchName string) (string, error) {
- cmdStr := c.GetBranchGraphCmdStr(branchName)
- return c.OSCommand.RunCommandWithOutput(cmdStr)
+ return c.OSCommand.RunWithOutput(c.GetBranchGraphCmdObj(branchName))
}
func (c *GitCommand) GetUpstreamForBranch(branchName string) (string, error) {
- output, err := c.RunCommandWithOutput("git rev-parse --abbrev-ref --symbolic-full-name %s@{u}", c.OSCommand.Quote(branchName))
+ output, err := c.RunWithOutput(c.NewCmdObj(fmt.Sprintf("git rev-parse --abbrev-ref --symbolic-full-name %s@{u}", c.OSCommand.Quote(branchName))))
return strings.TrimSpace(output), err
}
-func (c *GitCommand) GetBranchGraphCmdStr(branchName string) string {
+func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj {
branchLogCmdTemplate := c.Config.GetUserConfig().Git.BranchLogCmd
templateValues := map[string]string{
"branchName": c.OSCommand.Quote(branchName),
}
- return utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues)
+ return c.NewCmdObj(utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues))
}
func (c *GitCommand) SetUpstreamBranch(upstream string) error {
- return c.RunCommand("git branch -u %s", c.OSCommand.Quote(upstream))
+ return c.Run(c.NewCmdObj("git branch -u " + c.OSCommand.Quote(upstream)))
}
func (c *GitCommand) SetBranchUpstream(remoteName string, remoteBranchName string, branchName string) error {
- return c.RunCommand("git branch --set-upstream-to=%s/%s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(remoteBranchName), c.OSCommand.Quote(branchName))
+ return c.Run(c.NewCmdObj(fmt.Sprintf("git branch --set-upstream-to=%s/%s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(remoteBranchName), c.OSCommand.Quote(branchName))))
}
func (c *GitCommand) GetCurrentBranchUpstreamDifferenceCount() (string, string) {
@@ -105,11 +111,11 @@ func (c *GitCommand) GetBranchUpstreamDifferenceCount(branchName string) (string
// current branch
func (c *GitCommand) GetCommitDifferences(from, to string) (string, string) {
command := "git rev-list %s..%s --count"
- pushableCount, err := c.OSCommand.RunCommandWithOutput(command, to, from)
+ pushableCount, err := c.RunWithOutput(c.NewCmdObj(fmt.Sprintf(command, to, from)))
if err != nil {
return "?", "?"
}
- pullableCount, err := c.OSCommand.RunCommandWithOutput(command, from, to)
+ pullableCount, err := c.RunWithOutput(c.NewCmdObj(fmt.Sprintf(command, from, to)))
if err != nil {
return "?", "?"
}
@@ -129,33 +135,33 @@ func (c *GitCommand) Merge(branchName string, opts MergeOpts) error {
command = fmt.Sprintf("%s --ff-only", command)
}
- return c.OSCommand.RunCommand(command)
+ return c.OSCommand.Run(c.OSCommand.NewCmdObj(command))
}
// AbortMerge abort merge
func (c *GitCommand) AbortMerge() error {
- return c.RunCommand("git merge --abort")
+ return c.Run(c.NewCmdObj("git merge --abort"))
}
func (c *GitCommand) IsHeadDetached() bool {
- err := c.RunCommand("git symbolic-ref -q HEAD")
+ err := c.Run(c.NewCmdObj("git symbolic-ref -q HEAD"))
return err != nil
}
// ResetHardHead runs `git reset --hard`
func (c *GitCommand) ResetHard(ref string) error {
- return c.RunCommand("git reset --hard " + c.OSCommand.Quote(ref))
+ return c.Run(c.NewCmdObj("git reset --hard " + c.OSCommand.Quote(ref)))
}
// ResetSoft runs `git reset --soft HEAD`
func (c *GitCommand) ResetSoft(ref string) error {
- return c.RunCommand("git reset --soft " + c.OSCommand.Quote(ref))
+ return c.Run(c.NewCmdObj("git reset --soft " + c.OSCommand.Quote(ref)))
}
func (c *GitCommand) ResetMixed(ref string) error {
- return c.RunCommand("git reset --mixed " + c.OSCommand.Quote(ref))
+ return c.Run(c.NewCmdObj("git reset --mixed " + c.OSCommand.Quote(ref)))
}
func (c *GitCommand) RenameBranch(oldName string, newName string) error {
- return c.RunCommand("git branch --move %s %s", c.OSCommand.Quote(oldName), c.OSCommand.Quote(newName))
+ return c.Run(c.NewCmdObj(fmt.Sprintf("git branch --move %s %s", c.OSCommand.Quote(oldName), c.OSCommand.Quote(newName))))
}