simplify how we log commands

This commit is contained in:
Jesse Duffield 2022-01-05 11:57:32 +11:00
parent e524e39842
commit 05fa483f48
44 changed files with 291 additions and 233 deletions

View file

@ -18,12 +18,12 @@ func (c *GitCommand) NewBranch(name string, base string) error {
// 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.Cmd.New("git symbolic-ref --short HEAD").RunWithOutput()
branchName, err := c.Cmd.New("git symbolic-ref --short HEAD").DontLog().RunWithOutput()
if err == nil && branchName != "HEAD\n" {
trimmedBranchName := strings.TrimSpace(branchName)
return trimmedBranchName, trimmedBranchName, nil
}
output, err := c.Cmd.New("git branch --contains").RunWithOutput()
output, err := c.Cmd.New("git branch --contains").DontLog().RunWithOutput()
if err != nil {
return "", "", err
}
@ -74,11 +74,11 @@ func (c *GitCommand) Checkout(branch string, options CheckoutOptions) error {
// Currently it limits the result to 100 commits, but when we get async stuff
// working we can do lazy loading
func (c *GitCommand) GetBranchGraph(branchName string) (string, error) {
return c.GetBranchGraphCmdObj(branchName).RunWithOutput()
return c.GetBranchGraphCmdObj(branchName).DontLog().RunWithOutput()
}
func (c *GitCommand) GetUpstreamForBranch(branchName string) (string, error) {
output, err := c.Cmd.New(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))).DontLog().RunWithOutput()
return strings.TrimSpace(output), err
}
@ -87,7 +87,7 @@ func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj
templateValues := map[string]string{
"branchName": c.OSCommand.Quote(branchName),
}
return c.Cmd.New(utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues))
return c.Cmd.New(utils.ResolvePlaceholderString(branchLogCmdTemplate, templateValues)).DontLog()
}
func (c *GitCommand) SetUpstreamBranch(upstream string) error {
@ -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.Cmd.New(fmt.Sprintf(command, to, from)).RunWithOutput()
pushableCount, err := c.Cmd.New(fmt.Sprintf(command, to, from)).DontLog().RunWithOutput()
if err != nil {
return "?", "?"
}
pullableCount, err := c.Cmd.New(fmt.Sprintf(command, from, to)).RunWithOutput()
pullableCount, err := c.Cmd.New(fmt.Sprintf(command, from, to)).DontLog().RunWithOutput()
if err != nil {
return "?", "?"
}
@ -146,7 +146,7 @@ func (c *GitCommand) AbortMerge() error {
}
func (c *GitCommand) IsHeadDetached() bool {
err := c.Cmd.New("git symbolic-ref -q HEAD").Run()
err := c.Cmd.New("git symbolic-ref -q HEAD").DontLog().Run()
return err != nil
}
@ -169,5 +169,5 @@ func (c *GitCommand) RenameBranch(oldName string, newName string) error {
}
func (c *GitCommand) GetRawBranches() (string, error) {
return c.Cmd.New(`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`).DontLog().RunWithOutput()
}

View file

@ -40,19 +40,19 @@ func (c *GitCommand) CommitCmdObj(message string, flags string) oscommands.ICmdO
// Get the subject of the HEAD commit
func (c *GitCommand) GetHeadCommitMessage() (string, error) {
message, err := c.Cmd.New("git log -1 --pretty=%s").RunWithOutput()
message, err := c.Cmd.New("git log -1 --pretty=%s").DontLog().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.Cmd.New(cmdStr).RunWithOutput()
messageWithHeader, err := c.Cmd.New(cmdStr).DontLog().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.Cmd.New(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)).DontLog().RunWithOutput()
}
// AmendHead amends HEAD with whatever is staged in your working tree
@ -72,7 +72,7 @@ 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.Cmd.New(cmdStr)
return c.Cmd.New(cmdStr).DontLog()
}
// Revert reverts the selected commit by sha

View file

@ -229,7 +229,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.Cmd.New(cmdStr)
return c.Cmd.New(cmdStr).DontLog()
}
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
@ -265,7 +265,7 @@ func (c *GitCommand) ShowFileDiffCmdObj(from string, to string, reverse bool, fi
reverseFlag = " -R "
}
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)))
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))).DontLog()
}
// CheckoutFile checks out the file for the given commit
@ -280,7 +280,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.Cmd.New("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)).DontLog().Run(); err != nil {
if err := c.OSCommand.Remove(fileName); err != nil {
return err
}
@ -353,7 +353,7 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
editor = c.OSCommand.Getenv("EDITOR")
}
if editor == "" {
if err := c.OSCommand.Cmd.New("which vi").Run(); err == nil {
if err := c.OSCommand.Cmd.New("which vi").DontLog().Run(); err == nil {
editor = "vi"
}
}

View file

@ -111,29 +111,6 @@ func NewGitCommand(
return gitCommand, nil
}
func (c *GitCommand) WithSpan(span string) *GitCommand {
// sometimes .WithSpan(span) will be called where span actually is empty, in
// which case we don't need to log anything so we can just return early here
// with the original struct
if span == "" {
return c
}
newGitCommand := &GitCommand{}
*newGitCommand = *c
newGitCommand.OSCommand = c.OSCommand.WithSpan(span)
newGitCommand.Cmd = NewGitCmdObjBuilder(c.Log, newGitCommand.OSCommand.Cmd)
// NOTE: unlike the other things here which create shallow clones, this will
// actually update the PatchManager on the original struct to have the new span.
// This means each time we call ApplyPatch in PatchManager, we need to ensure
// we've called .WithSpan() ahead of time with the new span value
newGitCommand.PatchManager.ApplyPatch = newGitCommand.ApplyPatch
return newGitCommand
}
func navigateToRepoRootDirectory(stat func(string) (os.FileInfo, error), chdir func(string) error) error {
gitDir := env.GetGitDirEnv()
if gitDir != "" {
@ -245,7 +222,7 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam
}
func VerifyInGitRepo(osCommand *oscommands.OSCommand) error {
return osCommand.Cmd.New("git rev-parse --git-dir").Run()
return osCommand.Cmd.New("git rev-parse --git-dir").DontLog().Run()
}
func (c *GitCommand) GetDotGitDir() string {

View file

@ -28,7 +28,7 @@ func (self *CommitFileLoader) GetFilesInDiff(from string, to string, reverse boo
reverseFlag = " -R "
}
filenames, err := self.cmd.New(fmt.Sprintf("git diff --submodule --no-ext-diff --name-status -z --no-renames %s %s %s", reverseFlag, from, to)).RunWithOutput()
filenames, err := self.cmd.New(fmt.Sprintf("git diff --submodule --no-ext-diff --name-status -z --no-renames %s %s %s", reverseFlag, from, to)).DontLog().RunWithOutput()
if err != nil {
return nil, err
}

View file

@ -218,7 +218,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
prettyFormat,
20,
),
)
).DontLog()
hydratedCommits := make([]*models.Commit, 0, len(commits))
i := 0
@ -384,7 +384,7 @@ func (self *CommitLoader) getMergeBase(refName string) (string, error) {
}
// swallowing error because it's not a big deal; probably because there are no commits yet
output, _ := self.cmd.New(fmt.Sprintf("git merge-base %s %s", self.cmd.Quote(refName), self.cmd.Quote(baseBranch))).RunWithOutput()
output, _ := self.cmd.New(fmt.Sprintf("git merge-base %s %s", self.cmd.Quote(refName), self.cmd.Quote(baseBranch))).DontLog().RunWithOutput()
return ignoringWarnings(output), nil
}
@ -405,6 +405,7 @@ func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {
New(
fmt.Sprintf("git merge-base %s %s@{u}", self.cmd.Quote(refName), self.cmd.Quote(refName)),
).
DontLog().
RunWithOutput()
if err != nil {
return "", err
@ -444,7 +445,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
20,
filterFlag,
),
)
).DontLog()
}
var prettyFormat = fmt.Sprintf(

View file

@ -98,7 +98,7 @@ func (c *FileLoader) GitStatus(opts GitStatusOptions) ([]FileStatus, error) {
noRenamesFlag = " --no-renames"
}
statusLines, err := c.cmd.New(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)).DontLog().RunWithOutput()
if err != nil {
return []FileStatus{}, err
}

