Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPaths []string) *oscom
Arg("-p").
Arg(hash).
ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
ArgIf(self.UserConfig().Git.UseWordDiffInDiffView, "--word-diff").
Arg(fmt.Sprintf("--find-renames=%d%%", self.UserConfig().Git.RenameSimilarityThreshold)).
Arg("--").
Arg(filterPaths...).
Expand Down
25 changes: 25 additions & 0 deletions pkg/commands/git_commands/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,28 @@ func TestAddCoAuthorToDescription(t *testing.T) {
})
}
}

func TestWordDiffConfiguration(t *testing.T) {
userConfig := config.GetDefaultConfig()
userConfig.Git.UseWordDiffInDiffView = true

repoPaths := RepoPaths{
worktreePath: "/path/to/worktree",
}

runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{
"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show",
"--no-ext-diff", "--submodule", "--color=always", "--unified=3",
"--stat", "--decorate", "-p", "abc123", "--word-diff",
"--find-renames=50%", "--",
}, "", nil)

instance := buildCommitCommands(commonDeps{runner: runner, userConfig: userConfig, repoPaths: &repoPaths})

cmdObj := instance.ShowCmdObj("abc123", []string{})
err := cmdObj.Run()

assert.NoError(t, err)
runner.CheckForMissingCalls()
}
2 changes: 2 additions & 0 deletions pkg/commands/git_commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj {
useExtDiff := extDiffCmd != ""
useExtDiffGitConfig := self.UserConfig().Git.Paging.UseExternalDiffGitConfig
ignoreWhitespace := self.UserConfig().Git.IgnoreWhitespaceInDiffView
useWordDiff := self.UserConfig().Git.UseWordDiffInDiffView

return self.cmd.New(
NewGitCmd("diff").
Expand All @@ -32,6 +33,7 @@ func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj {
Arg("--submodule").
Arg(fmt.Sprintf("--color=%s", self.UserConfig().Git.Paging.ColorArg)).
ArgIf(ignoreWhitespace, "--ignore-all-space").
ArgIf(useWordDiff, "--word-diff").
Arg(fmt.Sprintf("--unified=%d", self.UserConfig().Git.DiffContextSize)).
Arg(diffArgs...).
Dir(self.repoPaths.worktreePath).
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/git_commands/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func (self *PatchCommands) diffHeadAgainstCommit(commit *models.Commit) (string,
cmdArgs := NewGitCmd("diff").
Config("diff.noprefix=false").
Arg("--no-ext-diff").
ArgIf(self.UserConfig().Git.UseWordDiffInDiffView, "--word-diff").
Arg("HEAD.." + commit.Hash()).
ToArgv()

Expand Down
1 change: 1 addition & 0 deletions pkg/commands/git_commands/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj {
Arg(fmt.Sprintf("--color=%s", self.UserConfig().Git.Paging.ColorArg)).
Arg(fmt.Sprintf("--unified=%d", self.UserConfig().Git.DiffContextSize)).
ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
ArgIf(self.UserConfig().Git.UseWordDiffInDiffView, "--word-diff").
Arg(fmt.Sprintf("--find-renames=%d%%", self.UserConfig().Git.RenameSimilarityThreshold)).
Arg(fmt.Sprintf("refs/stash@{%d}", index)).
Dir(self.repoPaths.worktreePath).
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/git_commands/working_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
Arg(fmt.Sprintf("--unified=%d", contextSize)).
Arg(fmt.Sprintf("--color=%s", colorArg)).
ArgIf(!plain && self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
ArgIf(!plain && self.UserConfig().Git.UseWordDiffInDiffView, "--word-diff").
Arg(fmt.Sprintf("--find-renames=%d%%", self.UserConfig().Git.RenameSimilarityThreshold)).
ArgIf(cached, "--cached").
ArgIf(noIndex, "--no-index").
Expand Down Expand Up @@ -319,6 +320,7 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve
Arg(to).
ArgIf(reverse, "-R").
ArgIf(!plain && self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
ArgIf(!plain && self.UserConfig().Git.UseWordDiffInDiffView, "--word-diff").
Arg("--").
Arg(fileName).
Dir(self.repoPaths.worktreePath).
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ type GitConfig struct {
AllBranchesLogCmds []string `yaml:"allBranchesLogCmds"`
// If true, git diffs are rendered with the `--ignore-all-space` flag, which ignores whitespace changes. Can be toggled from within Lazygit with `<c-w>`.
IgnoreWhitespaceInDiffView bool `yaml:"ignoreWhitespaceInDiffView"`
// If true, git diffs use word-diff mode. Can be toggled from within Lazygit with `<c-shift-w>`.
UseWordDiffInDiffView bool `yaml:"useWordDiffInDiffView"`
// The number of lines of context to show around each diff hunk. Can be changed from within Lazygit with the `{` and `}` keys.
DiffContextSize uint64 `yaml:"diffContextSize"`
// The threshold for considering a file to be renamed, in percent. Can be changed from within Lazygit with the `(` and `)` keys.
Expand Down Expand Up @@ -828,6 +830,7 @@ func GetDefaultConfig() *UserConfig {
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
AllBranchesLogCmds: []string{"git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"},
IgnoreWhitespaceInDiffView: false,
UseWordDiffInDiffView: false,
DiffContextSize: 3,
RenameSimilarityThreshold: 50,
DisableForcePushing: false,
Expand Down
11 changes: 11 additions & 0 deletions pkg/gui/controllers/diffing_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ func (self *DiffingMenuAction) Call() error {
},
}...)

menuItems = append(menuItems, []*types.MenuItem{
{
Label: self.c.Tr.ToggleWordDiffInDiffView,
OnPress: func() error {
self.c.UserConfig().Git.UseWordDiffInDiffView = !self.c.UserConfig().Git.UseWordDiffInDiffView
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
},
}...)

if self.c.Modes().Diffing.Active() {
menuItems = append(menuItems, []*types.MenuItem{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/controllers/global_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (self *GlobalController) toggleWhitespace() error {
return (&ToggleWhitespaceAction{c: self.c}).Call()
}

func (self *GlobalController) toggleWordDiff() error {
return (&ToggleWordDiffAction{c: self.c}).Call()
}

func (self *GlobalController) canShowRebaseOptions() *types.DisabledReason {
if self.c.Model().WorkingTreeStateAtLastCommitRefresh.None() {
return &types.DisabledReason{
Expand Down
14 changes: 14 additions & 0 deletions pkg/gui/controllers/toggle_word_diff_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controllers

import "github.com/jesseduffield/lazygit/pkg/gui/types"

type ToggleWordDiffAction struct {
c *ControllerCommon
}

func (self *ToggleWordDiffAction) Call() error {
self.c.UserConfig().Git.UseWordDiffInDiffView = !self.c.UserConfig().Git.UseWordDiffInDiffView

self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
return nil
}
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ type TranslationSet struct {
CommandLogHeader string
RandomTip string
ToggleWhitespaceInDiffView string
ToggleWordDiffInDiffView string
ToggleWhitespaceInDiffViewTooltip string
IgnoreWhitespaceDiffViewSubTitle string
IgnoreWhitespaceNotSupportedHere string
Expand Down Expand Up @@ -1819,6 +1820,7 @@ func EnglishTranslationSet() *TranslationSet {
CommandLogHeader: "You can hide/focus this panel by pressing '%s'\n",
RandomTip: "Random tip",
ToggleWhitespaceInDiffView: "Toggle whitespace",
ToggleWordDiffInDiffView: "Toggle word diff",
ToggleWhitespaceInDiffViewTooltip: "Toggle whether or not whitespace changes are shown in the diff view.\n\nThe default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'.",
IgnoreWhitespaceDiffViewSubTitle: "(ignoring whitespace)",
IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view",
Expand Down