summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-03-03 12:44:10 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-03-03 12:44:10 +1100
commit8925b161a75aed3162292c2ed0e2c0135fd91a54 (patch)
tree66a69f329aec7bb87be5274f1819b6a814037acf /pkg/commands
parent0a1298765c999e9dd052181295f5b32e01707bee (diff)
windows support for skipping the editor
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go35
-rw-r--r--pkg/commands/os.go34
-rw-r--r--pkg/commands/os_default_platform.go1
3 files changed, 56 insertions, 14 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 33ef6d5ba..9aa556ed4 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -584,11 +584,26 @@ func (c *GitCommand) FastForward(branchName string) error {
return c.OSCommand.RunCommand(fmt.Sprintf("git fetch %s %s:%s", upstream, branchName, branchName))
}
+func (c *GitCommand) RunSkipEditorCommand(command string) error {
+ cmd := c.OSCommand.ExecutableFromString(command)
+ cmd.Env = append(
+ os.Environ(),
+ "LAZYGIT_CLIENT_COMMAND=EXIT_IMMEDIATELY",
+ "EDITOR="+c.OSCommand.GetLazygitPath(),
+ )
+ return c.OSCommand.RunExecutable(cmd)
+}
+
// GenericMerge takes a commandType of "merge" or "rebase" and a command of "abort", "skip" or "continue"
// By default we skip the editor in the case where a commit will be made
func (c *GitCommand) GenericMerge(commandType string, command string) error {
- gitCommand := fmt.Sprintf("git %s %s --%s", c.OSCommand.Platform.skipEditorArg, commandType, command)
- return c.OSCommand.RunCommand(gitCommand)
+ return c.RunSkipEditorCommand(
+ fmt.Sprintf(
+ "git %s --%s",
+ commandType,
+ command,
+ ),
+ )
}
func (c *GitCommand) RewordCommit(commits []*Commit, index int) (*exec.Cmd, error) {
@@ -635,11 +650,11 @@ func (c *GitCommand) InteractiveRebase(commits []*Commit, index int, action stri
return c.OSCommand.RunPreparedCommand(cmd)
}
+// PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase
+// we tell git to run lazygit to edit the todo list, and we pass the client
+// lazygit a todo string to write to the todo file
func (c *GitCommand) PrepareInteractiveRebaseCommand(baseSha string, todo string, overrideEditor bool) (*exec.Cmd, error) {
- ex, err := os.Executable() // get the executable path for git to use
- if err != nil {
- ex = os.Args[0] // fallback to the first call argument if needed
- }
+ ex := c.OSCommand.GetLazygitPath()
debug := "FALSE"
if c.OSCommand.Config.GetDebug() == true {
@@ -658,7 +673,7 @@ func (c *GitCommand) PrepareInteractiveRebaseCommand(baseSha string, todo string
cmd.Env = os.Environ()
cmd.Env = append(
cmd.Env,
- "LAZYGIT_CONTEXT=INTERACTIVE_REBASE",
+ "LAZYGIT_CLIENT_COMMAND=INTERACTIVE_REBASE",
"LAZYGIT_REBASE_TODO="+todo,
"DEBUG="+debug,
"LANG=en_US.UTF-8", // Force using EN as language
@@ -703,7 +718,11 @@ func (c *GitCommand) AmendTo(sha string) error {
if err := c.OSCommand.RunCommand(fmt.Sprintf("git commit --fixup=%s", sha)); err != nil {
return err
}
- return c.OSCommand.RunCommand(fmt.Sprintf("git %s rebase --interactive --autostash --autosquash %s^", c.OSCommand.Platform.skipEditorArg, sha))
+ return c.RunSkipEditorCommand(
+ fmt.Sprintf(
+ "git rebase --interactive --autostash --autosquash %s^", sha,
+ ),
+ )
}
// EditRebaseTodo sets the action at a given index in the git-rebase-todo file
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index c55a7653e..a7a1fdaa4 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"os/exec"
+ "path/filepath"
"regexp"
"strings"
@@ -25,7 +26,6 @@ type Platform struct {
openCommand string
openLinkCommand string
fallbackEscapedQuote string
- skipEditorArg string
}
// OSCommand holds all the os commands
@@ -59,11 +59,26 @@ func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd) {
// RunCommandWithOutput wrapper around commands returning their output and error
func (c *OSCommand) RunCommandWithOutput(command string) (string, error) {
c.Log.WithField("command", command).Info("RunCommand")
- splitCmd := str.ToArgv(command)
+ cmd := c.ExecutableFromString(command)
+ return sanitisedCommandOutput(cmd.CombinedOutput())
+}
+
+// RunExecutableWithOutput runs an executable file and returns its output
+func (c *OSCommand) RunExecutableWithOutput(cmd *exec.Cmd) (string, error) {
+ return sanitisedCommandOutput(cmd.CombinedOutput())
+}
+
+// RunExecutable runs an executable file and returns an error if there was one
+func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error {
+ _, err := c.RunExecutableWithOutput(cmd)
+ return err
+}
+
+// ExecutableFromString takes a string like `git status` and returns an executable command for it
+func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
+ splitCmd := str.ToArgv(commandStr)
c.Log.Info(splitCmd)
- return sanitisedCommandOutput(
- c.command(splitCmd[0], splitCmd[1:]...).CombinedOutput(),
- )
+ return c.command(splitCmd[0], splitCmd[1:]...)
}
// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
@@ -272,3 +287,12 @@ func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error {
}
return nil
}
+
+// GetLazygitPath returns the path of the currently executed file
+func (c *OSCommand) GetLazygitPath() string {
+ ex, err := os.Executable() // get the executable path for git to use
+ if err != nil {
+ ex = os.Args[0] // fallback to the first call argument if needed
+ }
+ return filepath.ToSlash(ex)
+}
diff --git a/pkg/commands/os_default_platform.go b/pkg/commands/os_default_platform.go
index bf13b8e4e..73e453b6b 100644
--- a/pkg/commands/os_default_platform.go
+++ b/pkg/commands/os_default_platform.go
@@ -15,6 +15,5 @@ func getPlatform() *Platform {
openCommand: "open {{filename}}",
openLinkCommand: "open {{link}}",
fallbackEscapedQuote: "\"",
- skipEditorArg: "-c core.editor=true",
}
}