This commit is contained in:
Jesse Duffield 2021-12-30 10:43:46 +11:00
parent 65f910ebd8
commit d8084cd558
31 changed files with 127 additions and 165 deletions

View file

@ -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
}
}

View file

@ -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()
}

View file

@ -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)
}

View file

@ -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()
}

View file

@ -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"
}
}

View file

@ -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()
}

View file

@ -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
}

View file

@ -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),

View file

@ -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
}

View file

@ -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)

View file

@ -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
}

View file

@ -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()
}

View file

@ -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
}

View file

@ -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")
}

View file

@ -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()
}
}

View file

@ -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(

View file

@ -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()

View file

@ -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
}

View file

@ -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 {

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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())

View file

@ -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),
)
},
})

View file

@ -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(),
)
},
})

View file

@ -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()

View file

@ -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)
}

View file

@ -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())

View file

@ -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())

View file

@ -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 {

View file

@ -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
}