summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 13:03:20 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commite290710f6741c046ee7e52e622af813e8955639b (patch)
tree65a0ea8e98d43c5119ac0ec902572e452fae7ee5 /pkg/commands
parent438abd6003aff9621f93b8531aa20baad2c8933c (diff)
support drilling down into the files of a diff
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index ddb19f98a..57121955d 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -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