diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-30 10:43:46 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-30 10:44:08 +1100 |
commit | d8084cd558925eb7c9c38afeed5725c21653ab90 (patch) | |
tree | 8467867fc0998df30df799336e65ac142dd61045 /pkg | |
parent | 65f910ebd85283b5cce9bf67d03d3f1a9ea3813a (diff) |
WIP
Diffstat (limited to 'pkg')
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() + |