summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-28 12:08:13 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-28 13:19:35 +1100
commita9559a5c8738d6938f8750f0729f077e0842800e (patch)
tree6bf8ae15c80891325227261d46880d5f2e553c0b
parent814ee24c8d13ae554925530ec68f325394ddfe6d (diff)
move working tree state function into git.go
-rw-r--r--pkg/commands/git.go12
-rw-r--r--pkg/gui/files_panel.go6
-rw-r--r--pkg/gui/merge_panel.go2
-rw-r--r--pkg/gui/patch_options_panel.go2
-rw-r--r--pkg/gui/rebase_options_panel.go6
-rw-r--r--pkg/gui/status_panel.go8
-rw-r--r--pkg/gui/undoing.go4
7 files changed, 26 insertions, 14 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index f2a4706cc..19fe9c219 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -1192,3 +1192,15 @@ func (c *GitCommand) colorArg() string {
func (c *GitCommand) RenameBranch(oldName string, newName string) error {
return c.OSCommand.RunCommand("git branch --move %s %s", oldName, newName)
}
+
+func (c *GitCommand) WorkingTreeState() string {
+ rebaseMode, _ := c.RebaseMode()
+ if rebaseMode != "" {
+ return "rebasing"
+ }
+ merging, _ := c.IsInMergeState()
+ if merging {
+ return "merging"
+ }
+ return "normal"
+}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index b78d1b752..d3ecbdce4 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -278,7 +278,7 @@ func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error
}
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
- if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" {
+ if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
}
commitMessageView := gui.getCommitMessageView()
@@ -298,7 +298,7 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
}
func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error {
- if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" {
+ if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
}
if len(gui.State.Commits) == 0 {
@@ -324,7 +324,7 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
// handleCommitEditorPress - handle when the user wants to commit changes via
// their editor rather than via the popup panel
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {
- if len(gui.stagedFiles()) == 0 && gui.workingTreeState() == "normal" {
+ if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
}
gui.PrepareSubProcess(g, "git", "commit")
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go
index fa238ccb7..ba222a493 100644
--- a/pkg/gui/merge_panel.go
+++ b/pkg/gui/merge_panel.go
@@ -281,7 +281,7 @@ func (gui *Gui) handleCompleteMerge() error {
}
// if we got conflicts after unstashing, we don't want to call any git
// commands to continue rebasing/merging here
- if gui.workingTreeState() == "normal" {
+ if gui.GitCommand.WorkingTreeState() == "normal" {
return gui.handleEscapeMerge(gui.g, gui.getMainView())
}
// if there are no more files with merge conflicts, we should ask whether the user wants to continue
diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go
index 2fa274f7c..b8e88d903 100644
--- a/pkg/gui/patch_options_panel.go
+++ b/pkg/gui/patch_options_panel.go
@@ -59,7 +59,7 @@ func (gui *Gui) getPatchCommitIndex() int {
}
func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
- if gui.workingTreeState() != "normal" {
+ if gui.GitCommand.WorkingTreeState() != "normal" {
return false, gui.createErrorPanel(gui.Tr.SLocalize("CantPatchWhileRebasingError"))
}
return true, nil
diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go
index 5de1a7e3c..233f77e64 100644
--- a/pkg/gui/rebase_options_panel.go
+++ b/pkg/gui/rebase_options_panel.go
@@ -10,7 +10,7 @@ import (
func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error {
options := []string{"continue", "abort"}
- if gui.workingTreeState() == "rebasing" {
+ if gui.GitCommand.WorkingTreeState() == "rebasing" {
options = append(options, "skip")
}
@@ -27,7 +27,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error
}
var title string
- if gui.workingTreeState() == "merging" {
+ if gui.GitCommand.WorkingTreeState() == "merging" {
title = gui.Tr.SLocalize("MergeOptionsTitle")
} else {
title = gui.Tr.SLocalize("RebaseOptionsTitle")
@@ -37,7 +37,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error
}
func (gui *Gui) genericMergeCommand(command string) error {
- status := gui.workingTreeState()
+ status := gui.GitCommand.WorkingTreeState()
if status != "merging" && status != "rebasing" {
return gui.createErrorPanel(gui.Tr.SLocalize("NotMergingOrRebasing"))
diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go
index 207e493bb..6a21f2926 100644
--- a/pkg/gui/status_panel.go
+++ b/pkg/gui/status_panel.go
@@ -33,8 +33,8 @@ func (gui *Gui) refreshStatus() {
status = utils.ColoredString(fmt.Sprintf("ā†‘%sā†“%s ", currentBranch.Pushables, currentBranch.Pullables), trackColor)
}
- if gui.workingTreeState() != "normal" {
- status += utils.ColoredString(fmt.Sprintf("(%s) ", gui.workingTreeState()), color.FgYellow)
+ if gui.GitCommand.WorkingTreeState() != "normal" {
+ status += utils.ColoredString(fmt.Sprintf("(%s) ", gui.GitCommand.WorkingTreeState()), color.FgYellow)
}
name := utils.ColoredString(currentBranch.Name, presentation.GetBranchColor(currentBranch.Name))
@@ -66,9 +66,9 @@ func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error {
cx, _ := v.Cursor()
upstreamStatus := fmt.Sprintf("ā†‘%sā†“%s", currentBranch.Pushables, currentBranch.Pullables)
repoName := utils.GetCurrentRepoName()
- switch gui.workingTreeState() {
+ switch gui.GitCommand.WorkingTreeState() {
case "rebasing", "merging":
- workingTreeStatus := fmt.Sprintf("(%s)", gui.workingTreeState())
+ workingTreeStatus := fmt.Sprintf("(%s)", gui.GitCommand.WorkingTreeState())
if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) {
return gui.handleCreateRebaseOptionsMenu(gui.g, v)
}
diff --git a/pkg/gui/undoing.go b/pkg/gui/undoing.go
index 3ef863539..9ce7f7b0e 100644
--- a/pkg/gui/undoing.go
+++ b/pkg/gui/undoing.go
@@ -87,7 +87,7 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"}
undoingStatus := gui.Tr.SLocalize("UndoingStatus")
- if gui.workingTreeState() == "rebasing" {
+ if gui.GitCommand.WorkingTreeState() == "rebasing" {
return gui.createErrorPanel(gui.Tr.SLocalize("cantUndoWhileRebasing"))
}
@@ -118,7 +118,7 @@ func (gui *Gui) reflogRedo(g *gocui.Gui, v *gocui.View) error {
redoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit redo]"}
redoingStatus := gui.Tr.SLocalize("RedoingStatus")
- if gui.workingTreeState() == "rebasing" {
+ if gui.GitCommand.WorkingTreeState() == "rebasing" {
return gui.createErrorPanel(gui.Tr.SLocalize("cantRedoWhileRebasing"))
}