View file

@ -32,7 +32,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit
filterPathArg = fmt.Sprintf(" --follow -- %s", self.cmd.Quote(filterPath))
}
cmdObj := self.cmd.New(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg))
cmdObj := self.cmd.New(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg)).DontLog()
onlyObtainedNewReflogCommits := false
err := cmdObj.RunAndProcessLines(func(line string) (bool, error) {
fields := strings.SplitN(line, " ", 3)

View file

@ -31,7 +31,7 @@ func NewRemoteLoader(
}
func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
remoteBranchesStr, err := self.cmd.New("git branch -r").RunWithOutput()
remoteBranchesStr, err := self.cmd.New("git branch -r").DontLog().RunWithOutput()
if err != nil {
return nil, err
}

View file

@ -31,7 +31,7 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
return self.getUnfilteredStashEntries()
}
rawString, err := self.cmd.New("git stash list --name-only").RunWithOutput()
rawString, err := self.cmd.New("git stash list --name-only").DontLog().RunWithOutput()
if err != nil {
return self.getUnfilteredStashEntries()
}
@ -64,7 +64,7 @@ outer:
}
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
rawString, _ := self.cmd.New("git stash list --pretty='%gs'").RunWithOutput()
rawString, _ := self.cmd.New("git stash list --pretty='%gs'").DontLog().RunWithOutput()
stashEntries := []*models.StashEntry{}
for i, line := range utils.SplitLines(rawString) {
stashEntries = append(stashEntries, self.stashEntryFromLine(line, i))

View file

@ -27,7 +27,7 @@ func NewTagLoader(
func (self *TagLoader) 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 := self.cmd.New(`git tag --list --sort=-creatordate`).RunWithOutput()
remoteBranchesStr, err := self.cmd.New(`git tag --list --sort=-creatordate`).DontLog().RunWithOutput()
if err != nil {
return nil, err
}

View file

@ -22,16 +22,20 @@ type ICmdObj interface {
// runs the command and runs a callback function on each line of the output. If the callback returns true for the boolean value, we kill the process and return.
RunAndProcessLines(onLine func(line string) (bool, error)) error
// logs command
Log() ICmdObj
// Marks the command object as readonly, so that when it is run, we don't log it to the user.
// We only want to log commands to the user which change state in some way.
DontLog() ICmdObj
ShouldLog() bool
}
type CmdObj struct {
cmdStr string
cmd *exec.Cmd
runner ICmdObjRunner
logCommand func(ICmdObj)
runner ICmdObjRunner
// if set to true, we don't want to log the command to the user.
dontLog bool
}
func (self *CmdObj) GetCmd() *exec.Cmd {
@ -52,12 +56,15 @@ func (self *CmdObj) GetEnvVars() []string {
return self.cmd.Env
}
func (self *CmdObj) Log() ICmdObj {
self.logCommand(self)
func (self *CmdObj) DontLog() ICmdObj {
self.dontLog = true
return self
}
func (self *CmdObj) ShouldLog() bool {
return !self.dontLog
}
func (self *CmdObj) Run() error {
return self.runner.Run(self)
}

View file

@ -35,10 +35,9 @@ func (self *CmdObjBuilder) New(cmdStr string) ICmdObj {
cmd.Env = os.Environ()
return &CmdObj{
cmdStr: cmdStr,
cmd: cmd,
runner: self.runner,
logCommand: self.logCmdObj,
cmdStr: cmdStr,
cmd: cmd,
runner: self.runner,
}
}
@ -47,10 +46,9 @@ func (self *CmdObjBuilder) NewFromArgs(args []string) ICmdObj {
cmd.Env = os.Environ()
return &CmdObj{
cmdStr: strings.Join(args, " "),
cmd: cmd,
runner: self.runner,
logCommand: self.logCmdObj,
cmdStr: strings.Join(args, " "),
cmd: cmd,
runner: self.runner,
}
}

View file

@ -22,12 +22,19 @@ type cmdObjRunner struct {
var _ ICmdObjRunner = &cmdObjRunner{}
func (self *cmdObjRunner) Run(cmdObj ICmdObj) error {
if cmdObj.ShouldLog() {
self.logCmdObj(cmdObj)
}
_, err := self.RunWithOutput(cmdObj)
return err
}
func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) {
self.logCmdObj(cmdObj)
if cmdObj.ShouldLog() {
self.logCmdObj(cmdObj)
}
output, err := sanitisedCommandOutput(cmdObj.GetCmd().CombinedOutput())
if err != nil {
self.log.WithField("command", cmdObj.ToString()).Error(output)
@ -36,6 +43,10 @@ func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) {
}
func (self *cmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line string) (bool, error)) error {
if cmdObj.ShouldLog() {
self.logCmdObj(cmdObj)
}
cmd := cmdObj.GetCmd()
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {

View file

@ -66,7 +66,9 @@ func RunCommandWithOutputLiveAux(
startCmd func(cmd *exec.Cmd) (*cmdHandler, error),
) error {
c.Log.WithField("command", cmdObj.ToString()).Info("RunCommand")
c.LogCommand(cmdObj.ToString(), true)
if cmdObj.ShouldLog() {
c.LogCommand(cmdObj.ToString(), true)
}
cmd := cmdObj.AddEnvVars("LANG=en_US.UTF-8", "LC_ALL=en_US.UTF-8").GetCmd()
var stderr bytes.Buffer

View file

@ -87,22 +87,6 @@ func NewOSCommand(common *common.Common, platform *Platform) *OSCommand {
return c
}
func (c *OSCommand) WithSpan(span string) *OSCommand {
// sometimes .WithSpan(span) will be called where span actually is empty, in
// which case we don't need to log anything so we can just return early here
// with the original struct
if span == "" {
return c
}
newOSCommand := &OSCommand{}
*newOSCommand = *c
newOSCommand.CmdLogSpan = span
newOSCommand.Cmd.logCmdObj = newOSCommand.LogCmdObj
newOSCommand.Cmd.runner = &cmdObjRunner{log: c.Log, logCmdObj: newOSCommand.LogCmdObj}
return newOSCommand
}
func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
c.LogCommand(cmdObj.ToString(), true)
}
@ -110,7 +94,7 @@ func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
c.Log.WithField("command", cmdStr).Info("RunCommand")
if c.onRunCommand != nil && c.CmdLogSpan != "" {
if c.onRunCommand != nil {
c.onRunCommand(NewCmdLogEntry(cmdStr, c.CmdLogSpan, commandLine))
}
}

View file

@ -47,7 +47,9 @@ func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool {
New(
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
c.Cmd.Quote(branchName),
)).
),
).
DontLog().
RunWithOutput()
return err == nil

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
)
// StashDo modify stash
@ -17,9 +18,10 @@ func (c *GitCommand) StashSave(message string) error {
return c.Cmd.New("git stash save " + c.OSCommand.Quote(message)).Run()
}
// GetStashEntryDiff stash diff
func (c *GitCommand) ShowStashEntryCmdStr(index int) string {
return fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.UserConfig.Git.DiffContextSize, index)
func (c *GitCommand) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.UserConfig.Git.DiffContextSize, index)
return c.Cmd.New(cmdStr).DontLog()
}
// StashSaveStagedChanges stashes only the currently staged changes. This takes a few steps

View file

@ -25,7 +25,7 @@ func TestGitCommandStashSave(t *testing.T) {
runner.CheckForMissingCalls()
}
func TestGitCommandShowStashEntryCmdStr(t *testing.T) {
func TestGitCommandShowStashEntryCmdObj(t *testing.T) {
type scenario struct {
testName string
index int
@ -52,7 +52,7 @@ func TestGitCommandShowStashEntryCmdStr(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
gitCmd := NewDummyGitCommand()
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
cmdStr := gitCmd.ShowStashEntryCmdStr(s.index)
cmdStr := gitCmd.ShowStashEntryCmdObj(s.index).ToString()
assert.Equal(t, s.expected, cmdStr)
})
}

View file

@ -68,8 +68,12 @@ func (c *GitCommand) Fetch(opts FetchOptions) error {
}
cmdObj := c.Cmd.New(cmdStr)
userInitiated := opts.PromptUserForCredential != nil
if !userInitiated {
cmdObj.DontLog()
}
return c.DetectUnamePass(cmdObj, func(question string) string {
if opts.PromptUserForCredential != nil {
if userInitiated {
return opts.PromptUserForCredential(question)
}
return "\n"

View file

@ -80,7 +80,8 @@ func (gui *Gui) handleBranchPress() error {
return gui.createErrorPanel(gui.Tr.AlreadyCheckedOutBranch)
}
branch := gui.getSelectedBranch()
return gui.handleCheckoutRef(branch.Name, handleCheckoutRefOptions{span: gui.Tr.Spans.CheckoutBranch})
gui.logSpan(gui.Tr.Spans.CheckoutBranch)
return gui.handleCheckoutRef(branch.Name, handleCheckoutRefOptions{})
}
func (gui *Gui) handleCreatePullRequestPress() error {
@ -145,7 +146,8 @@ func (gui *Gui) handleForceCheckout() error {
title: title,
prompt: message,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.ForceCheckoutBranch).Checkout(branch.Name, commands.CheckoutOptions{Force: true}); err != nil {
gui.logSpan(gui.Tr.Spans.ForceCheckoutBranch)
if err := gui.GitCommand.Checkout(branch.Name, commands.CheckoutOptions{Force: true}); err != nil {
_ = gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
@ -157,7 +159,6 @@ type handleCheckoutRefOptions struct {
WaitingStatus string
EnvVars []string
onRefNotFound func(ref string) error
span string
}
func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) error {
@ -175,10 +176,8 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
gui.State.Panels.Commits.LimitCommits = true
}
gitCommand := gui.GitCommand.WithSpan(options.span)
return gui.WithWaitingStatus(waitingStatus, func() error {
if err := gitCommand.Checkout(ref, cmdOptions); err != nil {
if err := gui.GitCommand.Checkout(ref, cmdOptions); err != nil {
// note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
if options.onRefNotFound != nil && strings.Contains(err.Error(), "did not match any file(s) known to git") {
@ -192,15 +191,15 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
title: gui.Tr.AutoStashTitle,
prompt: gui.Tr.AutoStashPrompt,
handleConfirm: func() error {
if err := gitCommand.StashSave(gui.Tr.StashPrefix + ref); err != nil {
if err := gui.GitCommand.StashSave(gui.Tr.StashPrefix + ref); err != nil {
return gui.surfaceError(err)
}
if err := gitCommand.Checkout(ref, cmdOptions); err != nil {
if err := gui.GitCommand.Checkout(ref, cmdOptions); err != nil {
return gui.surfaceError(err)
}
onSuccess()
if err := gitCommand.StashDo(0, "pop"); err != nil {
if err := gui.GitCommand.StashDo(0, "pop"); err != nil {
if err := gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI}); err != nil {
return err
}
@ -226,10 +225,9 @@ func (gui *Gui) handleCheckoutByName() error {
title: gui.Tr.BranchName + ":",
findSuggestionsFunc: gui.getRefsSuggestionsFunc(),
handleConfirm: func(response string) error {
gui.logSpan("Checkout branch")
return gui.handleCheckoutRef(response, handleCheckoutRefOptions{
span: "Checkout branch",
onRefNotFound: func(ref string) error {
return gui.ask(askOpts{
title: gui.Tr.BranchNotFoundTitle,
prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"),
@ -300,7 +298,8 @@ func (gui *Gui) deleteNamedBranch(selectedBranch *models.Branch, force bool) err
title: title,
prompt: message,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DeleteBranch).DeleteBranch(selectedBranch.Name, force); err != nil {
gui.logSpan(gui.Tr.Spans.DeleteBranch)
if err := gui.GitCommand.DeleteBranch(selectedBranch.Name, force); err != nil {
errMessage := err.Error()
if !force && strings.Contains(errMessage, "git branch -D ") {
return gui.deleteNamedBranch(selectedBranch, true)
@ -336,7 +335,8 @@ func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error {
title: gui.Tr.MergingTitle,
prompt: prompt,
handleConfirm: func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.Merge).Merge(branchName, commands.MergeOpts{})
gui.logSpan(gui.Tr.Spans.Merge)
err := gui.GitCommand.Merge(branchName, commands.MergeOpts{})
return gui.handleGenericMergeCommandResult(err)
},
})
@ -377,7 +377,8 @@ func (gui *Gui) handleRebaseOntoBranch(selectedBranchName string) error {
title: gui.Tr.RebasingTitle,
prompt: prompt,
handleConfirm: func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.RebaseBranch).RebaseBranch(selectedBranchName)
gui.logSpan(gui.Tr.Spans.RebaseBranch)
err := gui.GitCommand.RebaseBranch(selectedBranchName)
return gui.handleGenericMergeCommandResult(err)
},
})
@ -420,7 +421,8 @@ func (gui *Gui) handleFastForward() error {
if gui.State.Panels.Branches.SelectedLineIdx == 0 {
_ = gui.pullWithLock(PullFilesOptions{span: span, FastForwardOnly: true})
} else {
err := gui.GitCommand.WithSpan(span).FastForward(branch.Name, remoteName, remoteBranchName, gui.promptUserForCredential)
gui.logSpan(span)
err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName, gui.promptUserForCredential)
gui.handleCredentialsPopup(err)
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{BRANCHES}})
}
@ -448,7 +450,8 @@ func (gui *Gui) handleRenameBranch() error {
title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":",
initialContent: branch.Name,
handleConfirm: func(newBranchName string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RenameBranch).RenameBranch(branch.Name, newBranchName); err != nil {
gui.logSpan(gui.Tr.Spans.RenameBranch)
if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil {
return gui.surfaceError(err)
}
@ -516,7 +519,8 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
title: message,
initialContent: prefilledName,
handleConfirm: func(response string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateBranch).NewBranch(sanitizedBranchName(response), item.ID()); err != nil {
gui.logSpan(gui.Tr.Spans.CreateBranch)
if err := gui.GitCommand.NewBranch(sanitizedBranchName(response), item.ID()); err != nil {
return err
}

View file

@ -148,7 +148,8 @@ func (gui *Gui) HandlePasteCommits() error {
prompt: gui.Tr.SureCherryPick,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.CherryPickingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.CherryPick).CherryPickCommits(gui.State.Modes.CherryPicking.CherryPickedCommits)
gui.logSpan(gui.Tr.Spans.CherryPick)
err := gui.GitCommand.CherryPickCommits(gui.State.Modes.CherryPicking.CherryPickedCommits)
return gui.handleGenericMergeCommandResult(err)
})
},

View file

@ -13,9 +13,6 @@ import (
)
func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
// closing over this so that nobody else can modify it
currentSpan := ""
return func(entry oscommands.CmdLogEntry) {
if gui.Views.Extras == nil {
return
@ -23,11 +20,6 @@ func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
gui.Views.Extras.Autoscroll = true
if entry.GetSpan() != currentSpan {
fmt.Fprint(gui.Views.Extras, "\n"+style.FgYellow.Sprint(entry.GetSpan()))
currentSpan = entry.GetSpan()
}
textStyle := theme.DefaultTextColor
if !entry.GetCommandLine() {
textStyle = style.FgMagenta
@ -38,6 +30,16 @@ func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
}
}
func (gui *Gui) logSpan(span string) {
if gui.Views.Extras == nil {
return
}
gui.Views.Extras.Autoscroll = true
fmt.Fprint(gui.Views.Extras, "\n"+style.FgYellow.Sprint(span))
}
func (gui *Gui) printCommandLogHeader() {
introStr := fmt.Sprintf(
gui.Tr.CommandLogHeader,

View file

@ -63,7 +63,8 @@ func (gui *Gui) handleCheckoutCommitFile() error {
return nil
}
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CheckoutFile).CheckoutFile(gui.State.CommitFileManager.GetParent(), node.GetPath()); err != nil {
gui.logSpan(gui.Tr.Spans.CheckoutFile)
if err := gui.GitCommand.CheckoutFile(gui.State.CommitFileManager.GetParent(), node.GetPath()); err != nil {
return gui.surfaceError(err)
}
@ -82,7 +83,8 @@ func (gui *Gui) handleDiscardOldFileChange() error {
prompt: gui.Tr.DiscardFileChangesPrompt,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardOldFileChange).DiscardOldFileChanges(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, fileName); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardOldFileChange)
if err := gui.GitCommand.DiscardOldFileChanges(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, fileName); err != nil {
if err := gui.handleGenericMergeCommandResult(err); err != nil {
return err
}

View file

@ -173,7 +173,8 @@ func (gui *Gui) handleCommitSquashDown() error {
prompt: gui.Tr.SureSquashThisCommit,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.SquashCommitDown).InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "squash")
gui.logSpan(gui.Tr.Spans.SquashCommitDown)
err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "squash")
return gui.handleGenericMergeCommandResult(err)
})
},
@ -202,7 +203,8 @@ func (gui *Gui) handleCommitFixup() error {
prompt: gui.Tr.SureFixupThisCommit,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.FixingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.FixupCommit).InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "fixup")
gui.logSpan(gui.Tr.Spans.FixupCommit)
err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "fixup")
return gui.handleGenericMergeCommandResult(err)
})
},
@ -240,7 +242,8 @@ func (gui *Gui) handleRenameCommit() error {
title: gui.Tr.LcRenameCommit,
initialContent: message,
handleConfirm: func(response string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RewordCommit).RenameCommit(response); err != nil {
gui.logSpan(gui.Tr.Spans.RewordCommit)
if err := gui.GitCommand.RenameCommit(response); err != nil {
return gui.surfaceError(err)
}
@ -262,7 +265,8 @@ func (gui *Gui) handleRenameCommitEditor() error {
return nil
}
subProcess, err := gui.GitCommand.WithSpan(gui.Tr.Spans.RewordCommit).RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx)
gui.logSpan(gui.Tr.Spans.RewordCommit)
subProcess, err := gui.GitCommand.RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx)
if err != nil {
return gui.surfaceError(err)
}
@ -321,7 +325,8 @@ func (gui *Gui) handleCommitDelete() error {
prompt: gui.Tr.DeleteCommitPrompt,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.DeletingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.DropCommit).InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "drop")
gui.logSpan(gui.Tr.Spans.DropCommit)
err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "drop")
return gui.handleGenericMergeCommandResult(err)
})
},
@ -358,7 +363,8 @@ func (gui *Gui) handleCommitMoveDown() error {
}
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() error {
err := gui.GitCommand.WithSpan(span).MoveCommitDown(gui.State.Commits, index)
gui.logSpan(span)
err := gui.GitCommand.MoveCommitDown(gui.State.Commits, index)
if err == nil {
gui.State.Panels.Commits.SelectedLineIdx++
}
@ -396,7 +402,8 @@ func (gui *Gui) handleCommitMoveUp() error {
}
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() error {
err := gui.GitCommand.WithSpan(span).MoveCommitDown(gui.State.Commits, index-1)
gui.logSpan(span)
err := gui.GitCommand.MoveCommitDown(gui.State.Commits, index-1)
if err == nil {
gui.State.Panels.Commits.SelectedLineIdx--
}
@ -418,7 +425,8 @@ func (gui *Gui) handleCommitEdit() error {
}
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
err = gui.GitCommand.WithSpan(gui.Tr.Spans.EditCommit).InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "edit")
gui.logSpan(gui.Tr.Spans.EditCommit)
err = gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "edit")
return gui.handleGenericMergeCommandResult(err)
})
}
@ -433,7 +441,8 @@ func (gui *Gui) handleCommitAmendTo() error {
prompt: gui.Tr.AmendCommitPrompt,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.AmendingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.AmendCommit).AmendTo(gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx].Sha)
gui.logSpan(gui.Tr.Spans.AmendCommit)
err := gui.GitCommand.AmendTo(gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx].Sha)
return gui.handleGenericMergeCommandResult(err)
})
},
@ -468,7 +477,8 @@ func (gui *Gui) handleCommitRevert() error {
if commit.IsMerge() {
return gui.createRevertMergeCommitMenu(commit)
} else {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RevertCommit).Revert(commit.Sha); err != nil {
gui.logSpan(gui.Tr.Spans.RevertCommit)
if err := gui.GitCommand.Revert(commit.Sha); err != nil {
return gui.surfaceError(err)
}
return gui.afterRevertCommit()
@ -488,7 +498,8 @@ func (gui *Gui) createRevertMergeCommitMenu(commit *models.Commit) error {
displayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
onPress: func() error {
parentNumber := i + 1
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RevertCommit).RevertMerge(commit.Sha, parentNumber); err != nil {
gui.logSpan(gui.Tr.Spans.RevertCommit)
if err := gui.GitCommand.RevertMerge(commit.Sha, parentNumber); err != nil {
return gui.surfaceError(err)
}
return gui.afterRevertCommit()
@ -534,7 +545,8 @@ func (gui *Gui) handleCreateFixupCommit() error {
title: gui.Tr.CreateFixupCommit,
prompt: prompt,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateFixupCommit).CreateFixupCommit(commit.Sha); err != nil {
gui.logSpan(gui.Tr.Spans.CreateFixupCommit)
if err := gui.GitCommand.CreateFixupCommit(commit.Sha); err != nil {
return gui.surfaceError(err)
}
@ -565,7 +577,8 @@ func (gui *Gui) handleSquashAllAboveFixupCommits() error {
prompt: prompt,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.SquashAllAboveFixupCommits).SquashAllAboveFixupCommits(commit.Sha)
gui.logSpan(gui.Tr.Spans.SquashAllAboveFixupCommits)
err := gui.GitCommand.SquashAllAboveFixupCommits(commit.Sha)
return gui.handleGenericMergeCommandResult(err)
})
},
@ -612,7 +625,8 @@ func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
return gui.prompt(promptOpts{
title: gui.Tr.TagMessageTitle,
handleConfirm: func(msg string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateAnnotatedTag).CreateAnnotatedTag(tagName, commitSha, msg); err != nil {
gui.logSpan(gui.Tr.Spans.CreateAnnotatedTag)
if err := gui.GitCommand.CreateAnnotatedTag(tagName, commitSha, msg); err != nil {
return gui.surfaceError(err)
}
return gui.afterTagCreate(tagName)
@ -626,7 +640,8 @@ func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
return gui.prompt(promptOpts{
title: gui.Tr.TagNameTitle,
handleConfirm: func(tagName string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.CreateLightweightTag).CreateLightweightTag(tagName, commitSha); err != nil {
gui.logSpan(gui.Tr.Spans.CreateLightweightTag)
if err := gui.GitCommand.CreateLightweightTag(tagName, commitSha); err != nil {
return gui.surfaceError(err)
}
return gui.afterTagCreate(tagName)
@ -644,7 +659,8 @@ func (gui *Gui) handleCheckoutCommit() error {
title: gui.Tr.LcCheckoutCommit,
prompt: gui.Tr.SureCheckoutThisCommit,
handleConfirm: func() error {
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{span: gui.Tr.Spans.CheckoutCommit})
gui.logSpan(gui.Tr.Spans.CheckoutCommit)
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
},
})
}
@ -699,7 +715,8 @@ func (gui *Gui) handleCopySelectedCommitMessageToClipboard() error {
return gui.surfaceError(err)
}
if err := gui.OSCommand.WithSpan(gui.Tr.Spans.CopyCommitMessageToClipboard).CopyToClipboard(message); err != nil {
gui.logSpan(gui.Tr.Spans.CopyCommitMessageToClipboard)
if err := gui.OSCommand.CopyToClipboard(message); err != nil {
return gui.surfaceError(err)
}

View file

@ -252,7 +252,8 @@ 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).Cmd.NewShell(cmdStr).Run()
gui.logSpan(gui.Tr.Spans.CustomCommand)
err := gui.OSCommand.Cmd.NewShell(cmdStr).Run()
if err != nil {
return gui.surfaceError(err)
}

View file

@ -12,7 +12,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
{
displayString: gui.Tr.LcDiscardAllChanges,
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllChangesInDirectory).DiscardAllDirChanges(node); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardAllChangesInDirectory)
if err := gui.GitCommand.DiscardAllDirChanges(node); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
@ -24,7 +25,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.LcDiscardUnstagedChanges,
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardUnstagedChangesInDirectory).DiscardUnstagedDirChanges(node); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardUnstagedChangesInDirectory)
if err := gui.GitCommand.DiscardUnstagedDirChanges(node); err != nil {
return gui.surfaceError(err)
}
@ -52,7 +54,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
{
displayString: gui.Tr.LcDiscardAllChanges,
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllChangesInFile).DiscardAllFileChanges(file); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardAllChangesInFile)
if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
@ -64,7 +67,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.LcDiscardUnstagedChanges,
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllUnstagedChangesInFile).DiscardUnstagedFileChanges(file); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardAllUnstagedChangesInFile)
if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil {
return gui.surfaceError(err)
}

