mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-10 11:10:18 +02:00
support drilling down into the files of a diff
This commit is contained in:
parent
438abd6003
commit
e290710f67
@ -1052,14 +1052,29 @@ func (c *GitCommand) GetFilesInRef(parent string, isStash bool, patchManager *pa
|
||||
command = "git stash show"
|
||||
}
|
||||
|
||||
files, err := c.OSCommand.RunCommandWithOutput("%s --no-commit-id --name-only -r --no-renames %s", command, parent)
|
||||
filenames, err := c.OSCommand.RunCommandWithOutput("%s --no-commit-id --name-only -r --no-renames %s", command, parent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.GetCommitFilesFromFilenames(filenames, parent, patchManager), nil
|
||||
}
|
||||
|
||||
// GetFilesInDiff get the specified commit files
|
||||
func (c *GitCommand) GetFilesInDiff(from string, to string, parent string, patchManager *patch.PatchManager) ([]*CommitFile, error) {
|
||||
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --name-only %s %s", from, to)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.GetCommitFilesFromFilenames(filenames, parent, patchManager), nil
|
||||
}
|
||||
|
||||
// filenames string is something like "file1\nfile2\nfile3"
|
||||
func (c *GitCommand) GetCommitFilesFromFilenames(filenames string, parent string, patchManager *patch.PatchManager) []*CommitFile {
|
||||
commitFiles := make([]*CommitFile, 0)
|
||||
|
||||
for _, file := range strings.Split(strings.TrimRight(files, "\n"), "\n") {
|
||||
for _, file := range strings.Split(strings.TrimRight(filenames, "\n"), "\n") {
|
||||
status := patch.UNSELECTED
|
||||
if patchManager != nil && patchManager.Parent == parent {
|
||||
status = patchManager.GetFileStatus(file)
|
||||
@ -1073,7 +1088,7 @@ func (c *GitCommand) GetFilesInRef(parent string, isStash bool, patchManager *pa
|
||||
})
|
||||
}
|
||||
|
||||
return commitFiles, nil
|
||||
return commitFiles
|
||||
}
|
||||
|
||||
// ShowCommitFile get the diff of specified commit file
|
||||
|
@ -94,7 +94,24 @@ func (gui *Gui) refreshCommitFilesView() error {
|
||||
}
|
||||
|
||||
isStash := gui.State.Panels.CommitFiles.refType == REF_TYPE_STASH
|
||||
files, err := gui.GitCommand.GetFilesInRef(gui.State.Panels.CommitFiles.refName, isStash, gui.GitCommand.PatchManager)
|
||||
refName := gui.State.Panels.CommitFiles.refName
|
||||
diffing := gui.State.Modes.Diffing
|
||||
|
||||
var files []*commands.CommitFile
|
||||
var err error
|
||||
if diffing.Active() {
|
||||
from := diffing.Ref
|
||||
to := refName
|
||||
|
||||
if diffing.Reverse {
|
||||
from, to = to, from
|
||||
}
|
||||
|
||||
files, err = gui.GitCommand.GetFilesInDiff(from, to, refName, gui.GitCommand.PatchManager)
|
||||
} else {
|
||||
files, err = gui.GitCommand.GetFilesInRef(refName, isStash, gui.GitCommand.PatchManager)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
@ -40,9 +40,10 @@ func (gui *Gui) currentDiffTerminals() []string {
|
||||
switch gui.currentContextKey() {
|
||||
case "":
|
||||
return nil
|
||||
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
|
||||
// not supporting these for now because I'm not sure how it would actually work
|
||||
return nil
|
||||
case FILES_CONTEXT_KEY:
|
||||
return []string{""}
|
||||
case COMMIT_FILES_CONTEXT_KEY:
|
||||
return []string{gui.State.Panels.CommitFiles.refName}
|
||||
case LOCAL_BRANCHES_CONTEXT_KEY:
|
||||
// for our local branches we want to include both the branch and its upstream
|
||||
branch := gui.getSelectedBranch()
|
||||
@ -75,6 +76,19 @@ func (gui *Gui) currentDiffTerminal() string {
|
||||
return names[0]
|
||||
}
|
||||
|
||||
func (gui *Gui) currentlySelectedFilename() string {
|
||||
switch gui.currentContextKey() {
|
||||
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
|
||||
item := gui.getSideContextSelectedItem()
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
return item.ID()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) diffStr() string {
|
||||
output := gui.State.Modes.Diffing.Ref
|
||||
|
||||
@ -82,9 +96,16 @@ func (gui *Gui) diffStr() string {
|
||||
if right != "" {
|
||||
output += " " + right
|
||||
}
|
||||
|
||||
if gui.State.Modes.Diffing.Reverse {
|
||||
output += " -R"
|
||||
}
|
||||
|
||||
file := gui.currentlySelectedFilename()
|
||||
if file != "" {
|
||||
output += " -- " + file
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user