mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
fix test
This commit is contained in:
@ -233,7 +233,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
|
|||||||
ignoreWhitespaceArg := ""
|
ignoreWhitespaceArg := ""
|
||||||
contextSize := self.UserConfig.Git.DiffContextSize
|
contextSize := self.UserConfig.Git.DiffContextSize
|
||||||
if cached {
|
if cached {
|
||||||
cachedArg = "--cached"
|
cachedArg = " --cached"
|
||||||
}
|
}
|
||||||
if !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached {
|
if !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached {
|
||||||
trackedArg = "--no-index -- /dev/null"
|
trackedArg = "--no-index -- /dev/null"
|
||||||
@ -242,10 +242,10 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
|
|||||||
colorArg = "never"
|
colorArg = "never"
|
||||||
}
|
}
|
||||||
if ignoreWhitespace {
|
if ignoreWhitespace {
|
||||||
ignoreWhitespaceArg = "--ignore-all-space"
|
ignoreWhitespaceArg = " --ignore-all-space"
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdStr := fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --color=%s %s %s %s %s", contextSize, colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, quotedPath)
|
cmdStr := fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --color=%s%s%s %s %s", contextSize, colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, quotedPath)
|
||||||
|
|
||||||
return self.cmd.New(cmdStr).DontLog()
|
return self.cmd.New(cmdStr).DontLog()
|
||||||
}
|
}
|
||||||
@ -280,14 +280,14 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve
|
|||||||
|
|
||||||
reverseFlag := ""
|
reverseFlag := ""
|
||||||
if reverse {
|
if reverse {
|
||||||
reverseFlag = " -R "
|
reverseFlag = " -R"
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.cmd.
|
return self.cmd.
|
||||||
New(
|
New(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"git diff --submodule --no-ext-diff --unified=%d --no-renames --color=%s %s %s %s -- %s",
|
"git diff --submodule --no-ext-diff --unified=%d --no-renames --color=%s%s%s%s -- %s",
|
||||||
contextSize, colorArg, from, to, reverseFlag, self.cmd.Quote(fileName)),
|
contextSize, colorArg, pad(from), pad(to), reverseFlag, self.cmd.Quote(fileName)),
|
||||||
).
|
).
|
||||||
DontLog()
|
DontLog()
|
||||||
}
|
}
|
||||||
@ -345,3 +345,12 @@ func (self *WorkingTreeCommands) ResetSoft(ref string) error {
|
|||||||
func (self *WorkingTreeCommands) ResetMixed(ref string) error {
|
func (self *WorkingTreeCommands) ResetMixed(ref string) error {
|
||||||
return self.cmd.New("git reset --mixed " + self.cmd.Quote(ref)).Run()
|
return self.cmd.New("git reset --mixed " + self.cmd.Quote(ref)).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// so that we don't have unnecessary space in our commands we use this helper function to prepend spaces to args so that in the format string we can go '%s%s%s' and if any args are missing we won't have gaps.
|
||||||
|
func pad(str string) string {
|
||||||
|
if str == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return " " + str
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
func TestWorkingTreeStageFile(t *testing.T) {
|
func TestWorkingTreeStageFile(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "add", "--", "test.txt"}, "", nil)
|
Expect(`git add -- "test.txt"`, "", nil)
|
||||||
|
|
||||||
instance := buildWorkingTreeCommands(commonDeps{runner: runner})
|
instance := buildWorkingTreeCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func TestWorkingTreeUnstageFile(t *testing.T) {
|
|||||||
testName: "Remove an untracked file from staging",
|
testName: "Remove an untracked file from staging",
|
||||||
reset: false,
|
reset: false,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "rm", "--cached", "--force", "--", "test.txt"}, "", nil),
|
Expect(`git rm --cached --force -- "test.txt"`, "", nil),
|
||||||
test: func(err error) {
|
test: func(err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
},
|
},
|
||||||
@ -45,7 +45,7 @@ func TestWorkingTreeUnstageFile(t *testing.T) {
|
|||||||
testName: "Remove a tracked file from staging",
|
testName: "Remove a tracked file from staging",
|
||||||
reset: true,
|
reset: true,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "reset", "HEAD", "--", "test.txt"}, "", nil),
|
Expect(`git reset HEAD -- "test.txt"`, "", nil),
|
||||||
test: func(err error) {
|
test: func(err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
},
|
},
|
||||||
@ -82,7 +82,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "reset", "--", "test"}, "", errors.New("error")),
|
Expect(`git reset -- "test"`, "", errors.New("error")),
|
||||||
expectedError: "error",
|
expectedError: "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -107,7 +107,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "checkout", "--", "test"}, "", errors.New("error")),
|
Expect(`git checkout -- "test"`, "", errors.New("error")),
|
||||||
expectedError: "error",
|
expectedError: "error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -119,7 +119,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "checkout", "--", "test"}, "", nil),
|
Expect(`git checkout -- "test"`, "", nil),
|
||||||
expectedError: "",
|
expectedError: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -131,8 +131,8 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "reset", "--", "test"}, "", nil).
|
Expect(`git reset -- "test"`, "", nil).
|
||||||
ExpectArgs([]string{"git", "checkout", "--", "test"}, "", nil),
|
Expect(`git checkout -- "test"`, "", nil),
|
||||||
expectedError: "",
|
expectedError: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -144,8 +144,8 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "reset", "--", "test"}, "", nil).
|
Expect(`git reset -- "test"`, "", nil).
|
||||||
ExpectArgs([]string{"git", "checkout", "--", "test"}, "", nil),
|
Expect(`git checkout -- "test"`, "", nil),
|
||||||
expectedError: "",
|
expectedError: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -161,7 +161,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "reset", "--", "test"}, "", nil),
|
Expect(`git reset -- "test"`, "", nil),
|
||||||
expectedError: "",
|
expectedError: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -223,7 +223,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --color=always -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "cached",
|
testName: "cached",
|
||||||
@ -237,7 +237,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--cached", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --color=always --cached -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "plain",
|
testName: "plain",
|
||||||
@ -251,7 +251,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=never", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --color=never -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "File not tracked and file has no staged changes",
|
testName: "File not tracked and file has no staged changes",
|
||||||
@ -265,7 +265,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--no-index", "--", "/dev/null", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --color=always --no-index -- /dev/null "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Default case (ignore whitespace)",
|
testName: "Default case (ignore whitespace)",
|
||||||
@ -279,7 +279,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: true,
|
ignoreWhitespace: true,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--ignore-all-space", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --color=always --ignore-all-space -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Show diff with custom context size",
|
testName: "Show diff with custom context size",
|
||||||
@ -293,7 +293,7 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
contextSize: 17,
|
contextSize: 17,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=17", "--color=always", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=17 --color=always -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
|
|||||||
plain: false,
|
plain: false,
|
||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=3", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=3 --no-renames --color=always 1234567890 0987654321 -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Show diff with custom context size",
|
testName: "Show diff with custom context size",
|
||||||
@ -343,7 +343,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
|
|||||||
plain: false,
|
plain: false,
|
||||||
contextSize: 123,
|
contextSize: 123,
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "diff", "--submodule", "--no-ext-diff", "--unified=123", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, expectedResult, nil),
|
Expect(`git diff --submodule --no-ext-diff --unified=123 --no-renames --color=always 1234567890 0987654321 -- "test.txt"`, expectedResult, nil),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,8 +416,9 @@ func TestWorkingTreeApplyPatch(t *testing.T) {
|
|||||||
expectFn := func(regexStr string, errToReturn error) func(cmdObj oscommands.ICmdObj) (string, error) {
|
expectFn := func(regexStr string, errToReturn error) func(cmdObj oscommands.ICmdObj) (string, error) {
|
||||||
return func(cmdObj oscommands.ICmdObj) (string, error) {
|
return func(cmdObj oscommands.ICmdObj) (string, error) {
|
||||||
re := regexp.MustCompile(regexStr)
|
re := regexp.MustCompile(regexStr)
|
||||||
matches := re.FindStringSubmatch(cmdObj.ToString())
|
cmdStr := cmdObj.ToString()
|
||||||
assert.Equal(t, 2, len(matches))
|
matches := re.FindStringSubmatch(cmdStr)
|
||||||
|
assert.Equal(t, 2, len(matches), fmt.Sprintf("unexpected command: %s", cmdStr))
|
||||||
|
|
||||||
filename := matches[1]
|
filename := matches[1]
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func TestGetBool(t *testing.T) {
|
|||||||
fake := NewFakeGitConfig(s.mockResponses)
|
fake := NewFakeGitConfig(s.mockResponses)
|
||||||
real := NewCachedGitConfig(
|
real := NewCachedGitConfig(
|
||||||
func(cmd *exec.Cmd) (string, error) {
|
func(cmd *exec.Cmd) (string, error) {
|
||||||
assert.Equal(t, "git config --get --null commit.gpgsign", strings.Join(cmd.Args, " "))
|
assert.Equal(t, "config --get --null commit.gpgsign", strings.Join(cmd.Args[1:], " "))
|
||||||
return fake.Get("commit.gpgsign"), nil
|
return fake.Get("commit.gpgsign"), nil
|
||||||
},
|
},
|
||||||
utils.NewDummyLog(),
|
utils.NewDummyLog(),
|
||||||
@ -92,7 +92,7 @@ func TestGet(t *testing.T) {
|
|||||||
fake := NewFakeGitConfig(s.mockResponses)
|
fake := NewFakeGitConfig(s.mockResponses)
|
||||||
real := NewCachedGitConfig(
|
real := NewCachedGitConfig(
|
||||||
func(cmd *exec.Cmd) (string, error) {
|
func(cmd *exec.Cmd) (string, error) {
|
||||||
assert.Equal(t, "git config --get --null commit.gpgsign", strings.Join(cmd.Args, " "))
|
assert.Equal(t, "config --get --null commit.gpgsign", strings.Join(cmd.Args[1:], " "))
|
||||||
return fake.Get("commit.gpgsign"), nil
|
return fake.Get("commit.gpgsign"), nil
|
||||||
},
|
},
|
||||||
utils.NewDummyLog(),
|
utils.NewDummyLog(),
|
||||||
@ -107,7 +107,7 @@ func TestGet(t *testing.T) {
|
|||||||
real := NewCachedGitConfig(
|
real := NewCachedGitConfig(
|
||||||
func(cmd *exec.Cmd) (string, error) {
|
func(cmd *exec.Cmd) (string, error) {
|
||||||
count++
|
count++
|
||||||
assert.Equal(t, "git config --get --null commit.gpgsign", strings.Join(cmd.Args, " "))
|
assert.Equal(t, "config --get --null commit.gpgsign", strings.Join(cmd.Args[1:], " "))
|
||||||
return "blah", nil
|
return "blah", nil
|
||||||
},
|
},
|
||||||
utils.NewDummyLog(),
|
utils.NewDummyLog(),
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
@ -19,7 +18,6 @@ type FileLoader struct {
|
|||||||
*common.Common
|
*common.Common
|
||||||
cmd oscommands.ICmdObjBuilder
|
cmd oscommands.ICmdObjBuilder
|
||||||
config FileLoaderConfig
|
config FileLoaderConfig
|
||||||
gitConfig git_config.IGitConfig
|
|
||||||
getFileType func(string) string
|
getFileType func(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package loaders
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
@ -189,12 +188,11 @@ func TestFileGetStatusFiles(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
cmd := oscommands.NewDummyCmdObjBuilder(s.runner)
|
cmd := oscommands.NewDummyCmdObjBuilder(s.runner)
|
||||||
gitConfig := git_config.NewFakeGitConfig(map[string]string{"status.showUntrackedFiles": "yes"})
|
|
||||||
|
|
||||||
loader := &FileLoader{
|
loader := &FileLoader{
|
||||||
Common: utils.NewDummyCommon(),
|
Common: utils.NewDummyCommon(),
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
gitConfig: gitConfig,
|
config: &FakeFileLoaderConfig{showUntrackedFiles: "yes"},
|
||||||
getFileType: func(string) string { return "file" },
|
getFileType: func(string) string { return "file" },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,3 +200,11 @@ func TestFileGetStatusFiles(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FakeFileLoaderConfig struct {
|
||||||
|
showUntrackedFiles string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *FakeFileLoaderConfig) GetShowUntrackedFiles() string {
|
||||||
|
return self.showUntrackedFiles
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user