mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +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"
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
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
|
status := patch.UNSELECTED
|
||||||
if patchManager != nil && patchManager.Parent == parent {
|
if patchManager != nil && patchManager.Parent == parent {
|
||||||
status = patchManager.GetFileStatus(file)
|
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
|
// 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
|
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 {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,10 @@ func (gui *Gui) currentDiffTerminals() []string {
|
|||||||
switch gui.currentContextKey() {
|
switch gui.currentContextKey() {
|
||||||
case "":
|
case "":
|
||||||
return nil
|
return nil
|
||||||
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
|
case FILES_CONTEXT_KEY:
|
||||||
// not supporting these for now because I'm not sure how it would actually work
|
return []string{""}
|
||||||
return nil
|
case COMMIT_FILES_CONTEXT_KEY:
|
||||||
|
return []string{gui.State.Panels.CommitFiles.refName}
|
||||||
case LOCAL_BRANCHES_CONTEXT_KEY:
|
case LOCAL_BRANCHES_CONTEXT_KEY:
|
||||||
// for our local branches we want to include both the branch and its upstream
|
// for our local branches we want to include both the branch and its upstream
|
||||||
branch := gui.getSelectedBranch()
|
branch := gui.getSelectedBranch()
|
||||||
@ -75,6 +76,19 @@ func (gui *Gui) currentDiffTerminal() string {
|
|||||||
return names[0]
|
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 {
|
func (gui *Gui) diffStr() string {
|
||||||
output := gui.State.Modes.Diffing.Ref
|
output := gui.State.Modes.Diffing.Ref
|
||||||
|
|
||||||
@ -82,9 +96,16 @@ func (gui *Gui) diffStr() string {
|
|||||||
if right != "" {
|
if right != "" {
|
||||||
output += " " + right
|
output += " " + right
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.State.Modes.Diffing.Reverse {
|
if gui.State.Modes.Diffing.Reverse {
|
||||||
output += " -R"
|
output += " -R"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file := gui.currentlySelectedFilename()
|
||||||
|
if file != "" {
|
||||||
|
output += " -- " + file
|
||||||
|
}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user