mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 12:12:42 +02:00
Support ignoring whitespace on stash
This commit is contained in:
parent
3dd96a8010
commit
d161afe37f
@ -59,8 +59,19 @@ func (self *StashCommands) Sha(index int) (string, error) {
|
|||||||
return strings.Trim(sha, "\r\n"), err
|
return strings.Trim(sha, "\r\n"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
|
func (self *StashCommands) ShowStashEntryCmdObj(index int, ignoreWhitespace bool) oscommands.ICmdObj {
|
||||||
cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", self.UserConfig.Git.Paging.ColorArg, self.UserConfig.Git.DiffContextSize, index)
|
ignoreWhitespaceFlag := ""
|
||||||
|
if ignoreWhitespace {
|
||||||
|
ignoreWhitespaceFlag = " --ignore-all-space"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdStr := fmt.Sprintf(
|
||||||
|
"git stash show -p --stat --color=%s --unified=%d%s stash@{%d}",
|
||||||
|
self.UserConfig.Git.Paging.ColorArg,
|
||||||
|
self.UserConfig.Git.DiffContextSize,
|
||||||
|
ignoreWhitespaceFlag,
|
||||||
|
index,
|
||||||
|
)
|
||||||
|
|
||||||
return self.cmd.New(cmdStr).DontLog()
|
return self.cmd.New(cmdStr).DontLog()
|
||||||
}
|
}
|
||||||
|
@ -99,24 +99,34 @@ func TestStashSha(t *testing.T) {
|
|||||||
|
|
||||||
func TestStashStashEntryCmdObj(t *testing.T) {
|
func TestStashStashEntryCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
index int
|
index int
|
||||||
contextSize int
|
contextSize int
|
||||||
expected string
|
ignoreWhitespace bool
|
||||||
|
expected string
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
testName: "Default case",
|
testName: "Default case",
|
||||||
index: 5,
|
index: 5,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
|
ignoreWhitespace: false,
|
||||||
|
expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Show diff with custom context size",
|
testName: "Show diff with custom context size",
|
||||||
index: 5,
|
index: 5,
|
||||||
contextSize: 77,
|
contextSize: 77,
|
||||||
expected: "git stash show -p --stat --color=always --unified=77 stash@{5}",
|
ignoreWhitespace: false,
|
||||||
|
expected: "git stash show -p --stat --color=always --unified=77 stash@{5}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Default case",
|
||||||
|
index: 5,
|
||||||
|
contextSize: 3,
|
||||||
|
ignoreWhitespace: true,
|
||||||
|
expected: "git stash show -p --stat --color=always --unified=3 --ignore-all-space stash@{5}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +137,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
userConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
instance := buildStashCommands(commonDeps{userConfig: userConfig})
|
instance := buildStashCommands(commonDeps{userConfig: userConfig})
|
||||||
|
|
||||||
cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString()
|
cmdStr := instance.ShowStashEntryCmdObj(s.index, s.ignoreWhitespace).ToString()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,12 @@ func (self *StashController) GetOnRenderToMain() func() error {
|
|||||||
if stashEntry == nil {
|
if stashEntry == nil {
|
||||||
task = types.NewRenderStringTask(self.c.Tr.NoStashEntries)
|
task = types.NewRenderStringTask(self.c.Tr.NoStashEntries)
|
||||||
} else {
|
} else {
|
||||||
task = types.NewRunPtyTask(self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index).GetCmd())
|
task = types.NewRunPtyTask(
|
||||||
|
self.c.Git().Stash.ShowStashEntryCmdObj(
|
||||||
|
stashEntry.Index,
|
||||||
|
self.c.State().GetIgnoreWhitespaceInDiffView(),
|
||||||
|
).GetCmd(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user