mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
refactor
This commit is contained in:
parent
3621854dc7
commit
c9a0cc6b30
@ -1,28 +0,0 @@
|
|||||||
package commands
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewDummyGitCommand creates a new dummy GitCommand for testing
|
|
||||||
func NewDummyGitCommand() *GitCommand {
|
|
||||||
return NewDummyGitCommandWithOSCommand(oscommands.NewDummyOSCommand())
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
|
|
||||||
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
|
|
||||||
return NewGitCommandAux(
|
|
||||||
utils.NewDummyCommon(),
|
|
||||||
osCommand,
|
|
||||||
utils.NewDummyGitConfig(),
|
|
||||||
".git",
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDummyGitCommandWithRunner(runner *oscommands.FakeCmdObjRunner) *GitCommand {
|
|
||||||
osCommand := oscommands.NewDummyOSCommandWithRunner(runner)
|
|
||||||
|
|
||||||
return NewDummyGitCommandWithOSCommand(osCommand)
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
@ -20,21 +21,21 @@ import (
|
|||||||
|
|
||||||
// GitCommand is our main git interface
|
// GitCommand is our main git interface
|
||||||
type GitCommand struct {
|
type GitCommand struct {
|
||||||
Branch *BranchCommands
|
Branch *git_commands.BranchCommands
|
||||||
Commit *CommitCommands
|
Commit *git_commands.CommitCommands
|
||||||
Config *ConfigCommands
|
Config *git_commands.ConfigCommands
|
||||||
Custom *CustomCommands
|
Custom *git_commands.CustomCommands
|
||||||
File *FileCommands
|
File *git_commands.FileCommands
|
||||||
Flow *FlowCommands
|
Flow *git_commands.FlowCommands
|
||||||
Patch *PatchCommands
|
Patch *git_commands.PatchCommands
|
||||||
Rebase *RebaseCommands
|
Rebase *git_commands.RebaseCommands
|
||||||
Remote *RemoteCommands
|
Remote *git_commands.RemoteCommands
|
||||||
Stash *StashCommands
|
Stash *git_commands.StashCommands
|
||||||
Status *StatusCommands
|
Status *git_commands.StatusCommands
|
||||||
Submodule *SubmoduleCommands
|
Submodule *git_commands.SubmoduleCommands
|
||||||
Sync *SyncCommands
|
Sync *git_commands.SyncCommands
|
||||||
Tag *TagCommands
|
Tag *git_commands.TagCommands
|
||||||
WorkingTree *WorkingTreeCommands
|
WorkingTree *git_commands.WorkingTreeCommands
|
||||||
|
|
||||||
Loaders Loaders
|
Loaders Loaders
|
||||||
}
|
}
|
||||||
@ -91,20 +92,20 @@ func NewGitCommandAux(
|
|||||||
// This is admittedly messy, but allows us to test each command struct in isolation,
|
// This is admittedly messy, but allows us to test each command struct in isolation,
|
||||||
// and allows for better namespacing when compared to having every method living
|
// and allows for better namespacing when compared to having every method living
|
||||||
// on the one struct.
|
// on the one struct.
|
||||||
configCommands := NewConfigCommands(cmn, gitConfig)
|
configCommands := git_commands.NewConfigCommands(cmn, gitConfig)
|
||||||
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
statusCommands := git_commands.NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||||
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
||||||
flowCommands := NewFlowCommands(cmn, cmd, configCommands)
|
flowCommands := git_commands.NewFlowCommands(cmn, cmd, configCommands)
|
||||||
remoteCommands := NewRemoteCommands(cmn, cmd)
|
remoteCommands := git_commands.NewRemoteCommands(cmn, cmd)
|
||||||
branchCommands := NewBranchCommands(cmn, cmd)
|
branchCommands := git_commands.NewBranchCommands(cmn, cmd)
|
||||||
syncCommands := NewSyncCommands(cmn, cmd)
|
syncCommands := git_commands.NewSyncCommands(cmn, cmd)
|
||||||
tagCommands := NewTagCommands(cmn, cmd)
|
tagCommands := git_commands.NewTagCommands(cmn, cmd)
|
||||||
commitCommands := NewCommitCommands(cmn, cmd)
|
commitCommands := git_commands.NewCommitCommands(cmn, cmd)
|
||||||
customCommands := NewCustomCommands(cmn, cmd)
|
customCommands := git_commands.NewCustomCommands(cmn, cmd)
|
||||||
fileCommands := NewFileCommands(cmn, cmd, configCommands, osCommand)
|
fileCommands := git_commands.NewFileCommands(cmn, cmd, configCommands, osCommand)
|
||||||
submoduleCommands := NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
submoduleCommands := git_commands.NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
||||||
workingTreeCommands := NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
workingTreeCommands := git_commands.NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
||||||
rebaseCommands := NewRebaseCommands(
|
rebaseCommands := git_commands.NewRebaseCommands(
|
||||||
cmn,
|
cmn,
|
||||||
cmd,
|
cmd,
|
||||||
osCommand,
|
osCommand,
|
||||||
@ -113,10 +114,10 @@ func NewGitCommandAux(
|
|||||||
configCommands,
|
configCommands,
|
||||||
dotGitDir,
|
dotGitDir,
|
||||||
)
|
)
|
||||||
stashCommands := NewStashCommands(cmn, cmd, osCommand, fileLoader, workingTreeCommands)
|
stashCommands := git_commands.NewStashCommands(cmn, cmd, osCommand, fileLoader, workingTreeCommands)
|
||||||
// TODO: have patch manager take workingTreeCommands in its entirety
|
// TODO: have patch manager take workingTreeCommands in its entirety
|
||||||
patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch, workingTreeCommands.ShowFileDiff)
|
patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch, workingTreeCommands.ShowFileDiff)
|
||||||
patchCommands := NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
|
patchCommands := git_commands.NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
|
||||||
|
|
||||||
return &GitCommand{
|
return &GitCommand{
|
||||||
Branch: branchCommands,
|
Branch: branchCommands,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -45,23 +45,23 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
|
|||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
|
func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
|
||||||
editor := c.UserConfig.OS.EditCommand
|
editor := self.UserConfig.OS.EditCommand
|
||||||
|
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.config.GetCoreEditor()
|
editor = self.config.GetCoreEditor()
|
||||||
}
|
}
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.os.Getenv("GIT_EDITOR")
|
editor = self.os.Getenv("GIT_EDITOR")
|
||||||
}
|
}
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.os.Getenv("VISUAL")
|
editor = self.os.Getenv("VISUAL")
|
||||||
}
|
}
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.os.Getenv("EDITOR")
|
editor = self.os.Getenv("EDITOR")
|
||||||
}
|
}
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
if err := c.cmd.New("which vi").DontLog().Run(); err == nil {
|
if err := self.cmd.New("which vi").DontLog().Run(); err == nil {
|
||||||
editor = "vi"
|
editor = "vi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,10 +71,10 @@ func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, e
|
|||||||
|
|
||||||
templateValues := map[string]string{
|
templateValues := map[string]string{
|
||||||
"editor": editor,
|
"editor": editor,
|
||||||
"filename": c.cmd.Quote(filename),
|
"filename": self.cmd.Quote(filename),
|
||||||
"line": strconv.Itoa(lineNumber),
|
"line": strconv.Itoa(lineNumber),
|
||||||
}
|
}
|
||||||
|
|
||||||
editCmdTemplate := c.UserConfig.OS.EditCommandTemplate
|
editCmdTemplate := self.UserConfig.OS.EditCommandTemplate
|
||||||
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -87,7 +87,7 @@ func (self *WorkingTreeCommands) UnStageFile(fileNames []string, reset bool) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*models.File, *models.File, error) {
|
func (self *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*models.File, *models.File, error) {
|
||||||
if !file.IsRename() {
|
if !file.IsRename() {
|
||||||
return nil, nil, errors.New("Expected renamed file")
|
return nil, nil, errors.New("Expected renamed file")
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func (c *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*m
|
|||||||
// all files, passing the --no-renames flag and then recursively call the function
|
// all files, passing the --no-renames flag and then recursively call the function
|
||||||
// again for the before file and after file.
|
// again for the before file and after file.
|
||||||
|
|
||||||
filesWithoutRenames := c.fileLoader.GetStatusFiles(loaders.GetStatusFileOptions{NoRenames: true})
|
filesWithoutRenames := self.fileLoader.GetStatusFiles(loaders.GetStatusFileOptions{NoRenames: true})
|
||||||
|
|
||||||
var beforeFile *models.File
|
var beforeFile *models.File
|
||||||
var afterFile *models.File
|
var afterFile *models.File
|
||||||
@ -123,43 +123,43 @@ func (c *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*m
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DiscardAllFileChanges directly
|
// DiscardAllFileChanges directly
|
||||||
func (c *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
||||||
if file.IsRename() {
|
if file.IsRename() {
|
||||||
beforeFile, afterFile, err := c.BeforeAndAfterFileForRename(file)
|
beforeFile, afterFile, err := self.BeforeAndAfterFileForRename(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.DiscardAllFileChanges(beforeFile); err != nil {
|
if err := self.DiscardAllFileChanges(beforeFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.DiscardAllFileChanges(afterFile); err != nil {
|
if err := self.DiscardAllFileChanges(afterFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
quotedFileName := c.cmd.Quote(file.Name)
|
quotedFileName := self.cmd.Quote(file.Name)
|
||||||
|
|
||||||
if file.ShortStatus == "AA" {
|
if file.ShortStatus == "AA" {
|
||||||
if err := c.cmd.New("git checkout --ours -- " + quotedFileName).Run(); err != nil {
|
if err := self.cmd.New("git checkout --ours -- " + quotedFileName).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.cmd.New("git add -- " + quotedFileName).Run(); err != nil {
|
if err := self.cmd.New("git add -- " + quotedFileName).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if file.ShortStatus == "DU" {
|
if file.ShortStatus == "DU" {
|
||||||
return c.cmd.New("git rm -- " + quotedFileName).Run()
|
return self.cmd.New("git rm -- " + quotedFileName).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the file isn't tracked, we assume you want to delete it
|
// if the file isn't tracked, we assume you want to delete it
|
||||||
if file.HasStagedChanges || file.HasMergeConflicts {
|
if file.HasStagedChanges || file.HasMergeConflicts {
|
||||||
if err := c.cmd.New("git reset -- " + quotedFileName).Run(); err != nil {
|
if err := self.cmd.New("git reset -- " + quotedFileName).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,30 +169,30 @@ func (c *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if file.Added {
|
if file.Added {
|
||||||
return c.os.RemoveFile(file.Name)
|
return self.os.RemoveFile(file.Name)
|
||||||
}
|
}
|
||||||
return c.DiscardUnstagedFileChanges(file)
|
return self.DiscardUnstagedFileChanges(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) DiscardAllDirChanges(node *filetree.FileNode) error {
|
func (self *WorkingTreeCommands) DiscardAllDirChanges(node *filetree.FileNode) error {
|
||||||
// this could be more efficient but we would need to handle all the edge cases
|
// this could be more efficient but we would need to handle all the edge cases
|
||||||
return node.ForEachFile(c.DiscardAllFileChanges)
|
return node.ForEachFile(self.DiscardAllFileChanges)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) DiscardUnstagedDirChanges(node *filetree.FileNode) error {
|
func (self *WorkingTreeCommands) DiscardUnstagedDirChanges(node *filetree.FileNode) error {
|
||||||
if err := c.RemoveUntrackedDirFiles(node); err != nil {
|
if err := self.RemoveUntrackedDirFiles(node); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
quotedPath := c.cmd.Quote(node.GetPath())
|
quotedPath := self.cmd.Quote(node.GetPath())
|
||||||
if err := c.cmd.New("git checkout -- " + quotedPath).Run(); err != nil {
|
if err := self.cmd.New("git checkout -- " + quotedPath).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) RemoveUntrackedDirFiles(node *filetree.FileNode) error {
|
func (self *WorkingTreeCommands) RemoveUntrackedDirFiles(node *filetree.FileNode) error {
|
||||||
untrackedFilePaths := node.GetPathsMatching(
|
untrackedFilePaths := node.GetPathsMatching(
|
||||||
func(n *filetree.FileNode) bool { return n.File != nil && !n.File.GetIsTracked() },
|
func(n *filetree.FileNode) bool { return n.File != nil && !n.File.GetIsTracked() },
|
||||||
)
|
)
|
||||||
@ -208,30 +208,30 @@ func (c *WorkingTreeCommands) RemoveUntrackedDirFiles(node *filetree.FileNode) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DiscardUnstagedFileChanges directly
|
// DiscardUnstagedFileChanges directly
|
||||||
func (c *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
||||||
quotedFileName := c.cmd.Quote(file.Name)
|
quotedFileName := self.cmd.Quote(file.Name)
|
||||||
return c.cmd.New("git checkout -- " + quotedFileName).Run()
|
return self.cmd.New("git checkout -- " + quotedFileName).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore adds a file to the gitignore for the repo
|
// Ignore adds a file to the gitignore for the repo
|
||||||
func (c *WorkingTreeCommands) Ignore(filename string) error {
|
func (self *WorkingTreeCommands) Ignore(filename string) error {
|
||||||
return c.os.AppendLineToFile(".gitignore", filename)
|
return self.os.AppendLineToFile(".gitignore", filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorktreeFileDiff returns the diff of a file
|
// WorktreeFileDiff returns the diff of a file
|
||||||
func (c *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool, ignoreWhitespace bool) string {
|
func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool, ignoreWhitespace bool) string {
|
||||||
// for now we assume an error means the file was deleted
|
// for now we assume an error means the file was deleted
|
||||||
s, _ := c.WorktreeFileDiffCmdObj(file, plain, cached, ignoreWhitespace).RunWithOutput()
|
s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached, ignoreWhitespace).RunWithOutput()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool, ignoreWhitespace bool) oscommands.ICmdObj {
|
func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool, ignoreWhitespace bool) oscommands.ICmdObj {
|
||||||
cachedArg := ""
|
cachedArg := ""
|
||||||
trackedArg := "--"
|
trackedArg := "--"
|
||||||
colorArg := c.UserConfig.Git.Paging.ColorArg
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||||
quotedPath := c.cmd.Quote(node.GetPath())
|
quotedPath := self.cmd.Quote(node.GetPath())
|
||||||
ignoreWhitespaceArg := ""
|
ignoreWhitespaceArg := ""
|
||||||
contextSize := c.UserConfig.Git.DiffContextSize
|
contextSize := self.UserConfig.Git.DiffContextSize
|
||||||
if cached {
|
if cached {
|
||||||
cachedArg = "--cached"
|
cachedArg = "--cached"
|
||||||
}
|
}
|
||||||
@ -247,13 +247,13 @@ func (c *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bo
|
|||||||
|
|
||||||
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 c.cmd.New(cmdStr).DontLog()
|
return self.cmd.New(cmdStr).DontLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error {
|
func (self *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error {
|
||||||
filepath := filepath.Join(oscommands.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch")
|
filepath := filepath.Join(oscommands.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch")
|
||||||
c.Log.Infof("saving temporary patch to %s", filepath)
|
self.Log.Infof("saving temporary patch to %s", filepath)
|
||||||
if err := c.os.CreateFileWithContent(filepath, patch); err != nil {
|
if err := self.os.CreateFileWithContent(filepath, patch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,18 +262,18 @@ func (c *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error {
|
|||||||
flagStr += " --" + flag
|
flagStr += " --" + flag
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.cmd.New(fmt.Sprintf("git apply%s %s", flagStr, c.cmd.Quote(filepath))).Run()
|
return self.cmd.New(fmt.Sprintf("git apply%s %s", flagStr, self.cmd.Quote(filepath))).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc
|
// ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc
|
||||||
// but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode.
|
// but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode.
|
||||||
func (c *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) {
|
func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) {
|
||||||
return c.ShowFileDiffCmdObj(from, to, reverse, fileName, plain).RunWithOutput()
|
return self.ShowFileDiffCmdObj(from, to, reverse, fileName, plain).RunWithOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
||||||
colorArg := c.UserConfig.Git.Paging.ColorArg
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||||
contextSize := c.UserConfig.Git.DiffContextSize
|
contextSize := self.UserConfig.Git.DiffContextSize
|
||||||
if plain {
|
if plain {
|
||||||
colorArg = "never"
|
colorArg = "never"
|
||||||
}
|
}
|
||||||
@ -283,53 +283,53 @@ func (c *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.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, c.cmd.Quote(fileName)),
|
contextSize, colorArg, from, to, reverseFlag, self.cmd.Quote(fileName)),
|
||||||
).
|
).
|
||||||
DontLog()
|
DontLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckoutFile checks out the file for the given commit
|
// CheckoutFile checks out the file for the given commit
|
||||||
func (c *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
|
func (self *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
|
||||||
return c.cmd.New(fmt.Sprintf("git checkout %s -- %s", commitSha, c.cmd.Quote(fileName))).Run()
|
return self.cmd.New(fmt.Sprintf("git checkout %s -- %s", commitSha, self.cmd.Quote(fileName))).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiscardAnyUnstagedFileChanges discards any unstages file changes via `git checkout -- .`
|
// DiscardAnyUnstagedFileChanges discards any unstages file changes via `git checkout -- .`
|
||||||
func (c *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
func (self *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
||||||
return c.cmd.New("git checkout -- .").Run()
|
return self.cmd.New("git checkout -- .").Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveTrackedFiles will delete the given file(s) even if they are currently tracked
|
// RemoveTrackedFiles will delete the given file(s) even if they are currently tracked
|
||||||
func (c *WorkingTreeCommands) RemoveTrackedFiles(name string) error {
|
func (self *WorkingTreeCommands) RemoveTrackedFiles(name string) error {
|
||||||
return c.cmd.New("git rm -r --cached -- " + c.cmd.Quote(name)).Run()
|
return self.cmd.New("git rm -r --cached -- " + self.cmd.Quote(name)).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveUntrackedFiles runs `git clean -fd`
|
// RemoveUntrackedFiles runs `git clean -fd`
|
||||||
func (c *WorkingTreeCommands) RemoveUntrackedFiles() error {
|
func (self *WorkingTreeCommands) RemoveUntrackedFiles() error {
|
||||||
return c.cmd.New("git clean -fd").Run()
|
return self.cmd.New("git clean -fd").Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetAndClean removes all unstaged changes and removes all untracked files
|
// ResetAndClean removes all unstaged changes and removes all untracked files
|
||||||
func (c *WorkingTreeCommands) ResetAndClean() error {
|
func (self *WorkingTreeCommands) ResetAndClean() error {
|
||||||
submoduleConfigs, err := c.submodule.GetConfigs()
|
submoduleConfigs, err := self.submodule.GetConfigs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(submoduleConfigs) > 0 {
|
if len(submoduleConfigs) > 0 {
|
||||||
if err := c.submodule.ResetSubmodules(submoduleConfigs); err != nil {
|
if err := self.submodule.ResetSubmodules(submoduleConfigs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.ResetHard("HEAD"); err != nil {
|
if err := self.ResetHard("HEAD"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.RemoveUntrackedFiles()
|
return self.RemoveUntrackedFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetHardHead runs `git reset --hard`
|
// ResetHardHead runs `git reset --hard`
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
@ -146,7 +146,7 @@ func (gui *Gui) handleForceCheckout() error {
|
|||||||
prompt: message,
|
prompt: message,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
gui.logAction(gui.Tr.Actions.ForceCheckoutBranch)
|
gui.logAction(gui.Tr.Actions.ForceCheckoutBranch)
|
||||||
if err := gui.GitCommand.Branch.Checkout(branch.Name, commands.CheckoutOptions{Force: true}); err != nil {
|
if err := gui.GitCommand.Branch.Checkout(branch.Name, git_commands.CheckoutOptions{Force: true}); err != nil {
|
||||||
_ = gui.surfaceError(err)
|
_ = gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
@ -166,7 +166,7 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
|
|||||||
waitingStatus = gui.Tr.CheckingOutStatus
|
waitingStatus = gui.Tr.CheckingOutStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdOptions := commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||||
|
|
||||||
onSuccess := func() {
|
onSuccess := func() {
|
||||||
gui.State.Panels.Branches.SelectedLineIdx = 0
|
gui.State.Panels.Branches.SelectedLineIdx = 0
|
||||||
@ -335,7 +335,7 @@ func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error {
|
|||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
handleConfirm: func() error {
|
handleConfirm: func() error {
|
||||||
gui.logAction(gui.Tr.Actions.Merge)
|
gui.logAction(gui.Tr.Actions.Merge)
|
||||||
err := gui.GitCommand.Branch.Merge(branchName, commands.MergeOpts{})
|
err := gui.GitCommand.Branch.Merge(branchName, git_commands.MergeOpts{})
|
||||||
return gui.handleGenericMergeCommandResult(err)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/updates"
|
"github.com/jesseduffield/lazygit/pkg/updates"
|
||||||
@ -16,6 +17,6 @@ func NewDummyUpdater() *updates.Updater {
|
|||||||
|
|
||||||
func NewDummyGui() *Gui {
|
func NewDummyGui() *Gui {
|
||||||
newAppConfig := config.NewDummyAppConfig()
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, utils.NewDummyGitConfig(), NewDummyUpdater(), "", false)
|
dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, git_config.NewFakeGitConfig(nil), NewDummyUpdater(), "", false)
|
||||||
return dummyGui
|
return dummyGui
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
@ -717,7 +717,7 @@ func (gui *Gui) pullWithLock(opts PullFilesOptions) error {
|
|||||||
gui.logAction(opts.action)
|
gui.logAction(opts.action)
|
||||||
|
|
||||||
err := gui.GitCommand.Sync.Pull(
|
err := gui.GitCommand.Sync.Pull(
|
||||||
commands.PullOptions{
|
git_commands.PullOptions{
|
||||||
RemoteName: opts.RemoteName,
|
RemoteName: opts.RemoteName,
|
||||||
BranchName: opts.BranchName,
|
BranchName: opts.BranchName,
|
||||||
FastForwardOnly: opts.FastForwardOnly,
|
FastForwardOnly: opts.FastForwardOnly,
|
||||||
@ -742,7 +742,7 @@ func (gui *Gui) push(opts pushOpts) error {
|
|||||||
}
|
}
|
||||||
go utils.Safe(func() {
|
go utils.Safe(func() {
|
||||||
gui.logAction(gui.Tr.Actions.Push)
|
gui.logAction(gui.Tr.Actions.Push)
|
||||||
err := gui.GitCommand.Sync.Push(commands.PushOpts{
|
err := gui.GitCommand.Sync.Push(git_commands.PushOpts{
|
||||||
Force: opts.force,
|
Force: opts.force,
|
||||||
UpstreamRemote: opts.upstreamRemote,
|
UpstreamRemote: opts.upstreamRemote,
|
||||||
UpstreamBranch: opts.upstreamBranch,
|
UpstreamBranch: opts.upstreamBranch,
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ func (gui *Gui) fetch() (err error) {
|
|||||||
defer gui.Mutexes.FetchMutex.Unlock()
|
defer gui.Mutexes.FetchMutex.Unlock()
|
||||||
|
|
||||||
gui.logAction("Fetch")
|
gui.logAction("Fetch")
|
||||||
err = gui.GitCommand.Sync.Fetch(commands.FetchOptions{})
|
err = gui.GitCommand.Sync.Fetch(git_commands.FetchOptions{})
|
||||||
|
|
||||||
if err != nil && strings.Contains(err.Error(), "exit status 128") {
|
if err != nil && strings.Contains(err.Error(), "exit status 128") {
|
||||||
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
|
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
|
||||||
@ -230,7 +230,7 @@ func (gui *Gui) backgroundFetch() (err error) {
|
|||||||
gui.Mutexes.FetchMutex.Lock()
|
gui.Mutexes.FetchMutex.Lock()
|
||||||
defer gui.Mutexes.FetchMutex.Unlock()
|
defer gui.Mutexes.FetchMutex.Unlock()
|
||||||
|
|
||||||
err = gui.GitCommand.Sync.Fetch(commands.FetchOptions{Background: true})
|
err = gui.GitCommand.Sync.Fetch(git_commands.FetchOptions{Background: true})
|
||||||
|
|
||||||
_ = gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC})
|
_ = gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC})
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
@ -34,7 +33,3 @@ func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *common.Common
|
|||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDummyGitConfig() git_config.IGitConfig {
|
|
||||||
return git_config.NewFakeGitConfig(map[string]string{})
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user