1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00
This commit is contained in:
Jesse Duffield 2020-08-21 20:50:54 +10:00
parent 1956301b1c
commit 59f5f5c1af
6 changed files with 26 additions and 9 deletions

View File

@ -46,8 +46,9 @@ func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager
}
// NewPatchManager returns a new PatchManager
func (p *PatchManager) Start(parent string, diffMap map[string]string) {
func (p *PatchManager) Start(parent string, diffMap map[string]string, canRebase bool) {
p.Parent = parent
p.CanRebase = canRebase
p.fileInfoMap = map[string]*fileInfo{}
for filename, diff := range diffMap {
p.fileInfoMap[filename] = &fileInfo{

View File

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

View File

@ -505,7 +505,7 @@ func (gui *Gui) handleViewCommitFiles() error {
return nil
}
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.BranchCommits.Context, "commits")
return gui.switchToCommitFilesContext(commit.Sha, REF_TYPE_LOCAL_COMMIT, gui.Contexts.BranchCommits.Context, "commits")
}
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {

View File

@ -188,7 +188,7 @@ type commitFilesPanelState struct {
// this is the SHA of the commit or the stash index of the stash.
// Not sure if ref is actually the right word here
refName string
isStash bool // true if we're dealing with a stash entry rather than a commit
refType int // eg REF_TYPE_LOCAL_COMMIT
}
type panelStates struct {

View File

@ -119,5 +119,5 @@ func (gui *Gui) handleViewReflogCommitFiles() error {
return nil
}
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits.Context, "commits")
return gui.switchToCommitFilesContext(commit.Sha, REF_TYPE_OTHER_COMMIT, gui.Contexts.ReflogCommits.Context, "commits")
}

View File

@ -135,5 +135,5 @@ func (gui *Gui) handleViewStashFiles() error {
return nil
}
return gui.switchToCommitFilesContext(stashEntry.RefName(), true, gui.Contexts.Stash.Context, "stash")
return gui.switchToCommitFilesContext(stashEntry.RefName(), REF_TYPE_STASH, gui.Contexts.Stash.Context, "stash")
}