summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-21 18:27:20 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-25 09:39:04 +1100
commit0e23f44b846b3bd43112c3e0f81f6fbfb45b22e6 (patch)
treec87220dc348c4243ea62b97478c98e9e9083610c /pkg/commands
parentdaecdd7c2b678e308b01d9e402c86c06a35b8021 (diff)
support reflog action prefix
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go15
-rw-r--r--pkg/commands/os.go16
2 files changed, 26 insertions, 5 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 222d53af0..4efb4c2cd 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -322,8 +322,8 @@ func (c *GitCommand) Fetch(unamePassQuestion func(string) string, canAskForCrede
}
// ResetToCommit reset to commit
-func (c *GitCommand) ResetToCommit(sha string, strength string) error {
- return c.OSCommand.RunCommand("git reset --%s %s", strength, sha)
+func (c *GitCommand) ResetToCommit(sha string, strength string, options RunCommandOptions) error {
+ return c.OSCommand.RunCommandWithOptions(fmt.Sprintf("git reset --%s %s", strength, sha), options)
}
// NewBranch create new branch
@@ -522,12 +522,17 @@ func (c *GitCommand) DiscardUnstagedFileChanges(file *File) error {
}
// Checkout checks out a branch (or commit), with --force if you set the force arg to true
-func (c *GitCommand) Checkout(branch string, force bool) error {
+type CheckoutOptions struct {
+ Force bool
+ EnvVars []string
+}
+
+func (c *GitCommand) Checkout(branch string, options CheckoutOptions) error {
forceArg := ""
- if force {
+ if options.Force {
forceArg = "--force "
}
- return c.OSCommand.RunCommand("git checkout %s %s", forceArg, branch)
+ return c.OSCommand.RunCommandWithOptions(fmt.Sprintf("git checkout %s %s", forceArg, branch), RunCommandOptions{EnvVars: options.EnvVars})
}
// PrepareCommitSubProcess prepares a subprocess for `git commit`
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index 9cf266f58..7b96b99c4 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -64,6 +64,22 @@ func (c *OSCommand) SetBeforeExecuteCmd(cmd func(*exec.Cmd)) {
c.beforeExecuteCmd = cmd
}
+type RunCommandOptions struct {
+ EnvVars []string
+}
+
+func (c *OSCommand) RunCommandWithOutputWithOptions(command string, options RunCommandOptions) (string, error) {
+ c.Log.WithField("command", command).Info("RunCommand")
+ cmd := c.ExecutableFromString(command)
+ cmd.Env = append(cmd.Env, options.EnvVars...)
+ return sanitisedCommandOutput(cmd.CombinedOutput())
+}
+
+func (c *OSCommand) RunCommandWithOptions(command string, options RunCommandOptions) error {
+ _, err := c.RunCommandWithOutputWithOptions(command, options)
+ return err
+}
+
// RunCommandWithOutput wrapper around commands returning their output and error
// NOTE: If you don't pass any formatArgs we'll just use the command directly,
// however there's a bizarre compiler error/warning when you pass in a formatString