mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
Combine GetPathDiff and GetAllDiff into one command (GetDiff)
This makes it more reusable for other purposes.
This commit is contained in:
parent
1c5fe8ff17
commit
eaaf123238
@ -16,6 +16,8 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is for generating diffs to be shown in the UI (e.g. rendering a range
|
||||||
|
// diff to the main view). It uses a custom pager if one is configured.
|
||||||
func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
|
func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
|
||||||
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
|
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
|
||||||
useExtDiff := extDiffCmd != ""
|
useExtDiff := extDiffCmd != ""
|
||||||
@ -36,27 +38,21 @@ func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *DiffCommands) internalDiffCmdObj(diffArgs ...string) *GitCommandBuilder {
|
// This is a basic generic diff command that can be used for any diff operation
|
||||||
return NewGitCmd("diff").
|
// (e.g. copying a diff to the clipboard). It will not use a custom pager, and
|
||||||
Config("diff.noprefix=false").
|
// does not use user configs such as ignore whitespace.
|
||||||
Arg("--no-ext-diff", "--no-color").
|
// If you want to diff specific refs (one or two), you need to add them yourself
|
||||||
Arg(diffArgs...).
|
// in additionalArgs; it is recommended to also pass `--` after that. If you
|
||||||
Dir(self.repoPaths.worktreePath)
|
// want to restrict the diff to specific paths, pass them in additionalArgs
|
||||||
}
|
// after the `--`.
|
||||||
|
func (self *DiffCommands) GetDiff(staged bool, additionalArgs ...string) (string, error) {
|
||||||
func (self *DiffCommands) GetPathDiff(path string, staged bool) (string, error) {
|
|
||||||
return self.cmd.New(
|
return self.cmd.New(
|
||||||
self.internalDiffCmdObj().
|
NewGitCmd("diff").
|
||||||
ArgIf(staged, "--staged").
|
Config("diff.noprefix=false").
|
||||||
Arg(path).
|
Arg("--no-ext-diff", "--no-color").
|
||||||
ToArgv(),
|
|
||||||
).RunWithOutput()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *DiffCommands) GetAllDiff(staged bool) (string, error) {
|
|
||||||
return self.cmd.New(
|
|
||||||
self.internalDiffCmdObj().
|
|
||||||
ArgIf(staged, "--staged").
|
ArgIf(staged, "--staged").
|
||||||
|
Dir(self.repoPaths.worktreePath).
|
||||||
|
Arg(additionalArgs...).
|
||||||
ToArgv(),
|
ToArgv(),
|
||||||
).RunWithOutput()
|
).RunWithOutput()
|
||||||
}
|
}
|
||||||
|
@ -869,7 +869,7 @@ func (self *FilesController) openCopyMenu() error {
|
|||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
path := self.context().GetSelectedPath()
|
path := self.context().GetSelectedPath()
|
||||||
hasStaged := self.hasPathStagedChanges(node)
|
hasStaged := self.hasPathStagedChanges(node)
|
||||||
diff, err := self.c.Git().Diff.GetPathDiff(path, hasStaged)
|
diff, err := self.c.Git().Diff.GetDiff(hasStaged, "--", path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -894,7 +894,7 @@ func (self *FilesController) openCopyMenu() error {
|
|||||||
Tooltip: self.c.Tr.CopyFileDiffTooltip,
|
Tooltip: self.c.Tr.CopyFileDiffTooltip,
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
hasStaged := self.c.Helpers().WorkingTree.AnyStagedFiles()
|
hasStaged := self.c.Helpers().WorkingTree.AnyStagedFiles()
|
||||||
diff, err := self.c.Git().Diff.GetAllDiff(hasStaged)
|
diff, err := self.c.Git().Diff.GetDiff(hasStaged, "--")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user