1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

cleanup now that we're always using the same diff command

This commit is contained in:
Jesse Duffield
2020-08-22 18:50:37 +10:00
parent 43d891b8d6
commit 148f601bcb
8 changed files with 20 additions and 98 deletions

View File

@ -1045,29 +1045,19 @@ func (c *GitCommand) CherryPickCommits(commits []*Commit) error {
return c.OSCommand.RunPreparedCommand(cmd)
}
// GetFilesInRef get the specified commit files
func (c *GitCommand) GetFilesInRef(refName string, isStash bool, patchManager *patch.PatchManager) ([]*CommitFile, error) {
command := "git diff-tree"
if isStash {
command = "git stash show"
}
filenames, err := c.OSCommand.RunCommandWithOutput("%s --no-commit-id --name-only -r --no-renames %s", command, refName)
if err != nil {
return nil, err
}
return c.GetCommitFilesFromFilenames(filenames, refName, patchManager), nil
}
// GetFilesInDiff get the specified commit files
func (c *GitCommand) GetFilesInDiff(from string, to string, parent string, patchManager *patch.PatchManager) ([]*CommitFile, error) {
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --name-only %s %s", from, to)
func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchManager *patch.PatchManager) ([]*CommitFile, error) {
reverseFlag := ""
if reverse {
reverseFlag = " -R "
}
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --name-only %s %s %s", reverseFlag, from, to)
if err != nil {
return nil, err
}
return c.GetCommitFilesFromFilenames(filenames, parent, patchManager), nil
return c.GetCommitFilesFromFilenames(filenames, to, patchManager), nil
}
// filenames string is something like "file1\nfile2\nfile3"

View File

@ -1852,45 +1852,6 @@ func TestGitCommandShowCommitFile(t *testing.T) {
}
}
// TestGitCommandGetFilesInRef is a function.
func TestGitCommandGetFilesInRef(t *testing.T) {
type scenario struct {
testName string
commitSha string
command func(string, ...string) *exec.Cmd
test func([]*CommitFile, error)
}
scenarios := []scenario{
{
"valid case",
"123456",
test.CreateMockCommand(t, []*test.CommandSwapper{
{
Expect: "git diff-tree --no-commit-id --name-only -r --no-renames 123456",
Replace: "echo 'hello\nworld'",
},
}),
func(commitFiles []*CommitFile, err error) {
assert.NoError(t, err)
assert.Equal(t, []*CommitFile{
{Parent: "123456", Name: "hello", DisplayString: "hello"},
{Parent: "123456", Name: "world", DisplayString: "world"},
}, commitFiles)
},
},
}
gitCmd := NewDummyGitCommand()
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
gitCmd.OSCommand.command = s.command
s.test(gitCmd.GetFilesInRef(s.commitSha, false, nil))
})
}
}
// TestGitCommandDiscardUnstagedFileChanges is a function.
func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
type scenario struct {