diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-21 19:53:45 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 2d90e1e8ee5ccb3d2acd8678e68137645c9e65bd (patch) | |
tree | cb623a51873bd086967ea794b21210861ce5031e /pkg/commands/git.go | |
parent | ddf25e14afe5ddfc2527149c54ea55ea2e83610a (diff) |
commit files kind of generalised
Diffstat (limited to 'pkg/commands/git.go')
-rw-r--r-- | pkg/commands/git.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index b52c989d7..eac5c0a53 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -1045,9 +1045,14 @@ func (c *GitCommand) CherryPickCommits(commits []*Commit) error { return c.OSCommand.RunPreparedCommand(cmd) } -// GetCommitFiles get the specified commit files -func (c *GitCommand) GetCommitFiles(commitSha string, patchManager *patch.PatchManager) ([]*CommitFile, error) { - files, err := c.OSCommand.RunCommandWithOutput("git diff-tree --no-commit-id --name-only -r --no-renames %s", commitSha) +// GetFilesInRef get the specified commit files +func (c *GitCommand) GetFilesInRef(commitSha string, isStash bool, patchManager *patch.PatchManager) ([]*CommitFile, error) { + command := "git diff-tree" + if isStash { + command = "git stash show" + } + + files, err := c.OSCommand.RunCommandWithOutput("%s --no-commit-id --name-only -r --no-renames %s", command, commitSha) if err != nil { return nil, err } @@ -1083,7 +1088,7 @@ func (c *GitCommand) ShowCommitFileCmdStr(commitSha, fileName string, plain bool colorArg = "never" } - return fmt.Sprintf("git show --no-renames --color=%s %s -- %s", colorArg, commitSha, fileName) + return fmt.Sprintf("git diff --no-renames --color=%s %s^..%s -- %s", colorArg, commitSha, commitSha, fileName) } // CheckoutFile checks out the file for the given commit |