summaryrefslogtreecommitdiffstats
path: root/pkg/gui/commit_files_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-21 20:50:54 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commit59f5f5c1af4ab52f91d8bc6538fb460a21e880a8 (patch)
tree0c9931f2aaad1eaa5f4a6317e3e54bd191c0dc52 /pkg/gui/commit_files_panel.go
parent1956301b1cdcb6c1a920e395bce8f6fdf19f3cfa (diff)
refactor
Diffstat (limited to 'pkg/gui/commit_files_panel.go')
-rw-r--r--pkg/gui/commit_files_panel.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index 2cdf0c02f..556c1088c 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -6,6 +6,20 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands"
)
+const (
+ // these are the possible ref types for refs that you can view files of.
+ // for local commits, we're allowed to build a patch and do things involving rebasing
+ // with that patch
+ REF_TYPE_LOCAL_COMMIT = iota
+
+ // for other kinds of commits like reflog commits, we can't do anything rebasey
+ REF_TYPE_OTHER_COMMIT
+
+ // for stash entries we can't do anything rebasey, and the command for
+ // obtaining the files is slightly different
+ REF_TYPE_STASH
+)
+
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
if selectedLine == -1 {
@@ -80,7 +94,8 @@ func (gui *Gui) refreshCommitFilesView() error {
return err
}
- files, err := gui.GitCommand.GetFilesInRef(gui.State.Panels.CommitFiles.refName, gui.State.Panels.CommitFiles.isStash, gui.GitCommand.PatchManager)
+ isStash := gui.State.Panels.CommitFiles.refType == REF_TYPE_STASH
+ files, err := gui.GitCommand.GetFilesInRef(gui.State.Panels.CommitFiles.refName, isStash, gui.GitCommand.PatchManager)
if err != nil {
return gui.surfaceError(err)
}
@@ -159,7 +174,8 @@ func (gui *Gui) startPatchManager() error {
diffMap[commitFile.Name] = commitText
}
- gui.GitCommand.PatchManager.Start(gui.State.Panels.CommitFiles.refName, diffMap)
+ canRebase := gui.State.Panels.CommitFiles.refType == REF_TYPE_LOCAL_COMMIT
+ gui.GitCommand.PatchManager.Start(gui.State.Panels.CommitFiles.refName, diffMap, canRebase)
return nil
}
@@ -210,14 +226,14 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
return enterTheFile(selectedLineIdx)
}
-func (gui *Gui) switchToCommitFilesContext(refName string, isStash bool, context Context, windowName string) error {
+func (gui *Gui) switchToCommitFilesContext(refName string, refType int, context Context, windowName string) error {
// sometimes the commitFiles view is already shown in another window, so we need to ensure that window
// no longer considers the commitFiles view as its main view.
gui.resetWindowForView("commitFiles")
gui.State.Panels.CommitFiles.SelectedLineIdx = 0
gui.State.Panels.CommitFiles.refName = refName
- gui.State.Panels.CommitFiles.isStash = isStash
+ gui.State.Panels.CommitFiles.refType = refType
gui.Contexts.CommitFiles.Context.SetParentContext(context)
gui.Contexts.CommitFiles.Context.SetWindowName(windowName)