mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-19 22:33:16 +02:00
simplify how we log commands
This commit is contained in:
parent
e524e39842
commit
05fa483f48
@ -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
|
// 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)'
|
// e.g. name is 123asdf and displayname is '(HEAD detached at 123asdf)'
|
||||||
func (c *GitCommand) CurrentBranchName() (string, string, error) {
|
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" {
|
if err == nil && branchName != "HEAD\n" {
|
||||||
trimmedBranchName := strings.TrimSpace(branchName)
|
trimmedBranchName := strings.TrimSpace(branchName)
|
||||||
return trimmedBranchName, trimmedBranchName, nil
|
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 {
|
if err != nil {
|
||||||
return "", "", err
|
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
|
// Currently it limits the result to 100 commits, but when we get async stuff
|
||||||
// working we can do lazy loading
|
// working we can do lazy loading
|
||||||
func (c *GitCommand) GetBranchGraph(branchName string) (string, error) {
|
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) {
|
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
|
return strings.TrimSpace(output), err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func (c *GitCommand) GetBranchGraphCmdObj(branchName string) oscommands.ICmdObj
|
|||||||
templateValues := map[string]string{
|
templateValues := map[string]string{
|
||||||
"branchName": c.OSCommand.Quote(branchName),
|
"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 {
|
func (c *GitCommand) SetUpstreamBranch(upstream string) error {
|
||||||
@ -110,11 +110,11 @@ func (c *GitCommand) GetBranchUpstreamDifferenceCount(branchName string) (string
|
|||||||
// current branch
|
// current branch
|
||||||
func (c *GitCommand) GetCommitDifferences(from, to string) (string, string) {
|
func (c *GitCommand) GetCommitDifferences(from, to string) (string, string) {
|
||||||
command := "git rev-list %s..%s --count"
|
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 {
|
if err != nil {
|
||||||
return "?", "?"
|
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 {
|
if err != nil {
|
||||||
return "?", "?"
|
return "?", "?"
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func (c *GitCommand) AbortMerge() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) IsHeadDetached() bool {
|
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
|
return err != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,5 +169,5 @@ func (c *GitCommand) RenameBranch(oldName string, newName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GetRawBranches() (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()
|
||||||
}
|
}
|
||||||
|
@ -40,19 +40,19 @@ func (c *GitCommand) CommitCmdObj(message string, flags string) oscommands.ICmdO
|
|||||||
|
|
||||||
// Get the subject of the HEAD commit
|
// Get the subject of the HEAD commit
|
||||||
func (c *GitCommand) GetHeadCommitMessage() (string, error) {
|
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
|
return strings.TrimSpace(message), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GetCommitMessage(commitSha string) (string, error) {
|
func (c *GitCommand) GetCommitMessage(commitSha string) (string, error) {
|
||||||
cmdStr := "git rev-list --format=%B --max-count=1 " + commitSha
|
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")
|
message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "\n")
|
||||||
return strings.TrimSpace(message), err
|
return strings.TrimSpace(message), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GetCommitMessageFirstLine(sha string) (string, error) {
|
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
|
// 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)
|
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
|
// Revert reverts the selected commit by sha
|
||||||
|
@ -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)
|
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 {
|
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 "
|
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
|
// 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)
|
// 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 {
|
if err := c.OSCommand.Remove(fileName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er
|
|||||||
editor = c.OSCommand.Getenv("EDITOR")
|
editor = c.OSCommand.Getenv("EDITOR")
|
||||||
}
|
}
|
||||||
if 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"
|
editor = "vi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,29 +111,6 @@ func NewGitCommand(
|
|||||||
return gitCommand, nil
|
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 {
|
func navigateToRepoRootDirectory(stat func(string) (os.FileInfo, error), chdir func(string) error) error {
|
||||||
gitDir := env.GetGitDirEnv()
|
gitDir := env.GetGitDirEnv()
|
||||||
if gitDir != "" {
|
if gitDir != "" {
|
||||||
@ -245,7 +222,7 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func VerifyInGitRepo(osCommand *oscommands.OSCommand) error {
|
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 {
|
func (c *GitCommand) GetDotGitDir() string {
|
||||||
|
@ -28,7 +28,7 @@ func (self *CommitFileLoader) GetFilesInDiff(from string, to string, reverse boo
|
|||||||
reverseFlag = " -R "
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
|
|||||||
prettyFormat,
|
prettyFormat,
|
||||||
20,
|
20,
|
||||||
),
|
),
|
||||||
)
|
).DontLog()
|
||||||
|
|
||||||
hydratedCommits := make([]*models.Commit, 0, len(commits))
|
hydratedCommits := make([]*models.Commit, 0, len(commits))
|
||||||
i := 0
|
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
|
// 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
|
return ignoringWarnings(output), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,6 +405,7 @@ func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {
|
|||||||
New(
|
New(
|
||||||
fmt.Sprintf("git merge-base %s %s@{u}", self.cmd.Quote(refName), self.cmd.Quote(refName)),
|
fmt.Sprintf("git merge-base %s %s@{u}", self.cmd.Quote(refName), self.cmd.Quote(refName)),
|
||||||
).
|
).
|
||||||
|
DontLog().
|
||||||
RunWithOutput()
|
RunWithOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -444,7 +445,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
|
|||||||
20,
|
20,
|
||||||
filterFlag,
|
filterFlag,
|
||||||
),
|
),
|
||||||
)
|
).DontLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
var prettyFormat = fmt.Sprintf(
|
var prettyFormat = fmt.Sprintf(
|
||||||
|
@ -98,7 +98,7 @@ func (c *FileLoader) GitStatus(opts GitStatusOptions) ([]FileStatus, error) {
|
|||||||
noRenamesFlag = " --no-renames"
|
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 {
|
if err != nil {
|
||||||
return []FileStatus{}, err
|
return []FileStatus{}, err
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit
|
|||||||
filterPathArg = fmt.Sprintf(" --follow -- %s", self.cmd.Quote(filterPath))
|
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
|
onlyObtainedNewReflogCommits := false
|
||||||
err := cmdObj.RunAndProcessLines(func(line string) (bool, error) {
|
err := cmdObj.RunAndProcessLines(func(line string) (bool, error) {
|
||||||
fields := strings.SplitN(line, " ", 3)
|
fields := strings.SplitN(line, " ", 3)
|
||||||
|
@ -31,7 +31,7 @@ func NewRemoteLoader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
|
|||||||
return self.getUnfilteredStashEntries()
|
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 {
|
if err != nil {
|
||||||
return self.getUnfilteredStashEntries()
|
return self.getUnfilteredStashEntries()
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
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{}
|
stashEntries := []*models.StashEntry{}
|
||||||
for i, line := range utils.SplitLines(rawString) {
|
for i, line := range utils.SplitLines(rawString) {
|
||||||
stashEntries = append(stashEntries, self.stashEntryFromLine(line, i))
|
stashEntries = append(stashEntries, self.stashEntryFromLine(line, i))
|
||||||
|
@ -27,7 +27,7 @@ func NewTagLoader(
|
|||||||
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
||||||
// get remote branches, sorted by creation date (descending)
|
// get remote branches, sorted by creation date (descending)
|
||||||
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// 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
|
RunAndProcessLines(onLine func(line string) (bool, error)) error
|
||||||
|
|
||||||
// logs command
|
// Marks the command object as readonly, so that when it is run, we don't log it to the user.
|
||||||
Log() ICmdObj
|
// We only want to log commands to the user which change state in some way.
|
||||||
|
DontLog() ICmdObj
|
||||||
|
ShouldLog() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CmdObj struct {
|
type CmdObj struct {
|
||||||
cmdStr string
|
cmdStr string
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
|
|
||||||
runner ICmdObjRunner
|
runner ICmdObjRunner
|
||||||
logCommand func(ICmdObj)
|
|
||||||
|
// if set to true, we don't want to log the command to the user.
|
||||||
|
dontLog bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObj) GetCmd() *exec.Cmd {
|
func (self *CmdObj) GetCmd() *exec.Cmd {
|
||||||
@ -52,12 +56,15 @@ func (self *CmdObj) GetEnvVars() []string {
|
|||||||
return self.cmd.Env
|
return self.cmd.Env
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObj) Log() ICmdObj {
|
func (self *CmdObj) DontLog() ICmdObj {
|
||||||
self.logCommand(self)
|
self.dontLog = true
|
||||||
|
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *CmdObj) ShouldLog() bool {
|
||||||
|
return !self.dontLog
|
||||||
|
}
|
||||||
|
|
||||||
func (self *CmdObj) Run() error {
|
func (self *CmdObj) Run() error {
|
||||||
return self.runner.Run(self)
|
return self.runner.Run(self)
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,9 @@ func (self *CmdObjBuilder) New(cmdStr string) ICmdObj {
|
|||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
return &CmdObj{
|
return &CmdObj{
|
||||||
cmdStr: cmdStr,
|
cmdStr: cmdStr,
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
runner: self.runner,
|
runner: self.runner,
|
||||||
logCommand: self.logCmdObj,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +46,9 @@ func (self *CmdObjBuilder) NewFromArgs(args []string) ICmdObj {
|
|||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
return &CmdObj{
|
return &CmdObj{
|
||||||
cmdStr: strings.Join(args, " "),
|
cmdStr: strings.Join(args, " "),
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
runner: self.runner,
|
runner: self.runner,
|
||||||
logCommand: self.logCmdObj,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,19 @@ type cmdObjRunner struct {
|
|||||||
var _ ICmdObjRunner = &cmdObjRunner{}
|
var _ ICmdObjRunner = &cmdObjRunner{}
|
||||||
|
|
||||||
func (self *cmdObjRunner) Run(cmdObj ICmdObj) error {
|
func (self *cmdObjRunner) Run(cmdObj ICmdObj) error {
|
||||||
|
if cmdObj.ShouldLog() {
|
||||||
|
self.logCmdObj(cmdObj)
|
||||||
|
}
|
||||||
|
|
||||||
_, err := self.RunWithOutput(cmdObj)
|
_, err := self.RunWithOutput(cmdObj)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) {
|
func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) {
|
||||||
self.logCmdObj(cmdObj)
|
if cmdObj.ShouldLog() {
|
||||||
|
self.logCmdObj(cmdObj)
|
||||||
|
}
|
||||||
|
|
||||||
output, err := sanitisedCommandOutput(cmdObj.GetCmd().CombinedOutput())
|
output, err := sanitisedCommandOutput(cmdObj.GetCmd().CombinedOutput())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
self.log.WithField("command", cmdObj.ToString()).Error(output)
|
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 {
|
func (self *cmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line string) (bool, error)) error {
|
||||||
|
if cmdObj.ShouldLog() {
|
||||||
|
self.logCmdObj(cmdObj)
|
||||||
|
}
|
||||||
|
|
||||||
cmd := cmdObj.GetCmd()
|
cmd := cmdObj.GetCmd()
|
||||||
stdoutPipe, err := cmd.StdoutPipe()
|
stdoutPipe, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,7 +66,9 @@ func RunCommandWithOutputLiveAux(
|
|||||||
startCmd func(cmd *exec.Cmd) (*cmdHandler, error),
|
startCmd func(cmd *exec.Cmd) (*cmdHandler, error),
|
||||||
) error {
|
) error {
|
||||||
c.Log.WithField("command", cmdObj.ToString()).Info("RunCommand")
|
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()
|
cmd := cmdObj.AddEnvVars("LANG=en_US.UTF-8", "LC_ALL=en_US.UTF-8").GetCmd()
|
||||||
|
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
|
@ -87,22 +87,6 @@ func NewOSCommand(common *common.Common, platform *Platform) *OSCommand {
|
|||||||
return c
|
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) {
|
func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
|
||||||
c.LogCommand(cmdObj.ToString(), true)
|
c.LogCommand(cmdObj.ToString(), true)
|
||||||
}
|
}
|
||||||
@ -110,7 +94,7 @@ func (c *OSCommand) LogCmdObj(cmdObj ICmdObj) {
|
|||||||
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
|
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
|
||||||
c.Log.WithField("command", cmdStr).Info("RunCommand")
|
c.Log.WithField("command", cmdStr).Info("RunCommand")
|
||||||
|
|
||||||
if c.onRunCommand != nil && c.CmdLogSpan != "" {
|
if c.onRunCommand != nil {
|
||||||
c.onRunCommand(NewCmdLogEntry(cmdStr, c.CmdLogSpan, commandLine))
|
c.onRunCommand(NewCmdLogEntry(cmdStr, c.CmdLogSpan, commandLine))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,9 @@ func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool {
|
|||||||
New(
|
New(
|
||||||
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
|
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
|
||||||
c.Cmd.Quote(branchName),
|
c.Cmd.Quote(branchName),
|
||||||
)).
|
),
|
||||||
|
).
|
||||||
|
DontLog().
|
||||||
RunWithOutput()
|
RunWithOutput()
|
||||||
|
|
||||||
return err == nil
|
return err == nil
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StashDo modify stash
|
// 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()
|
return c.Cmd.New("git stash save " + c.OSCommand.Quote(message)).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStashEntryDiff stash diff
|
func (c *GitCommand) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
|
||||||
func (c *GitCommand) ShowStashEntryCmdStr(index int) string {
|
cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.UserConfig.Git.DiffContextSize, index)
|
||||||
return 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
|
// StashSaveStagedChanges stashes only the currently staged changes. This takes a few steps
|
||||||
|
@ -25,7 +25,7 @@ func TestGitCommandStashSave(t *testing.T) {
|
|||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandShowStashEntryCmdStr(t *testing.T) {
|
func TestGitCommandShowStashEntryCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
index int
|
index int
|
||||||
@ -52,7 +52,7 @@ func TestGitCommandShowStashEntryCmdStr(t *testing.T) {
|
|||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
||||||
cmdStr := gitCmd.ShowStashEntryCmdStr(s.index)
|
cmdStr := gitCmd.ShowStashEntryCmdObj(s.index).ToString()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,12 @@ func (c *GitCommand) Fetch(opts FetchOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdObj := c.Cmd.New(cmdStr)
|
cmdObj := c.Cmd.New(cmdStr)
|
||||||
|
userInitiated := opts.PromptUserForCredential != nil
|
||||||
|
if !userInitiated {
|
||||||
|
cmdObj.DontLog()
|
||||||
|
}
|
||||||
return c.DetectUnamePass(cmdObj, func(question string) string {
|
return c.DetectUnamePass(cmdObj, func(question string) string {
|
||||||
if opts.PromptUserForCredential != nil {
|
if userInitiated {
|
||||||
return opts.PromptUserForCredential(question)
|
return opts.PromptUserForCredential(question)
|
||||||
}
|
}
|
||||||
return "\n"
|
return "\n"
|
||||||
|
@ -80,7 +80,8 @@ func (gui *Gui) handleBranchPress() error {
|
|||||||
return gui.createErrorPanel(gui.Tr.AlreadyCheckedOutBranch)
|
return gui.createErrorPanel(gui.Tr.AlreadyCheckedOutBranch)
|
||||||
}
|
}
|
||||||
branch := gui.getSelectedBranch()
|
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 {
|
func (gui *Gui) handleCreatePullRequestPress() error {
|
||||||
@ -145,7 +146,8 @@ func (gui *Gui) handleForceCheckout() error {
|
|||||||
title: title,
|
title: title,
|
||||||
prompt: message,
|
prompt: message,
|
||||||
handleConfirm: func() error {
|
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)
|
_ = gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
@ -157,7 +159,6 @@ type handleCheckoutRefOptions struct {
|
|||||||
WaitingStatus string
|
WaitingStatus string
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
onRefNotFound func(ref string) error
|
onRefNotFound func(ref string) error
|
||||||
span string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) error {
|
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
|
gui.State.Panels.Commits.LimitCommits = true
|
||||||
}
|
}
|
||||||
|
|
||||||
gitCommand := gui.GitCommand.WithSpan(options.span)
|
|
||||||
|
|
||||||
return gui.WithWaitingStatus(waitingStatus, func() error {
|
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
|
// 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") {
|
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,
|
title: gui.Tr.AutoStashTitle,
|
||||||
prompt: gui.Tr.AutoStashPrompt,
|
prompt: gui.Tr.AutoStashPrompt,
|
||||||
handleConfirm: func() error {
|
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)
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
onSuccess()
|
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 {
|
if err := gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -226,10 +225,9 @@ func (gui *Gui) handleCheckoutByName() error {
|
|||||||
title: gui.Tr.BranchName + ":",
|
title: gui.Tr.BranchName + ":",
|
||||||
findSuggestionsFunc: gui.getRefsSuggestionsFunc(),
|
findSuggestionsFunc: gui.getRefsSuggestionsFunc(),
|
||||||
handleConfirm: func(response string) error {
|
handleConfirm: func(response string) error {
|
||||||
|
gui.logSpan("Checkout branch")
|
||||||
return gui.handleCheckoutRef(response, handleCheckoutRefOptions{
|
return gui.handleCheckoutRef(response, handleCheckoutRefOptions{
|
||||||
span: "Checkout branch",
|
|
||||||
onRefNotFound: func(ref string) error {
|
onRefNotFound: func(ref string) error {
|
||||||
|
|
||||||
return gui.ask(askOpts{
|
return gui.ask(askOpts{
|
||||||
title: gui.Tr.BranchNotFoundTitle,
|
title: gui.Tr.BranchNotFoundTitle,
|
||||||
prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"),
|
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,
|
title: title,
|
||||||
prompt: message,
|
prompt: message,
|
||||||
handleConfirm: func() error {
|
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()
|
errMessage := err.Error()
|
||||||
if !force && strings.Contains(errMessage, "git branch -D ") {
|
if !force && strings.Contains(errMessage, "git branch -D ") {
|
||||||
return gui.deleteNamedBranch(selectedBranch, true)
|
return gui.deleteNamedBranch(selectedBranch, true)
|
||||||
@ -336,7 +335,8 @@ func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error {
|
|||||||
title: gui.Tr.MergingTitle,
|
title: gui.Tr.MergingTitle,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -377,7 +377,8 @@ func (gui *Gui) handleRebaseOntoBranch(selectedBranchName string) error {
|
|||||||
title: gui.Tr.RebasingTitle,
|
title: gui.Tr.RebasingTitle,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -420,7 +421,8 @@ func (gui *Gui) handleFastForward() error {
|
|||||||
if gui.State.Panels.Branches.SelectedLineIdx == 0 {
|
if gui.State.Panels.Branches.SelectedLineIdx == 0 {
|
||||||
_ = gui.pullWithLock(PullFilesOptions{span: span, FastForwardOnly: true})
|
_ = gui.pullWithLock(PullFilesOptions{span: span, FastForwardOnly: true})
|
||||||
} else {
|
} 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.handleCredentialsPopup(err)
|
||||||
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{BRANCHES}})
|
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{BRANCHES}})
|
||||||
}
|
}
|
||||||
@ -448,7 +450,8 @@ func (gui *Gui) handleRenameBranch() error {
|
|||||||
title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":",
|
title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":",
|
||||||
initialContent: branch.Name,
|
initialContent: branch.Name,
|
||||||
handleConfirm: func(newBranchName string) error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +519,8 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
|
|||||||
title: message,
|
title: message,
|
||||||
initialContent: prefilledName,
|
initialContent: prefilledName,
|
||||||
handleConfirm: func(response string) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,8 @@ func (gui *Gui) HandlePasteCommits() error {
|
|||||||
prompt: gui.Tr.SureCherryPick,
|
prompt: gui.Tr.SureCherryPick,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.CherryPickingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -13,9 +13,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
|
func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
|
||||||
// closing over this so that nobody else can modify it
|
|
||||||
currentSpan := ""
|
|
||||||
|
|
||||||
return func(entry oscommands.CmdLogEntry) {
|
return func(entry oscommands.CmdLogEntry) {
|
||||||
if gui.Views.Extras == nil {
|
if gui.Views.Extras == nil {
|
||||||
return
|
return
|
||||||
@ -23,11 +20,6 @@ func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) {
|
|||||||
|
|
||||||
gui.Views.Extras.Autoscroll = true
|
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
|
textStyle := theme.DefaultTextColor
|
||||||
if !entry.GetCommandLine() {
|
if !entry.GetCommandLine() {
|
||||||
textStyle = style.FgMagenta
|
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() {
|
func (gui *Gui) printCommandLogHeader() {
|
||||||
introStr := fmt.Sprintf(
|
introStr := fmt.Sprintf(
|
||||||
gui.Tr.CommandLogHeader,
|
gui.Tr.CommandLogHeader,
|
||||||
|
@ -63,7 +63,8 @@ func (gui *Gui) handleCheckoutCommitFile() error {
|
|||||||
return nil
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,8 @@ func (gui *Gui) handleDiscardOldFileChange() error {
|
|||||||
prompt: gui.Tr.DiscardFileChangesPrompt,
|
prompt: gui.Tr.DiscardFileChangesPrompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, 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 {
|
if err := gui.handleGenericMergeCommandResult(err); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,8 @@ func (gui *Gui) handleCommitSquashDown() error {
|
|||||||
prompt: gui.Tr.SureSquashThisCommit,
|
prompt: gui.Tr.SureSquashThisCommit,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -202,7 +203,8 @@ func (gui *Gui) handleCommitFixup() error {
|
|||||||
prompt: gui.Tr.SureFixupThisCommit,
|
prompt: gui.Tr.SureFixupThisCommit,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.FixingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -240,7 +242,8 @@ func (gui *Gui) handleRenameCommit() error {
|
|||||||
title: gui.Tr.LcRenameCommit,
|
title: gui.Tr.LcRenameCommit,
|
||||||
initialContent: message,
|
initialContent: message,
|
||||||
handleConfirm: func(response string) error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +265,8 @@ func (gui *Gui) handleRenameCommitEditor() error {
|
|||||||
return nil
|
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 {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
@ -321,7 +325,8 @@ func (gui *Gui) handleCommitDelete() error {
|
|||||||
prompt: gui.Tr.DeleteCommitPrompt,
|
prompt: gui.Tr.DeleteCommitPrompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.DeletingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -358,7 +363,8 @@ func (gui *Gui) handleCommitMoveDown() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() 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 {
|
if err == nil {
|
||||||
gui.State.Panels.Commits.SelectedLineIdx++
|
gui.State.Panels.Commits.SelectedLineIdx++
|
||||||
}
|
}
|
||||||
@ -396,7 +402,8 @@ func (gui *Gui) handleCommitMoveUp() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() 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 {
|
if err == nil {
|
||||||
gui.State.Panels.Commits.SelectedLineIdx--
|
gui.State.Panels.Commits.SelectedLineIdx--
|
||||||
}
|
}
|
||||||
@ -418,7 +425,8 @@ func (gui *Gui) handleCommitEdit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -433,7 +441,8 @@ func (gui *Gui) handleCommitAmendTo() error {
|
|||||||
prompt: gui.Tr.AmendCommitPrompt,
|
prompt: gui.Tr.AmendCommitPrompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.AmendingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -468,7 +477,8 @@ func (gui *Gui) handleCommitRevert() error {
|
|||||||
if commit.IsMerge() {
|
if commit.IsMerge() {
|
||||||
return gui.createRevertMergeCommitMenu(commit)
|
return gui.createRevertMergeCommitMenu(commit)
|
||||||
} else {
|
} 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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.afterRevertCommit()
|
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),
|
displayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
parentNumber := i + 1
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.afterRevertCommit()
|
return gui.afterRevertCommit()
|
||||||
@ -534,7 +545,8 @@ func (gui *Gui) handleCreateFixupCommit() error {
|
|||||||
title: gui.Tr.CreateFixupCommit,
|
title: gui.Tr.CreateFixupCommit,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +577,8 @@ func (gui *Gui) handleSquashAllAboveFixupCommits() error {
|
|||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, 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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -612,7 +625,8 @@ func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
|
|||||||
return gui.prompt(promptOpts{
|
return gui.prompt(promptOpts{
|
||||||
title: gui.Tr.TagMessageTitle,
|
title: gui.Tr.TagMessageTitle,
|
||||||
handleConfirm: func(msg string) error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.afterTagCreate(tagName)
|
return gui.afterTagCreate(tagName)
|
||||||
@ -626,7 +640,8 @@ func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
|
|||||||
return gui.prompt(promptOpts{
|
return gui.prompt(promptOpts{
|
||||||
title: gui.Tr.TagNameTitle,
|
title: gui.Tr.TagNameTitle,
|
||||||
handleConfirm: func(tagName string) error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.afterTagCreate(tagName)
|
return gui.afterTagCreate(tagName)
|
||||||
@ -644,7 +659,8 @@ func (gui *Gui) handleCheckoutCommit() error {
|
|||||||
title: gui.Tr.LcCheckoutCommit,
|
title: gui.Tr.LcCheckoutCommit,
|
||||||
prompt: gui.Tr.SureCheckoutThisCommit,
|
prompt: gui.Tr.SureCheckoutThisCommit,
|
||||||
handleConfirm: func() error {
|
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)
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,8 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
|||||||
loadingText = gui.Tr.LcRunningCustomCommandStatus
|
loadingText = gui.Tr.LcRunningCustomCommandStatus
|
||||||
}
|
}
|
||||||
return gui.WithWaitingStatus(loadingText, func() error {
|
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 {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
|
|||||||
{
|
{
|
||||||
displayString: gui.Tr.LcDiscardAllChanges,
|
displayString: gui.Tr.LcDiscardAllChanges,
|
||||||
onPress: func() error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
||||||
@ -24,7 +25,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
|
|||||||
menuItems = append(menuItems, &menuItem{
|
menuItems = append(menuItems, &menuItem{
|
||||||
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
|
|||||||
{
|
{
|
||||||
displayString: gui.Tr.LcDiscardAllChanges,
|
displayString: gui.Tr.LcDiscardAllChanges,
|
||||||
onPress: func() error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
||||||
@ -64,7 +67,8 @@ func (gui *Gui) handleCreateDiscardMenu() error {
|
|||||||
menuItems = append(menuItems, &menuItem{
|
menuItems = append(menuItems, &menuItem{
|
||||||
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,11 +207,13 @@ func (gui *Gui) handleFilePress() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if file.HasUnstagedChanges {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,12 +225,14 @@ func (gui *Gui) handleFilePress() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if node.GetHasUnstagedChanges() {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// pretty sure it doesn't matter that we're always passing true here
|
// 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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,9 +262,11 @@ func (gui *Gui) onFocusFile() error {
|
|||||||
func (gui *Gui) handleStageAll() error {
|
func (gui *Gui) handleStageAll() error {
|
||||||
var err error
|
var err error
|
||||||
if gui.allFilesStaged() {
|
if gui.allFilesStaged() {
|
||||||
err = gui.GitCommand.WithSpan(gui.Tr.Spans.UnstageAllFiles).UnstageAll()
|
gui.logSpan(gui.Tr.Spans.UnstageAllFiles)
|
||||||
|
err = gui.GitCommand.UnstageAll()
|
||||||
} else {
|
} else {
|
||||||
err = gui.GitCommand.WithSpan(gui.Tr.Spans.StageAllFiles).StageAll()
|
gui.logSpan(gui.Tr.Spans.StageAllFiles)
|
||||||
|
err = gui.GitCommand.StageAll()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = gui.surfaceError(err)
|
_ = gui.surfaceError(err)
|
||||||
@ -283,12 +289,12 @@ func (gui *Gui) handleIgnoreFile() error {
|
|||||||
return gui.createErrorPanel("Cannot ignore .gitignore")
|
return gui.createErrorPanel("Cannot ignore .gitignore")
|
||||||
}
|
}
|
||||||
|
|
||||||
gitCommand := gui.GitCommand.WithSpan(gui.Tr.Spans.IgnoreFile)
|
gui.logSpan(gui.Tr.Spans.IgnoreFile)
|
||||||
|
|
||||||
unstageFiles := func() error {
|
unstageFiles := func() error {
|
||||||
return node.ForEachFile(func(file *models.File) error {
|
return node.ForEachFile(func(file *models.File) error {
|
||||||
if file.HasStagedChanges {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,11 +313,11 @@ func (gui *Gui) handleIgnoreFile() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitCommand.RemoveTrackedFiles(node.GetPath()); err != nil {
|
if err := gui.GitCommand.RemoveTrackedFiles(node.GetPath()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitCommand.Ignore(node.GetPath()); err != nil {
|
if err := gui.GitCommand.Ignore(node.GetPath()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{FILES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{FILES}})
|
||||||
@ -323,7 +329,7 @@ func (gui *Gui) handleIgnoreFile() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitCommand.Ignore(node.GetPath()); err != nil {
|
if err := gui.GitCommand.Ignore(node.GetPath()); err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +362,8 @@ func (gui *Gui) commitPrefixConfigForRepo() *config.CommitPrefixConfig {
|
|||||||
func (gui *Gui) prepareFilesForCommit() error {
|
func (gui *Gui) prepareFilesForCommit() error {
|
||||||
noStagedFiles := len(gui.stagedFiles()) == 0
|
noStagedFiles := len(gui.stagedFiles()) == 0
|
||||||
if noStagedFiles && gui.UserConfig.Gui.SkipNoStagedFilesWarning {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -410,7 +417,8 @@ func (gui *Gui) promptToStageAllAndRetry(retry func() error) error {
|
|||||||
title: gui.Tr.NoFilesStagedTitle,
|
title: gui.Tr.NoFilesStagedTitle,
|
||||||
prompt: gui.Tr.NoFilesStagedPrompt,
|
prompt: gui.Tr.NoFilesStagedPrompt,
|
||||||
handleConfirm: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
if err := gui.refreshFilesAndSubmodules(); err != nil {
|
if err := gui.refreshFilesAndSubmodules(); err != nil {
|
||||||
@ -465,8 +473,9 @@ func (gui *Gui) handleCommitEditorPress() error {
|
|||||||
|
|
||||||
cmdStr := "git " + strings.Join(args, " ")
|
cmdStr := "git " + strings.Join(args, " ")
|
||||||
|
|
||||||
|
gui.logSpan(gui.Tr.Spans.Commit)
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.logSpan(gui.Tr.Spans.EditFile)
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(
|
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()
|
gui.Mutexes.FetchMutex.Lock()
|
||||||
defer gui.Mutexes.FetchMutex.Unlock()
|
defer gui.Mutexes.FetchMutex.Unlock()
|
||||||
|
|
||||||
gitCommand := gui.GitCommand.WithSpan(opts.span)
|
gui.logSpan(opts.span)
|
||||||
|
|
||||||
err := gitCommand.Pull(
|
err := gui.GitCommand.Pull(
|
||||||
commands.PullOptions{
|
commands.PullOptions{
|
||||||
PromptUserForCredential: gui.promptUserForCredential,
|
PromptUserForCredential: gui.promptUserForCredential,
|
||||||
RemoteName: opts.RemoteName,
|
RemoteName: opts.RemoteName,
|
||||||
@ -735,7 +745,8 @@ func (gui *Gui) push(opts pushOpts) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go utils.Safe(func() {
|
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,
|
Force: opts.force,
|
||||||
UpstreamRemote: opts.upstreamRemote,
|
UpstreamRemote: opts.upstreamRemote,
|
||||||
UpstreamBranch: opts.upstreamBranch,
|
UpstreamBranch: opts.upstreamBranch,
|
||||||
@ -891,7 +902,8 @@ func (gui *Gui) handleSwitchToMerge() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) openFile(filename string) 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 gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -936,13 +948,15 @@ func (gui *Gui) handleCreateStashMenu() error {
|
|||||||
{
|
{
|
||||||
displayString: gui.Tr.LcStashAllChanges,
|
displayString: gui.Tr.LcStashAllChanges,
|
||||||
onPress: func() error {
|
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,
|
displayString: gui.Tr.LcStashStagedChanges,
|
||||||
onPress: func() error {
|
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)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,9 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err
|
|||||||
return gui.createErrorPanel(gui.Tr.NotAGitFlowBranch)
|
return gui.createErrorPanel(gui.Tr.NotAGitFlowBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.logSpan(gui.Tr.Spans.GitFlowFinish)
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(
|
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{
|
return gui.prompt(promptOpts{
|
||||||
title: title,
|
title: title,
|
||||||
handleConfirm: func(name string) error {
|
handleConfirm: func(name string) error {
|
||||||
|
gui.logSpan(gui.Tr.Spans.GitFlowStart)
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(
|
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),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -216,10 +216,11 @@ func (gui *Gui) fetch(canPromptForCredentials bool, span string) (err error) {
|
|||||||
|
|
||||||
fetchOpts := commands.FetchOptions{}
|
fetchOpts := commands.FetchOptions{}
|
||||||
if canPromptForCredentials {
|
if canPromptForCredentials {
|
||||||
|
gui.logSpan(span)
|
||||||
fetchOpts.PromptUserForCredential = gui.promptUserForCredential
|
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") {
|
if canPromptForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
|
||||||
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
|
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
|
||||||
@ -238,7 +239,8 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
|
|||||||
return nil
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +90,8 @@ func (gui *Gui) copySelectedToClipboard() error {
|
|||||||
return gui.withLBLActiveCheck(func(state *LblPanelState) error {
|
return gui.withLBLActiveCheck(func(state *LblPanelState) error {
|
||||||
selected := state.PlainRenderSelected()
|
selected := state.PlainRenderSelected()
|
||||||
|
|
||||||
if err := gui.OSCommand.WithSpan(
|
gui.logSpan(gui.Tr.Spans.CopySelectedTextToClipboard)
|
||||||
gui.Tr.Spans.CopySelectedTextToClipboard,
|
if err := gui.OSCommand.CopyToClipboard(selected); err != nil {
|
||||||
).CopyToClipboard(selected); err != nil {
|
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,8 @@ func (gui *Gui) handleDeletePatchFromCommit() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -114,7 +115,8 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -131,7 +133,8 @@ func (gui *Gui) handleMovePatchIntoWorkingTree() error {
|
|||||||
pull := func(stash bool) error {
|
pull := func(stash bool) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -160,7 +163,8 @@ func (gui *Gui) handlePullPatchIntoNewCommit() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
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)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -174,7 +178,8 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
|
|||||||
if reverse {
|
if reverse {
|
||||||
span = "Apply patch in 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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
|
@ -51,7 +51,7 @@ func (gui *Gui) genericMergeCommand(command string) error {
|
|||||||
return gui.createErrorPanel(gui.Tr.NotMergingOrRebasing)
|
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 := ""
|
commandType := ""
|
||||||
switch status {
|
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
|
// 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 {
|
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 {
|
if sub != nil {
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(sub)
|
return gui.runSubprocessWithSuspenseAndRefresh(sub)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
result := gitCommand.GenericMergeOrRebaseAction(commandType, command)
|
result := gui.GitCommand.GenericMergeOrRebaseAction(commandType, command)
|
||||||
if err := gui.handleGenericMergeCommandResult(result); err != nil {
|
if err := gui.handleGenericMergeCommandResult(result); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,8 @@ func (gui *Gui) handleCheckoutReflogCommit() error {
|
|||||||
title: gui.Tr.LcCheckoutCommit,
|
title: gui.Tr.LcCheckoutCommit,
|
||||||
prompt: gui.Tr.SureCheckoutThisCommit,
|
prompt: gui.Tr.SureCheckoutThisCommit,
|
||||||
handleConfirm: func() error {
|
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 {
|
if err != nil {
|
||||||
|
@ -57,7 +57,8 @@ func (gui *Gui) handleDeleteRemoteBranch() error {
|
|||||||
prompt: message,
|
prompt: message,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.DeletingStatus, 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})
|
||||||
@ -87,7 +88,8 @@ func (gui *Gui) handleSetBranchUpstream() error {
|
|||||||
title: gui.Tr.SetUpstreamTitle,
|
title: gui.Tr.SetUpstreamTitle,
|
||||||
prompt: message,
|
prompt: message,
|
||||||
handleConfirm: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,8 @@ func (gui *Gui) handleAddRemote() error {
|
|||||||
return gui.prompt(promptOpts{
|
return gui.prompt(promptOpts{
|
||||||
title: gui.Tr.LcNewRemoteUrl,
|
title: gui.Tr.LcNewRemoteUrl,
|
||||||
handleConfirm: func(remoteUrl string) error {
|
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 err
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{REMOTES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{REMOTES}})
|
||||||
@ -106,7 +107,8 @@ func (gui *Gui) handleRemoveRemote() error {
|
|||||||
title: gui.Tr.LcRemoveRemote,
|
title: gui.Tr.LcRemoveRemote,
|
||||||
prompt: gui.Tr.LcRemoveRemotePrompt + " '" + remote.Name + "'?",
|
prompt: gui.Tr.LcRemoveRemotePrompt + " '" + remote.Name + "'?",
|
||||||
handleConfirm: func() error {
|
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)
|
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{
|
return gui.prompt(promptOpts{
|
||||||
title: editNameMessage,
|
title: editNameMessage,
|
||||||
initialContent: remote.Name,
|
initialContent: remote.Name,
|
||||||
handleConfirm: func(updatedRemoteName string) error {
|
handleConfirm: func(updatedRemoteName string) error {
|
||||||
if updatedRemoteName != remote.Name {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +158,8 @@ func (gui *Gui) handleEditRemote() error {
|
|||||||
title: editUrlMessage,
|
title: editUrlMessage,
|
||||||
initialContent: url,
|
initialContent: url,
|
||||||
handleConfirm: func(updatedRemoteUrl string) error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}})
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) resetToRef(ref string, strength string, span string, envVars []string) error {
|
func (gui *Gui) resetToRef(ref string, strength string, envVars []string) error {
|
||||||
if err := gui.GitCommand.WithSpan(span).ResetToCommit(ref, strength, envVars); err != nil {
|
if err := gui.GitCommand.ResetToCommit(ref, strength, envVars); err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,8 @@ func (gui *Gui) createResetMenu(ref string) error {
|
|||||||
style.FgRed.Sprintf("reset --%s %s", strength, ref),
|
style.FgRed.Sprintf("reset --%s %s", strength, ref),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.resetToRef(ref, strength, "Reset", []string{})
|
gui.logSpan("Reset")
|
||||||
|
return gui.resetToRef(ref, strength, []string{})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,8 @@ func (gui *Gui) applySelection(reverse bool, state *LblPanelState) error {
|
|||||||
if !reverse || state.SecondaryFocused {
|
if !reverse || state.SecondaryFocused {
|
||||||
applyFlags = append(applyFlags, "cached")
|
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 {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,7 @@ func (gui *Gui) stashRenderToMain() error {
|
|||||||
if stashEntry == nil {
|
if stashEntry == nil {
|
||||||
task = NewRenderStringTask(gui.Tr.NoStashEntries)
|
task = NewRenderStringTask(gui.Tr.NoStashEntries)
|
||||||
} else {
|
} else {
|
||||||
cmdObj := gui.OSCommand.Cmd.New(
|
task = NewRunPtyTask(gui.GitCommand.ShowStashEntryCmdObj(stashEntry.Index).GetCmd())
|
||||||
gui.GitCommand.ShowStashEntryCmdStr(stashEntry.Index),
|
|
||||||
)
|
|
||||||
task = NewRunPtyTask(cmdObj.GetCmd())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.refreshMainViews(refreshMainOpts{
|
return gui.refreshMainViews(refreshMainOpts{
|
||||||
@ -109,7 +106,8 @@ func (gui *Gui) stashDo(method string) error {
|
|||||||
|
|
||||||
return gui.createErrorPanel(errorMessage)
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{STASH, FILES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{STASH, FILES}})
|
||||||
|
@ -46,7 +46,8 @@ func (gui *Gui) handleCheckoutSubCommit() error {
|
|||||||
title: gui.Tr.LcCheckoutCommit,
|
title: gui.Tr.LcCheckoutCommit,
|
||||||
prompt: gui.Tr.SureCheckoutThisCommit,
|
prompt: gui.Tr.SureCheckoutThisCommit,
|
||||||
handleConfirm: func() error {
|
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 {
|
if err != nil {
|
||||||
|
@ -79,7 +79,8 @@ func (gui *Gui) removeSubmodule(submodule *models.SubmoduleConfig) error {
|
|||||||
title: gui.Tr.RemoveSubmodule,
|
title: gui.Tr.RemoveSubmodule,
|
||||||
prompt: fmt.Sprintf(gui.Tr.RemoveSubmodulePrompt, submodule.Name),
|
prompt: fmt.Sprintf(gui.Tr.RemoveSubmodulePrompt, submodule.Name),
|
||||||
handleConfirm: func() error {
|
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)
|
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 {
|
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)
|
file := gui.fileForSubmodule(submodule)
|
||||||
if file != nil {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitCommand.SubmoduleStash(submodule); err != nil {
|
if err := gui.GitCommand.SubmoduleStash(submodule); err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
if err := gitCommand.SubmoduleReset(submodule); err != nil {
|
if err := gui.GitCommand.SubmoduleReset(submodule); err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +141,8 @@ func (gui *Gui) handleAddSubmodule() error {
|
|||||||
initialContent: submoduleName,
|
initialContent: submoduleName,
|
||||||
handleConfirm: func(submodulePath string) error {
|
handleConfirm: func(submodulePath string) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
||||||
@ -160,7 +162,8 @@ func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error
|
|||||||
initialContent: submodule.Url,
|
initialContent: submodule.Url,
|
||||||
handleConfirm: func(newUrl string) error {
|
handleConfirm: func(newUrl string) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
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 {
|
func (gui *Gui) handleSubmoduleInit(submodule *models.SubmoduleConfig) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcInitializingSubmoduleStatus, func() 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
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())},
|
displayStrings: []string{gui.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(gui.GitCommand.SubmoduleBulkInitCmdObj().ToString())},
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, 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 {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
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())},
|
displayStrings: []string{gui.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(gui.GitCommand.SubmoduleBulkUpdateCmdObj().ToString())},
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, 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)
|
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())},
|
displayStrings: []string{gui.Tr.LcSubmoduleStashAndReset, style.FgRed.Sprintf("git stash in each submodule && %s", gui.GitCommand.SubmoduleForceBulkUpdateCmdObj().ToString())},
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, 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)
|
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())},
|
displayStrings: []string{gui.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(gui.GitCommand.SubmoduleBulkDeinitCmdObj().ToString())},
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcRunningCommand, 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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +274,8 @@ func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
|
|||||||
|
|
||||||
func (gui *Gui) handleUpdateSubmodule(submodule *models.SubmoduleConfig) error {
|
func (gui *Gui) handleUpdateSubmodule(submodule *models.SubmoduleConfig) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleStatus, func() 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{SUBMODULES}})
|
||||||
|
@ -63,7 +63,8 @@ func (gui *Gui) withSelectedTag(f func(tag *models.Tag) error) func() error {
|
|||||||
// tag-specific handlers
|
// tag-specific handlers
|
||||||
|
|
||||||
func (gui *Gui) handleCheckoutTag(tag *models.Tag) error {
|
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 err
|
||||||
}
|
}
|
||||||
return gui.pushContext(gui.State.Contexts.Branches)
|
return gui.pushContext(gui.State.Contexts.Branches)
|
||||||
@ -81,7 +82,8 @@ func (gui *Gui) handleDeleteTag(tag *models.Tag) error {
|
|||||||
title: gui.Tr.DeleteTagTitle,
|
title: gui.Tr.DeleteTagTitle,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
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.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
|
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(),
|
findSuggestionsFunc: gui.getRemoteSuggestionsFunc(),
|
||||||
handleConfirm: func(response string) error {
|
handleConfirm: func(response string) error {
|
||||||
return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() 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)
|
gui.handleCredentialsPopup(err)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -92,8 +92,6 @@ func (gui *Gui) reflogUndo() error {
|
|||||||
return gui.createErrorPanel(gui.Tr.LcCantUndoWhileRebasing)
|
return gui.createErrorPanel(gui.Tr.LcCantUndoWhileRebasing)
|
||||||
}
|
}
|
||||||
|
|
||||||
span := gui.Tr.Spans.Undo
|
|
||||||
|
|
||||||
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
||||||
if counter != 0 {
|
if counter != 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -101,16 +99,16 @@ func (gui *Gui) reflogUndo() error {
|
|||||||
|
|
||||||
switch action.kind {
|
switch action.kind {
|
||||||
case COMMIT, REBASE:
|
case COMMIT, REBASE:
|
||||||
|
gui.logSpan(gui.Tr.Spans.Undo)
|
||||||
return true, gui.handleHardResetWithAutoStash(action.from, handleHardResetWithAutoStashOptions{
|
return true, gui.handleHardResetWithAutoStash(action.from, handleHardResetWithAutoStashOptions{
|
||||||
EnvVars: undoEnvVars,
|
EnvVars: undoEnvVars,
|
||||||
WaitingStatus: undoingStatus,
|
WaitingStatus: undoingStatus,
|
||||||
span: span,
|
|
||||||
})
|
})
|
||||||
case CHECKOUT:
|
case CHECKOUT:
|
||||||
|
gui.logSpan(gui.Tr.Spans.Undo)
|
||||||
return true, gui.handleCheckoutRef(action.from, handleCheckoutRefOptions{
|
return true, gui.handleCheckoutRef(action.from, handleCheckoutRefOptions{
|
||||||
EnvVars: undoEnvVars,
|
EnvVars: undoEnvVars,
|
||||||
WaitingStatus: undoingStatus,
|
WaitingStatus: undoingStatus,
|
||||||
span: span,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +125,6 @@ func (gui *Gui) reflogRedo() error {
|
|||||||
return gui.createErrorPanel(gui.Tr.LcCantRedoWhileRebasing)
|
return gui.createErrorPanel(gui.Tr.LcCantRedoWhileRebasing)
|
||||||
}
|
}
|
||||||
|
|
||||||
span := gui.Tr.Spans.Redo
|
|
||||||
|
|
||||||
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
||||||
// if we're redoing and the counter is zero, we just return
|
// if we're redoing and the counter is zero, we just return
|
||||||
if counter == 0 {
|
if counter == 0 {
|
||||||
@ -139,16 +135,16 @@ func (gui *Gui) reflogRedo() error {
|
|||||||
|
|
||||||
switch action.kind {
|
switch action.kind {
|
||||||
case COMMIT, REBASE:
|
case COMMIT, REBASE:
|
||||||
|
gui.logSpan(gui.Tr.Spans.Redo)
|
||||||
return true, gui.handleHardResetWithAutoStash(action.to, handleHardResetWithAutoStashOptions{
|
return true, gui.handleHardResetWithAutoStash(action.to, handleHardResetWithAutoStashOptions{
|
||||||
EnvVars: redoEnvVars,
|
EnvVars: redoEnvVars,
|
||||||
WaitingStatus: redoingStatus,
|
WaitingStatus: redoingStatus,
|
||||||
span: span,
|
|
||||||
})
|
})
|
||||||
case CHECKOUT:
|
case CHECKOUT:
|
||||||
|
gui.logSpan(gui.Tr.Spans.Redo)
|
||||||
return true, gui.handleCheckoutRef(action.to, handleCheckoutRefOptions{
|
return true, gui.handleCheckoutRef(action.to, handleCheckoutRefOptions{
|
||||||
EnvVars: redoEnvVars,
|
EnvVars: redoEnvVars,
|
||||||
WaitingStatus: redoingStatus,
|
WaitingStatus: redoingStatus,
|
||||||
span: span,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,15 +156,12 @@ func (gui *Gui) reflogRedo() error {
|
|||||||
type handleHardResetWithAutoStashOptions struct {
|
type handleHardResetWithAutoStashOptions struct {
|
||||||
WaitingStatus string
|
WaitingStatus string
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
span string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only to be used in the undo flow for now
|
// only to be used in the undo flow for now
|
||||||
func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHardResetWithAutoStashOptions) error {
|
func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHardResetWithAutoStashOptions) error {
|
||||||
gitCommand := gui.GitCommand.WithSpan(options.span)
|
|
||||||
|
|
||||||
reset := func() error {
|
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 gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -183,14 +176,14 @@ func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHar
|
|||||||
prompt: gui.Tr.AutoStashPrompt,
|
prompt: gui.Tr.AutoStashPrompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
return gui.WithWaitingStatus(options.WaitingStatus, 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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
if err := reset(); err != nil {
|
if err := reset(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := gitCommand.StashDo(0, "pop")
|
err := gui.GitCommand.StashDo(0, "pop")
|
||||||
if err := gui.refreshSidePanels(refreshOptions{}); err != nil {
|
if err := gui.refreshSidePanels(refreshOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint(nukeStr),
|
red.Sprint(nukeStr),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +35,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint("git checkout -- ."),
|
red.Sprint("git checkout -- ."),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +49,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint("git clean -fd"),
|
red.Sprint("git clean -fd"),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +63,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint("git reset --soft HEAD"),
|
red.Sprint("git reset --soft HEAD"),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +77,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint("git reset --mixed HEAD"),
|
red.Sprint("git reset --mixed HEAD"),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +91,8 @@ func (gui *Gui) handleCreateResetMenu() error {
|
|||||||
red.Sprint("git reset --hard HEAD"),
|
red.Sprint("git reset --hard HEAD"),
|
||||||
},
|
},
|
||||||
onPress: func() error {
|
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)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user