From d8084cd558925eb7c9c38afeed5725c21653ab90 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 30 Dec 2021 10:43:46 +1100 Subject: [PATCH] WIP --- pkg/app/app.go | 4 +-- pkg/commands/branches.go | 38 ++++++++++++------------ pkg/commands/branches_test.go | 2 +- pkg/commands/commits.go | 22 +++++++------- pkg/commands/files.go | 40 +++++++++++++------------- pkg/commands/git.go | 22 +------------- pkg/commands/loading_commit_files.go | 2 +- pkg/commands/loading_commits.go | 18 ++++-------- pkg/commands/loading_files.go | 2 +- pkg/commands/loading_reflog_commits.go | 2 +- pkg/commands/loading_remotes.go | 2 +- pkg/commands/loading_stash.go | 4 +-- pkg/commands/loading_tags.go | 2 +- pkg/commands/oscommands/os.go | 18 ++---------- pkg/commands/oscommands/os_test.go | 4 +-- pkg/commands/rebasing.go | 4 +-- pkg/commands/remotes.go | 12 ++++---- pkg/commands/stash_entries.go | 10 +++---- pkg/commands/submodules.go | 30 +++++++++---------- pkg/commands/sync.go | 10 +++---- pkg/commands/tags.go | 8 +++--- pkg/gui/custom_commands.go | 4 +-- pkg/gui/diffing.go | 2 +- pkg/gui/files_panel.go | 6 ++-- pkg/gui/git_flow.go | 6 ++-- pkg/gui/gpg.go | 4 +-- pkg/gui/rebase_options_panel.go | 2 +- pkg/gui/recent_repos_panel.go | 2 +- pkg/gui/stash_panel.go | 2 +- pkg/integration/integration.go | 6 ++-- pkg/updates/updates.go | 2 +- 31 files changed, 127 insertions(+), 165 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 131f05c04..4fcbdc5b8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -151,7 +151,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { } func (app *App) validateGitVersion() error { - output, err := app.OSCommand.NewCmdObj("git --version").RunWithOutput() + output, err := app.OSCommand.Cmd.New("git --version").RunWithOutput() // if we get an error anywhere here we'll show the same status minVersionError := errors.New(app.Tr.MinGitVersionError) if err != nil { @@ -236,7 +236,7 @@ func (app *App) setupRepo() (bool, error) { os.Exit(1) } - if err := app.OSCommand.NewCmdObj("git init").Run(); err != nil { + if err := app.OSCommand.Cmd.New("git init").Run(); err != nil { return false, err } } diff --git a/pkg/commands/branches.go b/pkg/commands/branches.go index 57997b8dd..e3c40d343 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.NewCmdObj(fmt.Sprintf("git checkout -b %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(base))).Run() + return c.Cmd.New(fmt.Sprintf("git checkout -b %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(base))).Run() } // 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.NewCmdObj("git symbolic-ref --short HEAD").RunWithOutput() + branchName, err := c.Cmd.New("git symbolic-ref --short HEAD").RunWithOutput() if err == nil && branchName != "HEAD\n" { trimmedBranchName := strings.TrimSpace(branchName) return trimmedBranchName, trimmedBranchName, nil } - output, err := c.NewCmdObj("git branch --contains").RunWithOutput() + output, err := c.Cmd.New("git branch --contains").RunWithOutput() if err != nil { return "", "", err } @@ -47,7 +47,7 @@ func (c *GitCommand) DeleteBranch(branch string, force bool) error { command = "git branch -D" } - return c.NewCmdObj(fmt.Sprintf("%s %s", command, c.OSCommand.Quote(branch))).Run() + return c.Cmd.New(fmt.Sprintf("%s %s", command, c.OSCommand.Quote(branch))).Run() } // Checkout checks out a branch (or commit), with --force if you set the force arg to true @@ -62,7 +62,7 @@ func (c *GitCommand) Checkout(branch string, options CheckoutOptions) error { forceArg = " --force" } - return c.NewCmdObj(fmt.Sprintf("git checkout%s %s", forceArg, c.OSCommand.Quote(branch))). + return c.Cmd.New(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"). @@ -78,7 +78,7 @@ func (c *GitCommand) GetBranchGraph(branchName string) (string, error) { } func (c *GitCommand) GetUpstreamForBranch(branchName string) (string, error) { - output, err := c.NewCmdObj(fmt.Sprintf("git rev-parse --abbrev-ref --symbolic-full-name %s@{u}", c.OSCommand.Quote(branchName))).RunWithOutput() + output, err := c.Cmd.New(fmt.Sprintf("git rev-parse --abbrev-ref --symbolic-full-name %s@{u}", c.OSCommand.Quote(branchName))).RunWithOutput() return strings.TrimSpace(output), err } @@ -87,15 +87,15 @@ func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj templateValues := map[string]string{ "branchName": c.OSCommand.Quote(branchName), } - return c.NewCmdObj(utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues)) + return c.Cmd.New(utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues)) } func (c *GitCommand) SetUpstreamBranch(upstream string) error { - return c.NewCmdObj("git branch -u " + c.OSCommand.Quote(upstream)).Run() + return c.Cmd.New("git branch -u " + c.OSCommand.Quote(upstream)).Run() } func (c *GitCommand) SetBranchUpstream(remoteName string, remoteBranchName string, branchName string) error { - return c.NewCmdObj(fmt.Sprintf("git branch --set-upstream-to=%s/%s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(remoteBranchName), c.OSCommand.Quote(branchName))).Run() + return c.Cmd.New(fmt.Sprintf("git branch --set-upstream-to=%s/%s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(remoteBranchName), c.OSCommand.Quote(branchName))).Run() } func (c *GitCommand) GetCurrentBranchUpstreamDifferenceCount() (string, string) { @@ -110,11 +110,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.NewCmdObj(fmt.Sprintf(command, to, from)).RunWithOutput() + pushableCount, err := c.Cmd.New(fmt.Sprintf(command, to, from)).RunWithOutput() if err != nil { return "?", "?" } - pullableCount, err := c.NewCmdObj(fmt.Sprintf(command, from, to)).RunWithOutput() + pullableCount, err := c.Cmd.New(fmt.Sprintf(command, from, to)).RunWithOutput() if err != nil { return "?", "?" } @@ -134,37 +134,37 @@ func (c *GitCommand) Merge(branchName string, opts MergeOpts) error { command = fmt.Sprintf("%s --ff-only", command) } - return c.OSCommand.NewCmdObj(command).Run() + return c.OSCommand.Cmd.New(command).Run() } // AbortMerge abort merge func (c *GitCommand) AbortMerge() error { - return c.NewCmdObj("git merge --abort").Run() + return c.Cmd.New("git merge --abort").Run() } func (c *GitCommand) IsHeadDetached() bool { - err := c.NewCmdObj("git symbolic-ref -q HEAD").Run() + err := c.Cmd.New("git symbolic-ref -q HEAD").Run() return err != nil } // ResetHardHead runs `git reset --hard` func (c *GitCommand) ResetHard(ref string) error { - return c.NewCmdObj("git reset --hard " + c.OSCommand.Quote(ref)).Run() + return c.Cmd.New("git reset --hard " + c.OSCommand.Quote(ref)).Run() } // ResetSoft runs `git reset --soft HEAD` func (c *GitCommand) ResetSoft(ref string) error { - return c.NewCmdObj("git reset --soft " + c.OSCommand.Quote(ref)).Run() + return c.Cmd.New("git reset --soft " + c.OSCommand.Quote(ref)).Run() } func (c *GitCommand) ResetMixed(ref string) error { - return c.NewCmdObj("git reset --mixed " + c.OSCommand.Quote(ref)).Run() + return c.Cmd.New("git reset --mixed " + c.OSCommand.Quote(ref)).Run() } func (c *GitCommand) RenameBranch(oldName string, newName string) error { - return c.NewCmdObj(fmt.Sprintf("git branch --move %s %s", c.OSCommand.Quote(oldName), c.OSCommand.Quote(newName))).Run() + return c.Cmd.New(fmt.Sprintf("git branch --move %s %s", c.OSCommand.Quote(oldName), c.OSCommand.Quote(newName))).Run() } func (c *GitCommand) GetRawBranches() (string, error) { - return c.NewCmdObj(`git for-each-ref --sort=-committerdate --format="%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)" refs/heads`).RunWithOutput() + return c.Cmd.New(`git for-each-ref --sort=-committerdate --format="%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)" refs/heads`).RunWithOutput() } diff --git a/pkg/commands/branches_test.go b/pkg/commands/branches_test.go index a187a1a5d..45cfb8315 100644 --- a/pkg/commands/branches_test.go +++ b/pkg/commands/branches_test.go @@ -210,7 +210,7 @@ func TestGitCommandGetAllBranchGraph(t *testing.T) { return secureexec.Command("echo") } cmdStr := gitCmd.UserConfig.Git.AllBranchesLogCmd - _, err := gitCmd.NewCmdObj(cmdStr).RunWithOutput() + _, err := gitCmd.Cmd.New(cmdStr).RunWithOutput() assert.NoError(t, err) } diff --git a/pkg/commands/commits.go b/pkg/commands/commits.go index bd3e6ea0b..689220529 100644 --- a/pkg/commands/commits.go +++ b/pkg/commands/commits.go @@ -10,12 +10,12 @@ import ( // RenameCommit renames the topmost commit with the given name func (c *GitCommand) RenameCommit(name string) error { - return c.NewCmdObj("git commit --allow-empty --amend --only -m " + c.OSCommand.Quote(name)).Run() + return c.Cmd.New("git commit --allow-empty --amend --only -m " + c.OSCommand.Quote(name)).Run() } // ResetToCommit reset to commit func (c *GitCommand) ResetToCommit(sha string, strength string, envVars []string) error { - return c.NewCmdObj(fmt.Sprintf("git reset --%s %s", strength, sha)). + return c.Cmd.New(fmt.Sprintf("git reset --%s %s", strength, sha)). // 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"). @@ -35,24 +35,24 @@ func (c *GitCommand) CommitCmdObj(message string, flags string) oscommands.ICmdO flagsStr = fmt.Sprintf(" %s", flags) } - return c.NewCmdObj(fmt.Sprintf("git commit%s%s", flagsStr, lineArgs)) + return c.Cmd.New(fmt.Sprintf("git commit%s%s", flagsStr, lineArgs)) } // Get the subject of the HEAD commit func (c *GitCommand) GetHeadCommitMessage() (string, error) { - message, err := c.NewCmdObj("git log -1 --pretty=%s").RunWithOutput() + message, err := c.Cmd.New("git log -1 --pretty=%s").RunWithOutput() return strings.TrimSpace(message), err } func (c *GitCommand) GetCommitMessage(commitSha string) (string, error) { cmdStr := "git rev-list --format=%B --max-count=1 " + commitSha - messageWithHeader, err := c.NewCmdObj(cmdStr).RunWithOutput() + messageWithHeader, err := c.Cmd.New(cmdStr).RunWithOutput() message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "\n") return strings.TrimSpace(message), err } func (c *GitCommand) GetCommitMessageFirstLine(sha string) (string, error) { - return c.NewCmdObj(fmt.Sprintf("git show --no-patch --pretty=format:%%s %s", sha)).RunWithOutput() + return c.Cmd.New(fmt.Sprintf("git show --no-patch --pretty=format:%%s %s", sha)).RunWithOutput() } // AmendHead amends HEAD with whatever is staged in your working tree @@ -61,7 +61,7 @@ func (c *GitCommand) AmendHead() error { } func (c *GitCommand) AmendHeadCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git commit --amend --no-edit --allow-empty") + return c.Cmd.New("git commit --amend --no-edit --allow-empty") } func (c *GitCommand) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj { @@ -72,16 +72,16 @@ func (c *GitCommand) ShowCmdObj(sha string, filterPath string) oscommands.ICmdOb } cmdStr := fmt.Sprintf("git show --submodule --color=%s --unified=%d --no-renames --stat -p %s %s", c.colorArg(), contextSize, sha, filterPathArg) - return c.NewCmdObj(cmdStr) + return c.Cmd.New(cmdStr) } // Revert reverts the selected commit by sha func (c *GitCommand) Revert(sha string) error { - return c.NewCmdObj(fmt.Sprintf("git revert %s", sha)).Run() + return c.Cmd.New(fmt.Sprintf("git revert %s", sha)).Run() } func (c *GitCommand) RevertMerge(sha string, parentNumber int) error { - return c.NewCmdObj(fmt.Sprintf("git revert %s -m %d", sha, parentNumber)).Run() + return c.Cmd.New(fmt.Sprintf("git revert %s -m %d", sha, parentNumber)).Run() } // CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD @@ -101,5 +101,5 @@ func (c *GitCommand) CherryPickCommits(commits []*models.Commit) error { // CreateFixupCommit creates a commit that fixes up a previous commit func (c *GitCommand) CreateFixupCommit(sha string) error { - return c.NewCmdObj(fmt.Sprintf("git commit --fixup=%s", sha)).Run() + return c.Cmd.New(fmt.Sprintf("git commit --fixup=%s", sha)).Run() } diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 119d45ad9..da451e80c 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -25,7 +25,7 @@ func (c *GitCommand) CatFile(fileName string) (string, error) { } func (c *GitCommand) OpenMergeToolCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git mergetool") + return c.Cmd.New("git mergetool") } func (c *GitCommand) OpenMergeTool() error { @@ -34,17 +34,17 @@ func (c *GitCommand) OpenMergeTool() error { // StageFile stages a file func (c *GitCommand) StageFile(fileName string) error { - return c.NewCmdObj("git add -- " + c.OSCommand.Quote(fileName)).Run() + return c.Cmd.New("git add -- " + c.OSCommand.Quote(fileName)).Run() } // StageAll stages all files func (c *GitCommand) StageAll() error { - return c.NewCmdObj("git add -A").Run() + return c.Cmd.New("git add -A").Run() } // UnstageAll unstages all files func (c *GitCommand) UnstageAll() error { - return c.NewCmdObj("git reset").Run() + return c.Cmd.New("git reset").Run() } // UnStageFile unstages a file @@ -57,7 +57,7 @@ func (c *GitCommand) UnStageFile(fileNames []string, reset bool) error { } for _, name := range fileNames { - err := c.NewCmdObj(fmt.Sprintf(command, c.OSCommand.Quote(name))).Run() + err := c.Cmd.New(fmt.Sprintf(command, c.OSCommand.Quote(name))).Run() if err != nil { return err } @@ -122,22 +122,22 @@ func (c *GitCommand) DiscardAllFileChanges(file *models.File) error { quotedFileName := c.OSCommand.Quote(file.Name) if file.ShortStatus == "AA" { - if err := c.NewCmdObj("git checkout --ours -- " + quotedFileName).Run(); err != nil { + if err := c.Cmd.New("git checkout --ours -- " + quotedFileName).Run(); err != nil { return err } - if err := c.NewCmdObj("git add -- " + quotedFileName).Run(); err != nil { + if err := c.Cmd.New("git add -- " + quotedFileName).Run(); err != nil { return err } return nil } if file.ShortStatus == "DU" { - return c.NewCmdObj("git rm -- " + quotedFileName).Run() + return c.Cmd.New("git rm -- " + quotedFileName).Run() } // if the file isn't tracked, we assume you want to delete it if file.HasStagedChanges || file.HasMergeConflicts { - if err := c.NewCmdObj("git reset -- " + quotedFileName).Run(); err != nil { + if err := c.Cmd.New("git reset -- " + quotedFileName).Run(); err != nil { return err } } @@ -163,7 +163,7 @@ func (c *GitCommand) DiscardUnstagedDirChanges(node *filetree.FileNode) error { } quotedPath := c.OSCommand.Quote(node.GetPath()) - if err := c.NewCmdObj("git checkout -- " + quotedPath).Run(); err != nil { + if err := c.Cmd.New("git checkout -- " + quotedPath).Run(); err != nil { return err } @@ -188,7 +188,7 @@ func (c *GitCommand) RemoveUntrackedDirFiles(node *filetree.FileNode) error { // DiscardUnstagedFileChanges directly func (c *GitCommand) DiscardUnstagedFileChanges(file *models.File) error { quotedFileName := c.OSCommand.Quote(file.Name) - return c.NewCmdObj("git checkout -- " + quotedFileName).Run() + return c.Cmd.New("git checkout -- " + quotedFileName).Run() } // Ignore adds a file to the gitignore for the repo @@ -225,7 +225,7 @@ func (c *GitCommand) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cache cmdStr := fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --color=%s %s %s %s %s", contextSize, colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, quotedPath) - return c.NewCmdObj(cmdStr) + return c.Cmd.New(cmdStr) } func (c *GitCommand) ApplyPatch(patch string, flags ...string) error { @@ -240,7 +240,7 @@ func (c *GitCommand) ApplyPatch(patch string, flags ...string) error { flagStr += " --" + flag } - return c.NewCmdObj(fmt.Sprintf("git apply %s %s", flagStr, c.OSCommand.Quote(filepath))).Run() + return c.Cmd.New(fmt.Sprintf("git apply %s %s", flagStr, c.OSCommand.Quote(filepath))).Run() } // ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc @@ -261,12 +261,12 @@ func (c *GitCommand) ShowFileDiffCmdObj(from string, to string, reverse bool, fi reverseFlag = " -R " } - return c.NewCmdObj(fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --no-renames --color=%s %s %s %s -- %s", contextSize, colorArg, from, to, reverseFlag, c.OSCommand.Quote(fileName))) + return c.Cmd.New(fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --no-renames --color=%s %s %s %s -- %s", contextSize, colorArg, from, to, reverseFlag, c.OSCommand.Quote(fileName))) } // CheckoutFile checks out the file for the given commit func (c *GitCommand) CheckoutFile(commitSha, fileName string) error { - return c.NewCmdObj(fmt.Sprintf("git checkout %s -- %s", commitSha, c.OSCommand.Quote(fileName))).Run() + return c.Cmd.New(fmt.Sprintf("git checkout %s -- %s", commitSha, c.OSCommand.Quote(fileName))).Run() } // DiscardOldFileChanges discards changes to a file from an old commit @@ -276,7 +276,7 @@ func (c *GitCommand) DiscardOldFileChanges(commits []*models.Commit, commitIndex } // check if file exists in previous commit (this command returns an error if the file doesn't exist) - if err := c.NewCmdObj("git cat-file -e HEAD^:" + c.OSCommand.Quote(fileName)).Run(); err != nil { + if err := c.Cmd.New("git cat-file -e HEAD^:" + c.OSCommand.Quote(fileName)).Run(); err != nil { if err := c.OSCommand.Remove(fileName); err != nil { return err } @@ -299,17 +299,17 @@ func (c *GitCommand) DiscardOldFileChanges(commits []*models.Commit, commitIndex // DiscardAnyUnstagedFileChanges discards any unstages file changes via `git checkout -- .` func (c *GitCommand) DiscardAnyUnstagedFileChanges() error { - return c.NewCmdObj("git checkout -- .").Run() + return c.Cmd.New("git checkout -- .").Run() } // RemoveTrackedFiles will delete the given file(s) even if they are currently tracked func (c *GitCommand) RemoveTrackedFiles(name string) error { - return c.NewCmdObj("git rm -r --cached -- " + c.OSCommand.Quote(name)).Run() + return c.Cmd.New("git rm -r --cached -- " + c.OSCommand.Quote(name)).Run() } // RemoveUntrackedFiles runs `git clean -fd` func (c *GitCommand) RemoveUntrackedFiles() error { - return c.NewCmdObj("git clean -fd").Run() + return c.Cmd.New("git clean -fd").Run() } // ResetAndClean removes all unstaged changes and removes all untracked files @@ -349,7 +349,7 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er editor = c.OSCommand.Getenv("EDITOR") } if editor == "" { - if err := c.OSCommand.NewCmdObj("which vi").Run(); err == nil { + if err := c.OSCommand.Cmd.New("which vi").Run(); err == nil { editor = "vi" } } diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 3898a654d..b83fa1b73 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -219,25 +219,5 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam } func VerifyInGitRepo(osCommand *oscommands.OSCommand) error { - return osCommand.NewCmdObj("git rev-parse --git-dir").Run() -} - -func (c *GitCommand) Run(cmdObj oscommands.ICmdObj) error { - return cmdObj.Run() -} - -func (c *GitCommand) RunWithOutput(cmdObj oscommands.ICmdObj) (string, error) { - return cmdObj.RunWithOutput() -} - -func (c *GitCommand) RunLineOutputCmd(cmdObj oscommands.ICmdObj, onLine func(line string) (bool, error)) error { - return cmdObj.RunLineOutputCmd(onLine) -} - -func (c *GitCommand) NewCmdObj(cmdStr string) oscommands.ICmdObj { - return c.Cmd.New(cmdStr) -} - -func (c *GitCommand) Quote(str string) string { - return c.OSCommand.Quote(str) + return osCommand.Cmd.New("git rev-parse --git-dir").Run() } diff --git a/pkg/commands/loading_commit_files.go b/pkg/commands/loading_commit_files.go index f390bdc64..fa6d3c8a2 100644 --- a/pkg/commands/loading_commit_files.go +++ b/pkg/commands/loading_commit_files.go @@ -14,7 +14,7 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool) ([]*mo reverseFlag = " -R " } - filenames, err := c.NewCmdObj(fmt.Sprintf("git diff --submodule --no-ext-diff --name-status -z --no-renames %s %s %s", reverseFlag, from, to)).RunWithOutput() + filenames, err := c.Cmd.New(fmt.Sprintf("git diff --submodule --no-ext-diff --name-status -z --no-renames %s %s %s", reverseFlag, from, to)).RunWithOutput() if err != nil { return nil, err } diff --git a/pkg/commands/loading_commits.go b/pkg/commands/loading_commits.go index 9f107d6e8..d7673d334 100644 --- a/pkg/commands/loading_commits.go +++ b/pkg/commands/loading_commits.go @@ -26,16 +26,10 @@ import ( const SEPARATION_CHAR = "|" -// TODO: swap out for 'cmd' -type CmdObjBuilder interface { - NewCmdObj(command string) oscommands.ICmdObj - Quote(str string) string -} - // CommitListBuilder returns a list of Branch objects for the current repo type CommitListBuilder struct { *common.Common - cmd CmdObjBuilder + cmd oscommands.ICmdObjBuilder getCurrentBranchName func() (string, string, error) getRebaseMode func() (string, error) @@ -51,7 +45,7 @@ func NewCommitListBuilder( ) *CommitListBuilder { return &CommitListBuilder{ Common: cmn, - cmd: gitCommand, + cmd: gitCommand.Cmd, getCurrentBranchName: gitCommand.CurrentBranchName, getRebaseMode: gitCommand.RebaseMode, dotGitDir: gitCommand.DotGitDir, @@ -207,7 +201,7 @@ func (c *CommitListBuilder) getHydratedRebasingCommits(rebaseMode string) ([]*mo // note that we're not filtering these as we do non-rebasing commits just because // I suspect that will cause some damage - cmdObj := c.cmd.NewCmdObj( + cmdObj := c.cmd.New( fmt.Sprintf( "git show %s --no-patch --oneline %s --abbrev=%d", strings.Join(commitShas, " "), @@ -380,7 +374,7 @@ func (c *CommitListBuilder) getMergeBase(refName string) (string, error) { } // swallowing error because it's not a big deal; probably because there are no commits yet - output, _ := c.cmd.NewCmdObj(fmt.Sprintf("git merge-base %s %s", c.cmd.Quote(refName), c.cmd.Quote(baseBranch))).RunWithOutput() + output, _ := c.cmd.New(fmt.Sprintf("git merge-base %s %s", c.cmd.Quote(refName), c.cmd.Quote(baseBranch))).RunWithOutput() return ignoringWarnings(output), nil } @@ -397,7 +391,7 @@ func ignoringWarnings(commandOutput string) string { // getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream. // all commits above this are deemed unpushed and marked as such. func (c *CommitListBuilder) getFirstPushedCommit(refName string) (string, error) { - output, err := c.cmd.NewCmdObj(fmt.Sprintf("git merge-base %s %s@{u}", c.cmd.Quote(refName), c.cmd.Quote(refName))).RunWithOutput() + output, err := c.cmd.New(fmt.Sprintf("git merge-base %s %s@{u}", c.cmd.Quote(refName), c.cmd.Quote(refName))).RunWithOutput() if err != nil { return "", err } @@ -425,7 +419,7 @@ func (c *CommitListBuilder) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj allFlag = " --all" } - return c.cmd.NewCmdObj( + return c.cmd.New( fmt.Sprintf( "git log %s %s %s --oneline %s %s --abbrev=%d %s", c.cmd.Quote(opts.RefName), diff --git a/pkg/commands/loading_files.go b/pkg/commands/loading_files.go index f3d9af016..e28613c07 100644 --- a/pkg/commands/loading_files.go +++ b/pkg/commands/loading_files.go @@ -80,7 +80,7 @@ func (c *GitCommand) GitStatus(opts GitStatusOptions) ([]FileStatus, error) { noRenamesFlag = "--no-renames" } - statusLines, err := c.NewCmdObj(fmt.Sprintf("git status %s --porcelain -z %s", opts.UntrackedFilesArg, noRenamesFlag)).RunWithOutput() + statusLines, err := c.Cmd.New(fmt.Sprintf("git status %s --porcelain -z %s", opts.UntrackedFilesArg, noRenamesFlag)).RunWithOutput() if err != nil { return []FileStatus{}, err } diff --git a/pkg/commands/loading_reflog_commits.go b/pkg/commands/loading_reflog_commits.go index db49a11fd..6e14ab0ce 100644 --- a/pkg/commands/loading_reflog_commits.go +++ b/pkg/commands/loading_reflog_commits.go @@ -18,7 +18,7 @@ func (c *GitCommand) GetReflogCommits(lastReflogCommit *models.Commit, filterPat filterPathArg = fmt.Sprintf(" --follow -- %s", c.OSCommand.Quote(filterPath)) } - cmdObj := c.OSCommand.NewCmdObj(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg)) + cmdObj := c.OSCommand.Cmd.New(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg)) onlyObtainedNewReflogCommits := false err := cmdObj.RunLineOutputCmd(func(line string) (bool, error) { fields := strings.SplitN(line, " ", 3) diff --git a/pkg/commands/loading_remotes.go b/pkg/commands/loading_remotes.go index b0e0c6bab..0a581fff5 100644 --- a/pkg/commands/loading_remotes.go +++ b/pkg/commands/loading_remotes.go @@ -10,7 +10,7 @@ import ( ) func (c *GitCommand) GetRemotes() ([]*models.Remote, error) { - remoteBranchesStr, err := c.NewCmdObj("git branch -r").RunWithOutput() + remoteBranchesStr, err := c.Cmd.New("git branch -r").RunWithOutput() if err != nil { return nil, err } diff --git a/pkg/commands/loading_stash.go b/pkg/commands/loading_stash.go index 3433878d6..634dd87fb 100644 --- a/pkg/commands/loading_stash.go +++ b/pkg/commands/loading_stash.go @@ -10,7 +10,7 @@ import ( ) func (c *GitCommand) getUnfilteredStashEntries() []*models.StashEntry { - rawString, _ := c.NewCmdObj("git stash list --pretty='%gs'").RunWithOutput() + rawString, _ := c.Cmd.New("git stash list --pretty='%gs'").RunWithOutput() stashEntries := []*models.StashEntry{} for i, line := range utils.SplitLines(rawString) { stashEntries = append(stashEntries, stashEntryFromLine(line, i)) @@ -24,7 +24,7 @@ func (c *GitCommand) GetStashEntries(filterPath string) []*models.StashEntry { return c.getUnfilteredStashEntries() } - rawString, err := c.NewCmdObj("git stash list --name-only").RunWithOutput() + rawString, err := c.Cmd.New("git stash list --name-only").RunWithOutput() if err != nil { return c.getUnfilteredStashEntries() } diff --git a/pkg/commands/loading_tags.go b/pkg/commands/loading_tags.go index 5353de177..1bac83e9d 100644 --- a/pkg/commands/loading_tags.go +++ b/pkg/commands/loading_tags.go @@ -10,7 +10,7 @@ import ( func (c *GitCommand) GetTags() ([]*models.Tag, error) { // get remote branches, sorted by creation date (descending) // see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt - remoteBranchesStr, err := c.NewCmdObj(`git tag --list --sort=-creatordate`).RunWithOutput() + remoteBranchesStr, err := c.Cmd.New(`git tag --list --sort=-creatordate`).RunWithOutput() if err != nil { return nil, err } diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index c3cd3cce9..5a21413f1 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -165,7 +165,7 @@ func (c *OSCommand) OpenFile(filename string) error { "filename": c.Quote(filename), } command := utils.ResolvePlaceholderString(commandTemplate, templateValues) - return c.NewShellCmdObj(command).Run() + return c.Cmd.NewShell(command).Run() } // OpenLink opens a file with the given @@ -177,7 +177,7 @@ func (c *OSCommand) OpenLink(link string) error { } command := utils.ResolvePlaceholderString(commandTemplate, templateValues) - return c.NewShellCmdObj(command).Run() + return c.Cmd.NewShell(command).Run() } // Quote wraps a message in platform-specific quotation marks @@ -294,7 +294,7 @@ func (c *OSCommand) PipeCommands(commandStrings ...string) error { logCmdStr += " | " } logCmdStr += str - cmds[i] = c.NewCmdObj(str).GetCmd() + cmds[i] = c.Cmd.New(str).GetCmd() } c.LogCommand(logCmdStr, true) @@ -370,18 +370,6 @@ func (c *OSCommand) RemoveFile(path string) error { return c.removeFile(path) } -func (c *OSCommand) NewCmdObj(cmdStr string) ICmdObj { - return c.Cmd.New(cmdStr) -} - -func (c *OSCommand) NewCmdObjFromArgs(args []string) ICmdObj { - return c.Cmd.NewFromArgs(args) -} - -func (c *OSCommand) NewShellCmdObj(commandStr string) ICmdObj { - return c.Cmd.NewShell(commandStr) -} - func GetTempDir() string { return filepath.Join(os.TempDir(), "lazygit") } diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index 98109f408..424aa72b3 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -33,7 +33,7 @@ func TestOSCommandRunWithOutput(t *testing.T) { for _, s := range scenarios { c := NewDummyOSCommand() - s.test(c.NewCmdObj(s.command).RunWithOutput()) + s.test(c.Cmd.New(s.command).RunWithOutput()) } } @@ -55,7 +55,7 @@ func TestOSCommandRun(t *testing.T) { for _, s := range scenarios { c := NewDummyOSCommand() - s.test(c.NewCmdObj(s.command)).Run() + s.test(c.Cmd.New(s.command)).Run() } } diff --git a/pkg/commands/rebasing.go b/pkg/commands/rebasing.go index 1ed73f62c..8827246ab 100644 --- a/pkg/commands/rebasing.go +++ b/pkg/commands/rebasing.go @@ -69,7 +69,7 @@ func (c *GitCommand) PrepareInteractiveRebaseCommand(baseSha string, todo string cmdStr := fmt.Sprintf("git rebase --interactive --autostash --keep-empty %s", baseSha) c.Log.WithField("command", cmdStr).Info("RunCommand") - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) gitSequenceEditor := ex if todo == "" { @@ -267,7 +267,7 @@ func (c *GitCommand) GenericMergeOrRebaseAction(commandType string, command stri } func (c *GitCommand) runSkipEditorCommand(command string) error { - cmdObj := c.OSCommand.NewCmdObj(command) + cmdObj := c.OSCommand.Cmd.New(command) lazyGitPath := c.OSCommand.GetLazygitPath() return cmdObj. AddEnvVars( diff --git a/pkg/commands/remotes.go b/pkg/commands/remotes.go index 680ee149d..79d38c029 100644 --- a/pkg/commands/remotes.go +++ b/pkg/commands/remotes.go @@ -7,24 +7,24 @@ import ( ) func (c *GitCommand) AddRemote(name string, url string) error { - return c.NewCmdObj(fmt.Sprintf("git remote add %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(url))).Run() + return c.Cmd.New(fmt.Sprintf("git remote add %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(url))).Run() } func (c *GitCommand) RemoveRemote(name string) error { - return c.NewCmdObj(fmt.Sprintf("git remote remove %s", c.OSCommand.Quote(name))).Run() + return c.Cmd.New(fmt.Sprintf("git remote remove %s", c.OSCommand.Quote(name))).Run() } func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error { - return c.NewCmdObj(fmt.Sprintf("git remote rename %s %s", c.OSCommand.Quote(oldRemoteName), c.OSCommand.Quote(newRemoteName))).Run() + return c.Cmd.New(fmt.Sprintf("git remote rename %s %s", c.OSCommand.Quote(oldRemoteName), c.OSCommand.Quote(newRemoteName))).Run() } func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error { - return c.NewCmdObj(fmt.Sprintf("git remote set-url %s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(updatedUrl))).Run() + return c.Cmd.New(fmt.Sprintf("git remote set-url %s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(updatedUrl))).Run() } func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string, promptUserForCredential func(string) string) error { command := fmt.Sprintf("git push %s --delete %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(branchName)) - cmdObj := c.NewCmdObj(command) + cmdObj := c.Cmd.New(command) return c.DetectUnamePass(cmdObj, promptUserForCredential) } @@ -34,7 +34,7 @@ func (c *GitCommand) DetectUnamePass(cmdObj oscommands.ICmdObj, promptUserForCre // CheckRemoteBranchExists Returns remote branch func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool { - _, err := c.NewCmdObj( + _, err := c.Cmd.New( fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s", c.OSCommand.Quote(branchName), )).RunWithOutput() diff --git a/pkg/commands/stash_entries.go b/pkg/commands/stash_entries.go index 084415005..16b0806bc 100644 --- a/pkg/commands/stash_entries.go +++ b/pkg/commands/stash_entries.go @@ -4,13 +4,13 @@ import "fmt" // StashDo modify stash func (c *GitCommand) StashDo(index int, method string) error { - return c.NewCmdObj(fmt.Sprintf("git stash %s stash@{%d}", method, index)).Run() + return c.Cmd.New(fmt.Sprintf("git stash %s stash@{%d}", method, index)).Run() } // StashSave save stash // TODO: before calling this, check if there is anything to save func (c *GitCommand) StashSave(message string) error { - return c.NewCmdObj("git stash save " + c.OSCommand.Quote(message)).Run() + return c.Cmd.New("git stash save " + c.OSCommand.Quote(message)).Run() } // GetStashEntryDiff stash diff @@ -22,7 +22,7 @@ func (c *GitCommand) ShowStashEntryCmdStr(index int) string { // shoutouts to Joe on https://stackoverflow.com/questions/14759748/stashing-only-staged-changes-in-git-is-it-possible func (c *GitCommand) StashSaveStagedChanges(message string) error { // wrap in 'writing', which uses a mutex - if err := c.NewCmdObj("git stash --keep-index").Run(); err != nil { + if err := c.Cmd.New("git stash --keep-index").Run(); err != nil { return err } @@ -30,7 +30,7 @@ func (c *GitCommand) StashSaveStagedChanges(message string) error { return err } - if err := c.NewCmdObj("git stash apply stash@{1}").Run(); err != nil { + if err := c.Cmd.New("git stash apply stash@{1}").Run(); err != nil { return err } @@ -38,7 +38,7 @@ func (c *GitCommand) StashSaveStagedChanges(message string) error { return err } - if err := c.NewCmdObj("git stash drop stash@{1}").Run(); err != nil { + if err := c.Cmd.New("git stash drop stash@{1}").Run(); err != nil { return err } diff --git a/pkg/commands/submodules.go b/pkg/commands/submodules.go index 73675f2ee..7e957234b 100644 --- a/pkg/commands/submodules.go +++ b/pkg/commands/submodules.go @@ -71,28 +71,28 @@ func (c *GitCommand) SubmoduleStash(submodule *models.SubmoduleConfig) error { return nil } - return c.NewCmdObj("git -C " + c.OSCommand.Quote(submodule.Path) + " stash --include-untracked").Run() + return c.Cmd.New("git -C " + c.OSCommand.Quote(submodule.Path) + " stash --include-untracked").Run() } func (c *GitCommand) SubmoduleReset(submodule *models.SubmoduleConfig) error { - return c.NewCmdObj("git submodule update --init --force -- " + c.OSCommand.Quote(submodule.Path)).Run() + return c.Cmd.New("git submodule update --init --force -- " + c.OSCommand.Quote(submodule.Path)).Run() } func (c *GitCommand) SubmoduleUpdateAll() error { // not doing an --init here because the user probably doesn't want that - return c.NewCmdObj("git submodule update --force").Run() + return c.Cmd.New("git submodule update --force").Run() } func (c *GitCommand) SubmoduleDelete(submodule *models.SubmoduleConfig) error { // based on https://gist.github.com/myusuf3/7f645819ded92bda6677 - if err := c.NewCmdObj("git submodule deinit --force -- " + c.OSCommand.Quote(submodule.Path)).Run(); err != nil { + if err := c.Cmd.New("git submodule deinit --force -- " + c.OSCommand.Quote(submodule.Path)).Run(); err != nil { if strings.Contains(err.Error(), "did not match any file(s) known to git") { - if err := c.NewCmdObj("git config --file .gitmodules --remove-section submodule." + c.OSCommand.Quote(submodule.Name)).Run(); err != nil { + if err := c.Cmd.New("git config --file .gitmodules --remove-section submodule." + c.OSCommand.Quote(submodule.Name)).Run(); err != nil { return err } - if err := c.NewCmdObj("git config --remove-section submodule." + c.OSCommand.Quote(submodule.Name)).Run(); err != nil { + if err := c.Cmd.New("git config --remove-section submodule." + c.OSCommand.Quote(submodule.Name)).Run(); err != nil { return err } @@ -102,7 +102,7 @@ func (c *GitCommand) SubmoduleDelete(submodule *models.SubmoduleConfig) error { } } - if err := c.NewCmdObj("git rm --force -r " + submodule.Path).Run(); err != nil { + if err := c.Cmd.New("git rm --force -r " + submodule.Path).Run(); err != nil { // if the directory isn't there then that's fine c.Log.Error(err) } @@ -124,11 +124,11 @@ func (c *GitCommand) SubmoduleAdd(name string, path string, url string) error { func (c *GitCommand) SubmoduleUpdateUrl(name string, path string, newUrl string) error { // the set-url command is only for later git versions so we're doing it manually here - if err := c.NewCmdObj("git config --file .gitmodules submodule." + c.OSCommand.Quote(name) + ".url " + c.OSCommand.Quote(newUrl)).Run(); err != nil { + if err := c.Cmd.New("git config --file .gitmodules submodule." + c.OSCommand.Quote(name) + ".url " + c.OSCommand.Quote(newUrl)).Run(); err != nil { return err } - if err := c.NewCmdObj("git submodule sync -- " + c.OSCommand.Quote(path)).Run(); err != nil { + if err := c.Cmd.New("git submodule sync -- " + c.OSCommand.Quote(path)).Run(); err != nil { return err } @@ -136,27 +136,27 @@ func (c *GitCommand) SubmoduleUpdateUrl(name string, path string, newUrl string) } func (c *GitCommand) SubmoduleInit(path string) error { - return c.NewCmdObj("git submodule init -- " + c.OSCommand.Quote(path)).Run() + return c.Cmd.New("git submodule init -- " + c.OSCommand.Quote(path)).Run() } func (c *GitCommand) SubmoduleUpdate(path string) error { - return c.NewCmdObj("git submodule update --init -- " + c.OSCommand.Quote(path)).Run() + return c.Cmd.New("git submodule update --init -- " + c.OSCommand.Quote(path)).Run() } func (c *GitCommand) SubmoduleBulkInitCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git submodule init") + return c.Cmd.New("git submodule init") } func (c *GitCommand) SubmoduleBulkUpdateCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git submodule update") + return c.Cmd.New("git submodule update") } func (c *GitCommand) SubmoduleForceBulkUpdateCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git submodule update --force") + return c.Cmd.New("git submodule update --force") } func (c *GitCommand) SubmoduleBulkDeinitCmdObj() oscommands.ICmdObj { - return c.NewCmdObj("git submodule deinit --all --force") + return c.Cmd.New("git submodule deinit --all --force") } func (c *GitCommand) ResetSubmodules(submodules []*models.SubmoduleConfig) error { diff --git a/pkg/commands/sync.go b/pkg/commands/sync.go index 65a70bd0d..05dc745d8 100644 --- a/pkg/commands/sync.go +++ b/pkg/commands/sync.go @@ -37,7 +37,7 @@ func (c *GitCommand) Push(opts PushOpts) error { cmdStr += " " + c.OSCommand.Quote(opts.UpstreamBranch) } - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) return c.DetectUnamePass(cmdObj, opts.PromptUserForCredential) } @@ -58,7 +58,7 @@ func (c *GitCommand) Fetch(opts FetchOptions) error { cmdStr = fmt.Sprintf("%s %s", cmdStr, c.OSCommand.Quote(opts.BranchName)) } - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) return c.DetectUnamePass(cmdObj, func(question string) string { if opts.PromptUserForCredential != nil { return opts.PromptUserForCredential(question) @@ -94,18 +94,18 @@ func (c *GitCommand) Pull(opts PullOptions) error { // setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user // has 'pull.rebase = interactive' configured. - cmdObj := c.NewCmdObj(cmdStr).AddEnvVars("GIT_SEQUENCE_EDITOR=:") + cmdObj := c.Cmd.New(cmdStr).AddEnvVars("GIT_SEQUENCE_EDITOR=:") return c.DetectUnamePass(cmdObj, opts.PromptUserForCredential) } func (c *GitCommand) FastForward(branchName string, remoteName string, remoteBranchName string, promptUserForCredential func(string) string) error { cmdStr := fmt.Sprintf("git fetch %s %s:%s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(remoteBranchName), c.OSCommand.Quote(branchName)) - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) return c.DetectUnamePass(cmdObj, promptUserForCredential) } func (c *GitCommand) FetchRemote(remoteName string, promptUserForCredential func(string) string) error { cmdStr := fmt.Sprintf("git fetch %s", c.OSCommand.Quote(remoteName)) - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) return c.DetectUnamePass(cmdObj, promptUserForCredential) } diff --git a/pkg/commands/tags.go b/pkg/commands/tags.go index 4965a8173..795a44b79 100644 --- a/pkg/commands/tags.go +++ b/pkg/commands/tags.go @@ -5,19 +5,19 @@ import ( ) func (c *GitCommand) CreateLightweightTag(tagName string, commitSha string) error { - return c.NewCmdObj(fmt.Sprintf("git tag -- %s %s", c.OSCommand.Quote(tagName), commitSha)).Run() + return c.Cmd.New(fmt.Sprintf("git tag -- %s %s", c.OSCommand.Quote(tagName), commitSha)).Run() } func (c *GitCommand) CreateAnnotatedTag(tagName, commitSha, msg string) error { - return c.NewCmdObj(fmt.Sprintf("git tag %s %s -m %s", tagName, commitSha, c.OSCommand.Quote(msg))).Run() + return c.Cmd.New(fmt.Sprintf("git tag %s %s -m %s", tagName, commitSha, c.OSCommand.Quote(msg))).Run() } func (c *GitCommand) DeleteTag(tagName string) error { - return c.NewCmdObj(fmt.Sprintf("git tag -d %s", c.OSCommand.Quote(tagName))).Run() + return c.Cmd.New(fmt.Sprintf("git tag -d %s", c.OSCommand.Quote(tagName))).Run() } func (c *GitCommand) PushTag(remoteName string, tagName string, promptUserForCredential func(string) string) error { cmdStr := fmt.Sprintf("git push %s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(tagName)) - cmdObj := c.NewCmdObj(cmdStr) + cmdObj := c.Cmd.New(cmdStr) return c.DetectUnamePass(cmdObj, promptUserForCredential) } diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index e5de5fb6a..60d7f806c 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -203,7 +203,7 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR } // Run and save output - message, err := gui.GitCommand.NewCmdObj(cmdStr).RunWithOutput() + message, err := gui.GitCommand.Cmd.New(cmdStr).RunWithOutput() if err != nil { return gui.surfaceError(err) } @@ -252,7 +252,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand loadingText = gui.Tr.LcRunningCustomCommandStatus } return gui.WithWaitingStatus(loadingText, func() error { - err := gui.OSCommand.WithSpan(gui.Tr.Spans.CustomCommand).NewShellCmdObj(cmdStr).Run() + err := gui.OSCommand.WithSpan(gui.Tr.Spans.CustomCommand).Cmd.NewShell(cmdStr).Run() if err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 8b54e21af..e3b888066 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -13,7 +13,7 @@ func (gui *Gui) exitDiffMode() error { } func (gui *Gui) renderDiff() error { - cmdObj := gui.OSCommand.NewCmdObj( + cmdObj := gui.OSCommand.Cmd.New( fmt.Sprintf("git diff --submodule --no-ext-diff --color %s", gui.diffStr()), ) task := NewRunPtyTask(cmdObj.GetCmd()) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index b5c387c81..f1ac1d1a5 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -465,7 +465,7 @@ func (gui *Gui) handleCommitEditorPress() error { cmdStr := "git " + strings.Join(args, " ") return gui.runSubprocessWithSuspenseAndRefresh( - gui.GitCommand.WithSpan(gui.Tr.Spans.Commit).NewCmdObj(cmdStr).Log(), + gui.GitCommand.WithSpan(gui.Tr.Spans.Commit).Cmd.New(cmdStr).Log(), ) } @@ -511,7 +511,7 @@ func (gui *Gui) editFileAtLine(filename string, lineNumber int) error { } return gui.runSubprocessWithSuspenseAndRefresh( - gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).NewShellCmdObj(cmdStr), + gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).Cmd.NewShell(cmdStr), ) } @@ -923,7 +923,7 @@ func (gui *Gui) handleCustomCommand() error { gui.OnRunCommand(oscommands.NewCmdLogEntry(command, gui.Tr.Spans.CustomCommand, true)) return gui.runSubprocessWithSuspenseAndRefresh( - gui.OSCommand.NewShellCmdObj(command), + gui.OSCommand.Cmd.NewShell(command), ) }, }) diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go index 14676e4b2..3c8066527 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -32,7 +32,7 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err } return gui.runSubprocessWithSuspenseAndRefresh( - gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowFinish).NewCmdObj("git flow " + branchType + " finish " + suffix).Log(), + gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowFinish).Cmd.New("git flow " + branchType + " finish " + suffix).Log(), ) } @@ -43,7 +43,7 @@ func (gui *Gui) handleCreateGitFlowMenu() error { } // get config - gitFlowConfig, err := gui.GitCommand.NewCmdObj("git config --local --get-regexp gitflow").RunWithOutput() + gitFlowConfig, err := gui.GitCommand.Cmd.New("git config --local --get-regexp gitflow").RunWithOutput() if err != nil { return gui.createErrorPanel("You need to install git-flow and enable it in this repo to use git-flow features") } @@ -56,7 +56,7 @@ func (gui *Gui) handleCreateGitFlowMenu() error { title: title, handleConfirm: func(name string) error { return gui.runSubprocessWithSuspenseAndRefresh( - gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowStart).NewCmdObj("git flow " + branchType + " start " + name).Log(), + gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowStart).Cmd.New("git flow " + branchType + " start " + name).Log(), ) }, }) diff --git a/pkg/gui/gpg.go b/pkg/gui/gpg.go index a757871a1..fe40f8cb8 100644 --- a/pkg/gui/gpg.go +++ b/pkg/gui/gpg.go @@ -15,7 +15,7 @@ import ( func (gui *Gui) withGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error { useSubprocess := gui.GitCommand.UsingGpg() if useSubprocess { - success, err := gui.runSubprocessWithSuspense(gui.OSCommand.NewShellCmdObj(cmdObj.ToString())) + success, err := gui.runSubprocessWithSuspense(gui.OSCommand.Cmd.NewShell(cmdObj.ToString())) if success && onSuccess != nil { if err := onSuccess(); err != nil { return err @@ -33,7 +33,7 @@ func (gui *Gui) withGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, func (gui *Gui) RunAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error { return gui.WithWaitingStatus(waitingStatus, func() error { - cmdObj := gui.OSCommand.NewShellCmdObj(cmdObj.ToString()) + cmdObj := gui.OSCommand.Cmd.NewShell(cmdObj.ToString()) cmdObj.AddEnvVars("TERM=dumb") cmdWriter := gui.getCmdWriter() cmd := cmdObj.GetCmd() diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index 90108258e..205b9df92 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -58,7 +58,7 @@ func (gui *Gui) genericMergeCommand(command string) error { // it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge if status == commands.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit { - sub := gitCommand.NewCmdObj("git " + commandType + " --" + command) + sub := gitCommand.Cmd.New("git " + commandType + " --" + command) if sub != nil { return gui.runSubprocessWithSuspenseAndRefresh(sub) } diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 64f99c611..5a7c58edb 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -38,7 +38,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error { } func (gui *Gui) handleShowAllBranchLogs() error { - cmdObj := gui.OSCommand.NewCmdObj( + cmdObj := gui.OSCommand.Cmd.New( gui.UserConfig.Git.AllBranchesLogCmd, ) task := NewRunPtyTask(cmdObj.GetCmd()) diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 3064b5a62..1f23ccc37 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -22,7 +22,7 @@ func (gui *Gui) stashRenderToMain() error { if stashEntry == nil { task = NewRenderStringTask(gui.Tr.NoStashEntries) } else { - cmdObj := gui.OSCommand.NewCmdObj( + cmdObj := gui.OSCommand.Cmd.New( gui.GitCommand.ShowStashEntryCmdStr(stashEntry.Index), ) task = NewRunPtyTask(cmdObj.GetCmd()) diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index 0ae952c07..3ae60f740 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -45,7 +45,7 @@ func RunTests( testDir := filepath.Join(rootDir, "test", "integration") osCommand := oscommands.NewDummyOSCommand() - err = osCommand.NewCmdObj("go build -o " + tempLazygitPath()).Run() + err = osCommand.Cmd.New("go build -o " + tempLazygitPath()).Run() if err != nil { return err } @@ -319,7 +319,7 @@ func generateSnapshot(dir string) (string, error) { for _, cmdStr := range cmdStrs { // ignoring error for now. If there's an error it could be that there are no results - output, _ := osCommand.NewCmdObj(cmdStr).RunWithOutput() + output, _ := osCommand.Cmd.New(cmdStr).RunWithOutput() snapshot += output + "\n" } @@ -428,7 +428,7 @@ func getLazygitCommand(testPath string, rootDir string, record bool, speed float cmdStr := fmt.Sprintf("%s -debug --use-config-dir=%s --path=%s %s", tempLazygitPath(), configDir, actualDir, extraCmdArgs) - cmdObj := osCommand.NewCmdObj(cmdStr) + cmdObj := osCommand.Cmd.New(cmdStr) cmdObj.AddEnvVars(fmt.Sprintf("SPEED=%f", speed)) if record { diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index 350308f65..ef873fdf7 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -295,7 +295,7 @@ func (u *Updater) downloadAndInstall(rawUrl string) error { } u.Log.Info("untarring tarball/unzipping zip file") - err = u.OSCommand.NewCmdObj(fmt.Sprintf("tar -zxf %s %s", u.OSCommand.Quote(zipPath), "lazygit")).Run() + err = u.OSCommand.Cmd.New(fmt.Sprintf("tar -zxf %s %s", u.OSCommand.Quote(zipPath), "lazygit")).Run() if err != nil { return err }