View file

@ -207,11 +207,13 @@ func (gui *Gui) handleFilePress() error {
}
if file.HasUnstagedChanges {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.StageFile).StageFile(file.Name); err != nil {
gui.logSpan(gui.Tr.Spans.StageFile)
if err := gui.GitCommand.StageFile(file.Name); err != nil {
return gui.surfaceError(err)
}
} else {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.UnstageFile).UnStageFile(file.Names(), file.Tracked); err != nil {
gui.logSpan(gui.Tr.Spans.UnstageFile)
if err := gui.GitCommand.UnStageFile(file.Names(), file.Tracked); err != nil {
return gui.surfaceError(err)
}
}
@ -223,12 +225,14 @@ func (gui *Gui) handleFilePress() error {
}
if node.GetHasUnstagedChanges() {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.StageFile).StageFile(node.Path); err != nil {
gui.logSpan(gui.Tr.Spans.StageFile)
if err := gui.GitCommand.StageFile(node.Path); err != nil {
return gui.surfaceError(err)
}
} else {
// pretty sure it doesn't matter that we're always passing true here
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.UnstageFile).UnStageFile([]string{node.Path}, true); err != nil {
gui.logSpan(gui.Tr.Spans.UnstageFile)
if err := gui.GitCommand.UnStageFile([]string{node.Path}, true); err != nil {
return gui.surfaceError(err)
}
}
@ -258,9 +262,11 @@ func (gui *Gui) onFocusFile() error {
func (gui *Gui) handleStageAll() error {
var err error
if gui.allFilesStaged() {
err = gui.GitCommand.WithSpan(gui.Tr.Spans.UnstageAllFiles).UnstageAll()
gui.logSpan(gui.Tr.Spans.UnstageAllFiles)
err = gui.GitCommand.UnstageAll()
} else {
err = gui.GitCommand.WithSpan(gui.Tr.Spans.StageAllFiles).StageAll()
gui.logSpan(gui.Tr.Spans.StageAllFiles)
err = gui.GitCommand.StageAll()
}
if err != nil {
_ = gui.surfaceError(err)
@ -283,12 +289,12 @@ func (gui *Gui) handleIgnoreFile() error {
return gui.createErrorPanel("Cannot ignore .gitignore")
}
gitCommand := gui.GitCommand.WithSpan(gui.Tr.Spans.IgnoreFile)
gui.logSpan(gui.Tr.Spans.IgnoreFile)
unstageFiles := func() error {
return node.ForEachFile(func(file *models.File) error {
if file.HasStagedChanges {
if err := gitCommand.UnStageFile(file.Names(), file.Tracked); err != nil {
if err := gui.GitCommand.UnStageFile(file.Names(), file.Tracked); err != nil {
return err
}
}
@ -307,11 +313,11 @@ func (gui *Gui) handleIgnoreFile() error {
return err
}
if err := gitCommand.RemoveTrackedFiles(node.GetPath()); err != nil {
if err := gui.GitCommand.RemoveTrackedFiles(node.GetPath()); err != nil {
return err
}
if err := gitCommand.Ignore(node.GetPath()); err != nil {
if err := gui.GitCommand.Ignore(node.GetPath()); err != nil {
return err
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{FILES}})
@ -323,7 +329,7 @@ func (gui *Gui) handleIgnoreFile() error {
return err
}
if err := gitCommand.Ignore(node.GetPath()); err != nil {
if err := gui.GitCommand.Ignore(node.GetPath()); err != nil {
return gui.surfaceError(err)
}
@ -356,7 +362,8 @@ func (gui *Gui) commitPrefixConfigForRepo() *config.CommitPrefixConfig {
func (gui *Gui) prepareFilesForCommit() error {
noStagedFiles := len(gui.stagedFiles()) == 0
if noStagedFiles && gui.UserConfig.Gui.SkipNoStagedFilesWarning {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.StageAllFiles).StageAll()
gui.logSpan(gui.Tr.Spans.StageAllFiles)
err := gui.GitCommand.StageAll()
if err != nil {
return err
}
@ -410,7 +417,8 @@ func (gui *Gui) promptToStageAllAndRetry(retry func() error) error {
title: gui.Tr.NoFilesStagedTitle,
prompt: gui.Tr.NoFilesStagedPrompt,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.StageAllFiles).StageAll(); err != nil {
gui.logSpan(gui.Tr.Spans.StageAllFiles)
if err := gui.GitCommand.StageAll(); err != nil {
return gui.surfaceError(err)
}
if err := gui.refreshFilesAndSubmodules(); err != nil {
@ -465,8 +473,9 @@ func (gui *Gui) handleCommitEditorPress() error {
cmdStr := "git " + strings.Join(args, " ")
gui.logSpan(gui.Tr.Spans.Commit)
return gui.runSubprocessWithSuspenseAndRefresh(
gui.GitCommand.WithSpan(gui.Tr.Spans.Commit).Cmd.New(cmdStr).Log(),
gui.GitCommand.Cmd.New(cmdStr),
)
}
@ -511,8 +520,9 @@ func (gui *Gui) editFileAtLine(filename string, lineNumber int) error {
return gui.surfaceError(err)
}
gui.logSpan(gui.Tr.Spans.EditFile)
return gui.runSubprocessWithSuspenseAndRefresh(
gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).Cmd.NewShell(cmdStr),
gui.OSCommand.Cmd.NewShell(cmdStr),
)
}
@ -707,9 +717,9 @@ func (gui *Gui) pullWithLock(opts PullFilesOptions) error {
gui.Mutexes.FetchMutex.Lock()
defer gui.Mutexes.FetchMutex.Unlock()
gitCommand := gui.GitCommand.WithSpan(opts.span)
gui.logSpan(opts.span)
err := gitCommand.Pull(
err := gui.GitCommand.Pull(
commands.PullOptions{
PromptUserForCredential: gui.promptUserForCredential,
RemoteName: opts.RemoteName,
@ -735,7 +745,8 @@ func (gui *Gui) push(opts pushOpts) error {
return err
}
go utils.Safe(func() {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.Push).Push(commands.PushOpts{
gui.logSpan(gui.Tr.Spans.Push)
err := gui.GitCommand.Push(commands.PushOpts{
Force: opts.force,
UpstreamRemote: opts.upstreamRemote,
UpstreamBranch: opts.upstreamBranch,
@ -891,7 +902,8 @@ func (gui *Gui) handleSwitchToMerge() error {
}
func (gui *Gui) openFile(filename string) error {
if err := gui.OSCommand.WithSpan(gui.Tr.Spans.OpenFile).OpenFile(filename); err != nil {
gui.logSpan(gui.Tr.Spans.OpenFile)
if err := gui.OSCommand.OpenFile(filename); err != nil {
return gui.surfaceError(err)
}
return nil
@ -936,13 +948,15 @@ func (gui *Gui) handleCreateStashMenu() error {
{
displayString: gui.Tr.LcStashAllChanges,
onPress: func() error {
return gui.handleStashSave(gui.GitCommand.WithSpan(gui.Tr.Spans.StashAllChanges).StashSave)
gui.logSpan(gui.Tr.Spans.StashAllChanges)
return gui.handleStashSave(gui.GitCommand.StashSave)
},
},
{
displayString: gui.Tr.LcStashStagedChanges,
onPress: func() error {
return gui.handleStashSave(gui.GitCommand.WithSpan(gui.Tr.Spans.StashStagedChanges).StashSaveStagedChanges)
gui.logSpan(gui.Tr.Spans.StashStagedChanges)
return gui.handleStashSave(gui.GitCommand.StashSaveStagedChanges)
},
},
}

View file

@ -31,8 +31,9 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err
return gui.createErrorPanel(gui.Tr.NotAGitFlowBranch)
}
gui.logSpan(gui.Tr.Spans.GitFlowFinish)
return gui.runSubprocessWithSuspenseAndRefresh(
gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowFinish).Cmd.New("git flow " + branchType + " finish " + suffix).Log(),
gui.GitCommand.Cmd.New("git flow " + branchType + " finish " + suffix),
)
}
@ -55,8 +56,9 @@ func (gui *Gui) handleCreateGitFlowMenu() error {
return gui.prompt(promptOpts{
title: title,
handleConfirm: func(name string) error {
gui.logSpan(gui.Tr.Spans.GitFlowStart)
return gui.runSubprocessWithSuspenseAndRefresh(
gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowStart).Cmd.New("git flow " + branchType + " start " + name).Log(),
gui.GitCommand.Cmd.New("git flow " + branchType + " start " + name),
)
},
})

View file

@ -216,10 +216,11 @@ func (gui *Gui) fetch(canPromptForCredentials bool, span string) (err error) {
fetchOpts := commands.FetchOptions{}
if canPromptForCredentials {
gui.logSpan(span)
fetchOpts.PromptUserForCredential = gui.promptUserForCredential
}
err = gui.GitCommand.WithSpan(span).Fetch(fetchOpts)
err = gui.GitCommand.Fetch(fetchOpts)
if canPromptForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
@ -238,7 +239,8 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
return nil
}
if err := gui.OSCommand.WithSpan(gui.Tr.Spans.CopyToClipboard).CopyToClipboard(itemId); err != nil {
gui.logSpan(gui.Tr.Spans.CopyToClipboard)
if err := gui.OSCommand.CopyToClipboard(itemId); err != nil {
return gui.surfaceError(err)
}

View file

@ -90,9 +90,8 @@ func (gui *Gui) copySelectedToClipboard() error {
return gui.withLBLActiveCheck(func(state *LblPanelState) error {
selected := state.PlainRenderSelected()
if err := gui.OSCommand.WithSpan(
gui.Tr.Spans.CopySelectedTextToClipboard,
).CopyToClipboard(selected); err != nil {
gui.logSpan(gui.Tr.Spans.CopySelectedTextToClipboard)
if err := gui.OSCommand.CopyToClipboard(selected); err != nil {
return gui.surfaceError(err)
}

View file

@ -98,7 +98,8 @@ func (gui *Gui) handleDeletePatchFromCommit() error {
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.WithSpan(gui.Tr.Spans.RemovePatchFromCommit).DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
gui.logSpan(gui.Tr.Spans.RemovePatchFromCommit)
err := gui.GitCommand.DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
return gui.handleGenericMergeCommandResult(err)
})
}
@ -114,7 +115,8 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.WithSpan(gui.Tr.Spans.MovePatchToSelectedCommit).MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLineIdx, gui.GitCommand.PatchManager)
gui.logSpan(gui.Tr.Spans.MovePatchToSelectedCommit)
err := gui.GitCommand.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLineIdx, gui.GitCommand.PatchManager)
return gui.handleGenericMergeCommandResult(err)
})
}
@ -131,7 +133,8 @@ func (gui *Gui) handleMovePatchIntoWorkingTree() error {
pull := func(stash bool) error {
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.WithSpan(gui.Tr.Spans.MovePatchIntoIndex).MovePatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager, stash)
gui.logSpan(gui.Tr.Spans.MovePatchIntoIndex)
err := gui.GitCommand.MovePatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager, stash)
return gui.handleGenericMergeCommandResult(err)
})
}
@ -160,7 +163,8 @@ func (gui *Gui) handlePullPatchIntoNewCommit() error {
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.WithSpan(gui.Tr.Spans.MovePatchIntoNewCommit).PullPatchIntoNewCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
gui.logSpan(gui.Tr.Spans.MovePatchIntoNewCommit)
err := gui.GitCommand.PullPatchIntoNewCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
return gui.handleGenericMergeCommandResult(err)
})
}
@ -174,7 +178,8 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
if reverse {
span = "Apply patch in reverse"
}
if err := gui.GitCommand.WithSpan(span).PatchManager.ApplyPatches(reverse); err != nil {
gui.logSpan(span)
if err := gui.GitCommand.PatchManager.ApplyPatches(reverse); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})

View file

@ -51,7 +51,7 @@ func (gui *Gui) genericMergeCommand(command string) error {
return gui.createErrorPanel(gui.Tr.NotMergingOrRebasing)
}
gitCommand := gui.GitCommand.WithSpan(fmt.Sprintf("Merge/Rebase: %s", command))
gui.logSpan(fmt.Sprintf("Merge/Rebase: %s", command))
commandType := ""
switch status {
@ -65,13 +65,13 @@ 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 == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit {
sub := gitCommand.Cmd.New("git " + commandType + " --" + command)
sub := gui.GitCommand.Cmd.New("git " + commandType + " --" + command)
if sub != nil {
return gui.runSubprocessWithSuspenseAndRefresh(sub)
}
return nil
}
result := gitCommand.GenericMergeOrRebaseAction(commandType, command)
result := gui.GitCommand.GenericMergeOrRebaseAction(commandType, command)
if err := gui.handleGenericMergeCommandResult(result); err != nil {
return err
}

View file

@ -93,7 +93,8 @@ func (gui *Gui) handleCheckoutReflogCommit() error {
title: gui.Tr.LcCheckoutCommit,
prompt: gui.Tr.SureCheckoutThisCommit,
handleConfirm: func() error {
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{span: gui.Tr.Spans.CheckoutReflogCommit})
gui.logSpan(gui.Tr.Spans.CheckoutReflogCommit)
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
},
})
if err != nil {

View file

@ -57,7 +57,8 @@ func (gui *Gui) handleDeleteRemoteBranch() error {
prompt: message,
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.DeletingStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.DeleteRemoteBranch).DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name, gui.promptUserForCredential)
gui.logSpan(gui.Tr.Spans.DeleteRemoteBranch)
err := gui.GitCommand.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name, gui.promptUserForCredential)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})
@ -87,7 +88,8 @@ func (gui *Gui) handleSetBranchUpstream() error {
title: gui.Tr.SetUpstreamTitle,
prompt: message,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.SetBranchUpstream).SetBranchUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil {
gui.logSpan(gui.Tr.Spans.SetBranchUpstream)
if err := gui.GitCommand.SetBranchUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil {
return gui.surfaceError(err)
}

View file

@ -85,7 +85,8 @@ func (gui *Gui) handleAddRemote() error {
return gui.prompt(promptOpts{
title: gui.Tr.LcNewRemoteUrl,
handleConfirm: func(remoteUrl string) error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.AddRemote).AddRemote(remoteName, remoteUrl); err != nil {
gui.logSpan(gui.Tr.Spans.AddRemote)
if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil {
return err
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{REMOTES}})
@ -106,7 +107,8 @@ func (gui *Gui) handleRemoveRemote() error {
title: gui.Tr.LcRemoveRemote,
prompt: gui.Tr.LcRemoveRemotePrompt + " '" + remote.Name + "'?",
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RemoveRemote).RemoveRemote(remote.Name); err != nil {
gui.logSpan(gui.Tr.Spans.RemoveRemote)
if err := gui.GitCommand.RemoveRemote(remote.Name); err != nil {
return gui.surfaceError(err)
}
@ -128,14 +130,13 @@ func (gui *Gui) handleEditRemote() error {
},
)
gitCommand := gui.GitCommand.WithSpan(gui.Tr.Spans.UpdateRemote)
return gui.prompt(promptOpts{
title: editNameMessage,
initialContent: remote.Name,
handleConfirm: func(updatedRemoteName string) error {
if updatedRemoteName != remote.Name {
if err := gitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil {
gui.logSpan(gui.Tr.Spans.UpdateRemote)
if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil {
return gui.surfaceError(err)
}
}
@ -157,7 +158,8 @@ func (gui *Gui) handleEditRemote() error {
title: editUrlMessage,
initialContent: url,
handleConfirm: func(updatedRemoteUrl string) error {
if err := gitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
gui.logSpan(gui.Tr.Spans.UpdateRemote)
if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})

View file

@ -6,8 +6,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
func (gui *Gui) resetToRef(ref string, strength string, span string, envVars []string) error {
if err := gui.GitCommand.WithSpan(span).ResetToCommit(ref, strength, envVars); err != nil {
func (gui *Gui) resetToRef(ref string, strength string, envVars []string) error {
if err := gui.GitCommand.ResetToCommit(ref, strength, envVars); err != nil {
return gui.surfaceError(err)
}
@ -38,7 +38,8 @@ func (gui *Gui) createResetMenu(ref string) error {
style.FgRed.Sprintf("reset --%s %s", strength, ref),
},
onPress: func() error {
return gui.resetToRef(ref, strength, "Reset", []string{})
gui.logSpan("Reset")
return gui.resetToRef(ref, strength, []string{})
},
}
}

View file

@ -143,7 +143,8 @@ func (gui *Gui) applySelection(reverse bool, state *LblPanelState) error {
if !reverse || state.SecondaryFocused {
applyFlags = append(applyFlags, "cached")
}
err := gui.GitCommand.WithSpan(gui.Tr.Spans.ApplyPatch).ApplyPatch(patch, applyFlags...)
gui.logSpan(gui.Tr.Spans.ApplyPatch)
err := gui.GitCommand.ApplyPatch(patch, applyFlags...)
if err != nil {
return gui.surfaceError(err)
}

View file

@ -23,10 +23,7 @@ func (gui *Gui) stashRenderToMain() error {
if stashEntry == nil {
task = NewRenderStringTask(gui.Tr.NoStashEntries)
} else {
cmdObj := gui.OSCommand.Cmd.New(
gui.GitCommand.ShowStashEntryCmdStr(stashEntry.Index),
)
task = NewRunPtyTask(cmdObj.GetCmd())
task = NewRunPtyTask(gui.GitCommand.ShowStashEntryCmdObj(stashEntry.Index).GetCmd())
}
return gui.refreshMainViews(refreshMainOpts{
@ -109,7 +106,8 @@ func (gui *Gui) stashDo(method string) error {
return gui.createErrorPanel(errorMessage)
}
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.Stash).StashDo(stashEntry.Index, method); err != nil {
gui.logSpan(gui.Tr.Spans.Stash)
if err := gui.GitCommand.StashDo(stashEntry.Index, method); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{STASH, FILES}})

View file

@ -46,7 +46,8 @@ func (gui *Gui) handleCheckoutSubCommit() error {
title: gui.Tr.LcCheckoutCommit,
prompt: gui.Tr.SureCheckoutThisCommit,
handleConfirm: func() error {
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{span: gui.Tr.Spans.CheckoutCommit})
gui.logSpan(gui.Tr.Spans.CheckoutCommit)
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
},
})
if err != nil {

View file

@ -79,7 +79,8 @@ func (gui *Gui) removeSubmodule(submodule *models.SubmoduleConfig) error {
title: gui.Tr.RemoveSubmodule,
prompt: fmt.Sprintf(gui.Tr.RemoveSubmodulePrompt, submodule.Name),
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RemoveSubmodule).SubmoduleDelete(submodule); err != nil {
gui.logSpan(gui.Tr.Spans.RemoveSubmodule)
if err := gui.GitCommand.SubmoduleDelete(submodule); err != nil {
return gui.surfaceError(err)
}
@ -105,19 +106,19 @@ func (gui *Gui) fileForSubmodule(submodule *models.SubmoduleConfig) *models.File
}
func (gui *Gui) resetSubmodule(submodule *models.SubmoduleConfig) error {
gitCommand := gui.GitCommand.WithSpan(gui.Tr.Spans.ResetSubmodule)
gui.logSpan(gui.Tr.Spans.ResetSubmodule)
file := gui.fileForSubmodule(submodule)
if file != nil {
if err := gitCommand.UnStageFile(file.Names(), file.Tracked); err != nil {
if err := gui.GitCommand.UnStageFile(file.Names(), file.Tracked); err != nil {
return gui.surfaceError(err)
}
}
if err := gitCommand.SubmoduleStash(submodule); err != nil {
if err := gui.GitCommand.SubmoduleStash(submodule); err != nil {
return gui.surfaceError(err)
}
if err := gitCommand.SubmoduleReset(submodule); err != nil {
if err := gui.GitCommand.SubmoduleReset(submodule); err != nil {
return gui.surfaceError(err)
}
@ -140,7 +141,8 @@ func (gui *Gui) handleAddSubmodule() error {
initialContent: submoduleName,
handleConfirm: func(submodulePath string) error {
return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.AddSubmodule).SubmoduleAdd(submoduleName, submodulePath, submoduleUrl)
gui.logSpan(gui.Tr.Spans.AddSubmodule)
err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
@ -160,7 +162,8 @@ func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error
initialContent: submodule.Url,
handleConfirm: func(newUrl string) error {
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.UpdateSubmoduleUrl).SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl)
gui.logSpan(gui.Tr.Spans.UpdateSubmoduleUrl)
err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
@ -171,7 +174,8 @@ func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error
func (gui *Gui) handleSubmoduleInit(submodule *models.SubmoduleConfig) error {
return gui.WithWaitingStatus(gui.Tr.LcInitializingSubmoduleStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.InitialiseSubmodule).SubmoduleInit(submodule.Path)
gui.logSpan(gui.Tr.Spans.InitialiseSubmodule)
err := gui.GitCommand.SubmoduleInit(submodule.Path)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
@ -214,7 +218,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
displayStrings: []string{gui.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(gui.GitCommand.SubmoduleBulkInitCmdObj().ToString())},
onPress: func() error {
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.BulkInitialiseSubmodules).SubmoduleBulkInitCmdObj().Run()
gui.logSpan(gui.Tr.Spans.BulkInitialiseSubmodules)
err := gui.GitCommand.SubmoduleBulkInitCmdObj().Run()
if err != nil {
return gui.surfaceError(err)
}
@ -227,7 +232,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
displayStrings: []string{gui.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(gui.GitCommand.SubmoduleBulkUpdateCmdObj().ToString())},
onPress: func() error {
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.BulkUpdateSubmodules).SubmoduleBulkUpdateCmdObj().Run(); err != nil {
gui.logSpan(gui.Tr.Spans.BulkUpdateSubmodules)
if err := gui.GitCommand.SubmoduleBulkUpdateCmdObj().Run(); err != nil {
return gui.surfaceError(err)
}
@ -239,7 +245,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
displayStrings: []string{gui.Tr.LcSubmoduleStashAndReset, style.FgRed.Sprintf("git stash in each submodule && %s", gui.GitCommand.SubmoduleForceBulkUpdateCmdObj().ToString())},
onPress: func() error {
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.BulkStashAndResetSubmodules).ResetSubmodules(gui.State.Submodules); err != nil {
gui.logSpan(gui.Tr.Spans.BulkStashAndResetSubmodules)
if err := gui.GitCommand.ResetSubmodules(gui.State.Submodules); err != nil {
return gui.surfaceError(err)
}
@ -251,7 +258,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
displayStrings: []string{gui.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(gui.GitCommand.SubmoduleBulkDeinitCmdObj().ToString())},
onPress: func() error {
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.BulkDeinitialiseSubmodules).SubmoduleBulkDeinitCmdObj().Run(); err != nil {
gui.logSpan(gui.Tr.Spans.BulkDeinitialiseSubmodules)
if err := gui.GitCommand.SubmoduleBulkDeinitCmdObj().Run(); err != nil {
return gui.surfaceError(err)
}
@ -266,7 +274,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
func (gui *Gui) handleUpdateSubmodule(submodule *models.SubmoduleConfig) error {
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.UpdateSubmodule).SubmoduleUpdate(submodule.Path)
gui.logSpan(gui.Tr.Spans.UpdateSubmodule)
err := gui.GitCommand.SubmoduleUpdate(submodule.Path)
gui.handleCredentialsPopup(err)
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})

View file

@ -63,7 +63,8 @@ func (gui *Gui) withSelectedTag(f func(tag *models.Tag) error) func() error {
// tag-specific handlers
func (gui *Gui) handleCheckoutTag(tag *models.Tag) error {
if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{span: gui.Tr.Spans.CheckoutTag}); err != nil {
gui.logSpan(gui.Tr.Spans.CheckoutTag)
if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil {
return err
}
return gui.pushContext(gui.State.Contexts.Branches)
@ -81,7 +82,8 @@ func (gui *Gui) handleDeleteTag(tag *models.Tag) error {
title: gui.Tr.DeleteTagTitle,
prompt: prompt,
handleConfirm: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DeleteTag).DeleteTag(tag.Name); err != nil {
gui.logSpan(gui.Tr.Spans.DeleteTag)
if err := gui.GitCommand.DeleteTag(tag.Name); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
@ -103,7 +105,8 @@ func (gui *Gui) handlePushTag(tag *models.Tag) error {
findSuggestionsFunc: gui.getRemoteSuggestionsFunc(),
handleConfirm: func(response string) error {
return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error {
err := gui.GitCommand.WithSpan(gui.Tr.Spans.PushTag).PushTag(response, tag.Name, gui.promptUserForCredential)
gui.logSpan(gui.Tr.Spans.PushTag)
err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential)
gui.handleCredentialsPopup(err)
return nil

View file

@ -92,8 +92,6 @@ func (gui *Gui) reflogUndo() error {
return gui.createErrorPanel(gui.Tr.LcCantUndoWhileRebasing)
}
span := gui.Tr.Spans.Undo
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
if counter != 0 {
return false, nil
@ -101,16 +99,16 @@ func (gui *Gui) reflogUndo() error {
switch action.kind {
case COMMIT, REBASE:
gui.logSpan(gui.Tr.Spans.Undo)
return true, gui.handleHardResetWithAutoStash(action.from, handleHardResetWithAutoStashOptions{
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
span: span,
})
case CHECKOUT:
gui.logSpan(gui.Tr.Spans.Undo)
return true, gui.handleCheckoutRef(action.from, handleCheckoutRefOptions{
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
span: span,
})
}
@ -127,8 +125,6 @@ func (gui *Gui) reflogRedo() error {
return gui.createErrorPanel(gui.Tr.LcCantRedoWhileRebasing)
}
span := gui.Tr.Spans.Redo
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
// if we're redoing and the counter is zero, we just return
if counter == 0 {
@ -139,16 +135,16 @@ func (gui *Gui) reflogRedo() error {
switch action.kind {
case COMMIT, REBASE:
gui.logSpan(gui.Tr.Spans.Redo)
return true, gui.handleHardResetWithAutoStash(action.to, handleHardResetWithAutoStashOptions{
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
span: span,
})
case CHECKOUT:
gui.logSpan(gui.Tr.Spans.Redo)
return true, gui.handleCheckoutRef(action.to, handleCheckoutRefOptions{
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
span: span,
})
}
@ -160,15 +156,12 @@ func (gui *Gui) reflogRedo() error {
type handleHardResetWithAutoStashOptions struct {
WaitingStatus string
EnvVars []string
span string
}
// only to be used in the undo flow for now
func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHardResetWithAutoStashOptions) error {
gitCommand := gui.GitCommand.WithSpan(options.span)
reset := func() error {
if err := gui.resetToRef(commitSha, "hard", options.span, options.EnvVars); err != nil {
if err := gui.resetToRef(commitSha, "hard", options.EnvVars); err != nil {
return gui.surfaceError(err)
}
return nil
@ -183,14 +176,14 @@ func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHar
prompt: gui.Tr.AutoStashPrompt,
handleConfirm: func() error {
return gui.WithWaitingStatus(options.WaitingStatus, func() error {
if err := gitCommand.StashSave(gui.Tr.StashPrefix + commitSha); err != nil {
if err := gui.GitCommand.StashSave(gui.Tr.StashPrefix + commitSha); err != nil {
return gui.surfaceError(err)
}
if err := reset(); err != nil {
return err
}
err := gitCommand.StashDo(0, "pop")
err := gui.GitCommand.StashDo(0, "pop")
if err := gui.refreshSidePanels(refreshOptions{}); err != nil {
return err
}

View file

@ -21,7 +21,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint(nukeStr),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.NukeWorkingTree).ResetAndClean(); err != nil {
gui.logSpan(gui.Tr.Spans.NukeWorkingTree)
if err := gui.GitCommand.ResetAndClean(); err != nil {
return gui.surfaceError(err)
}
@ -34,7 +35,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint("git checkout -- ."),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardUnstagedFileChanges).DiscardAnyUnstagedFileChanges(); err != nil {
gui.logSpan(gui.Tr.Spans.DiscardUnstagedFileChanges)
if err := gui.GitCommand.DiscardAnyUnstagedFileChanges(); err != nil {
return gui.surfaceError(err)
}
@ -47,7 +49,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint("git clean -fd"),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RemoveUntrackedFiles).RemoveUntrackedFiles(); err != nil {
gui.logSpan(gui.Tr.Spans.RemoveUntrackedFiles)
if err := gui.GitCommand.RemoveUntrackedFiles(); err != nil {
return gui.surfaceError(err)
}
@ -60,7 +63,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint("git reset --soft HEAD"),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.SoftReset).ResetSoft("HEAD"); err != nil {
gui.logSpan(gui.Tr.Spans.SoftReset)
if err := gui.GitCommand.ResetSoft("HEAD"); err != nil {
return gui.surfaceError(err)
}
@ -73,7 +77,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint("git reset --mixed HEAD"),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.MixedReset).ResetMixed("HEAD"); err != nil {
gui.logSpan(gui.Tr.Spans.MixedReset)
if err := gui.GitCommand.ResetMixed("HEAD"); err != nil {
return gui.surfaceError(err)
}
@ -86,7 +91,8 @@ func (gui *Gui) handleCreateResetMenu() error {
red.Sprint("git reset --hard HEAD"),
},
onPress: func() error {
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.HardReset).ResetHard("HEAD"); err != nil {
gui.logSpan(gui.Tr.Spans.HardReset)
if err := gui.GitCommand.ResetHard("HEAD"); err != nil {
return gui.surfaceError(err)
}