@@ -16,6 +16,8 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands {
1616 }
1717}
1818
19+ // This is for generating diffs to be shown in the UI (e.g. rendering a range
20+ // diff to the main view). It uses a custom pager if one is configured.
1921func (self * DiffCommands ) DiffCmdObj (diffArgs []string ) oscommands.ICmdObj {
2022 extDiffCmd := self .UserConfig ().Git .Paging .ExternalDiffCommand
2123 useExtDiff := extDiffCmd != ""
@@ -36,27 +38,21 @@ func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
3638 )
3739}
3840
39- func (self * DiffCommands ) internalDiffCmdObj (diffArgs ... string ) * GitCommandBuilder {
40- return NewGitCmd ("diff" ).
41- Config ("diff.noprefix=false" ).
42- Arg ("--no-ext-diff" , "--no-color" ).
43- Arg (diffArgs ... ).
44- Dir (self .repoPaths .worktreePath )
45- }
46-
47- func (self * DiffCommands ) GetPathDiff (path string , staged bool ) (string , error ) {
41+ // This is a basic generic diff command that can be used for any diff operation
42+ // (e.g. copying a diff to the clipboard). It will not use a custom pager, and
43+ // does not use user configs such as ignore whitespace.
44+ // If you want to diff specific refs (one or two), you need to add them yourself
45+ // in additionalArgs; it is recommended to also pass `--` after that. If you
46+ // want to restrict the diff to specific paths, pass them in additionalArgs
47+ // after the `--`.
48+ func (self * DiffCommands ) GetDiff (staged bool , additionalArgs ... string ) (string , error ) {
4849 return self .cmd .New (
49- self .internalDiffCmdObj ().
50- ArgIf (staged , "--staged" ).
51- Arg (path ).
52- ToArgv (),
53- ).RunWithOutput ()
54- }
55-
56- func (self * DiffCommands ) GetAllDiff (staged bool ) (string , error ) {
57- return self .cmd .New (
58- self .internalDiffCmdObj ().
50+ NewGitCmd ("diff" ).
51+ Config ("diff.noprefix=false" ).
52+ Arg ("--no-ext-diff" , "--no-color" ).
5953 ArgIf (staged , "--staged" ).
54+ Dir (self .repoPaths .worktreePath ).
55+ Arg (additionalArgs ... ).
6056 ToArgv (),
6157 ).RunWithOutput ()
6258}
0 commit comments