mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-04 10:34:55 +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"
|
||||
|
||||
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/loaders"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
@ -20,21 +21,21 @@ import (
|
||||
|
||||
// GitCommand is our main git interface
|
||||
type GitCommand struct {
|
||||
Branch *BranchCommands
|
||||
Commit *CommitCommands
|
||||
Config *ConfigCommands
|
||||
Custom *CustomCommands
|
||||
File *FileCommands
|
||||
Flow *FlowCommands
|
||||
Patch *PatchCommands
|
||||
Rebase *RebaseCommands
|
||||
Remote *RemoteCommands
|
||||
Stash *StashCommands
|
||||
Status *StatusCommands
|
||||
Submodule *SubmoduleCommands
|
||||
Sync *SyncCommands
|
||||
Tag *TagCommands
|
||||
WorkingTree *WorkingTreeCommands
|
||||
Branch *git_commands.BranchCommands
|
||||
Commit *git_commands.CommitCommands
|
||||
Config *git_commands.ConfigCommands
|
||||
Custom *git_commands.CustomCommands
|
||||
File *git_commands.FileCommands
|
||||
Flow *git_commands.FlowCommands
|
||||
Patch *git_commands.PatchCommands
|
||||
Rebase *git_commands.RebaseCommands
|
||||
Remote *git_commands.RemoteCommands
|
||||
Stash *git_commands.StashCommands
|
||||
Status *git_commands.StatusCommands
|
||||
Submodule *git_commands.SubmoduleCommands
|
||||
Sync *git_commands.SyncCommands
|
||||
Tag *git_commands.TagCommands
|
||||
WorkingTree *git_commands.WorkingTreeCommands
|
||||
|
||||
Loaders Loaders
|
||||
}
|
||||
@ -91,20 +92,20 @@ func NewGitCommandAux(
|
||||
// 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
|
||||
// on the one struct.
|
||||
configCommands := NewConfigCommands(cmn, gitConfig)
|
||||
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||
configCommands := git_commands.NewConfigCommands(cmn, gitConfig)
|
||||
statusCommands := git_commands.NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
||||
flowCommands := NewFlowCommands(cmn, cmd, configCommands)
|
||||
remoteCommands := NewRemoteCommands(cmn, cmd)
|
||||
branchCommands := NewBranchCommands(cmn, cmd)
|
||||
syncCommands := NewSyncCommands(cmn, cmd)
|
||||
tagCommands := NewTagCommands(cmn, cmd)
|
||||
commitCommands := NewCommitCommands(cmn, cmd)
|
||||
customCommands := NewCustomCommands(cmn, cmd)
|
||||
fileCommands := NewFileCommands(cmn, cmd, configCommands, osCommand)
|
||||
submoduleCommands := NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
||||
workingTreeCommands := NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
||||
rebaseCommands := NewRebaseCommands(
|
||||
flowCommands := git_commands.NewFlowCommands(cmn, cmd, configCommands)
|
||||
remoteCommands := git_commands.NewRemoteCommands(cmn, cmd)
|
||||
branchCommands := git_commands.NewBranchCommands(cmn, cmd)
|
||||
syncCommands := git_commands.NewSyncCommands(cmn, cmd)
|
||||
tagCommands := git_commands.NewTagCommands(cmn, cmd)
|
||||
commitCommands := git_commands.NewCommitCommands(cmn, cmd)
|
||||
customCommands := git_commands.NewCustomCommands(cmn, cmd)
|
||||
fileCommands := git_commands.NewFileCommands(cmn, cmd, configCommands, osCommand)
|
||||
submoduleCommands := git_commands.NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
||||
workingTreeCommands := git_commands.NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
||||
rebaseCommands := git_commands.NewRebaseCommands(
|
||||
cmn,
|
||||
cmd,
|
||||
osCommand,
|
||||
@ -113,10 +114,10 @@ func NewGitCommandAux(
|
||||
configCommands,
|
||||
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
|
||||
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{
|
||||
Branch: branchCommands,
|
||||
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"os"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"github.com/go-errors/errors"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
@ -45,23 +45,23 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
|
||||
editor := c.UserConfig.OS.EditCommand
|
||||
func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
|
||||
editor := self.UserConfig.OS.EditCommand
|
||||
|
||||
if editor == "" {
|
||||
editor = c.config.GetCoreEditor()
|
||||
editor = self.config.GetCoreEditor()
|
||||
}
|
||||
if editor == "" {
|
||||
editor = c.os.Getenv("GIT_EDITOR")
|
||||
editor = self.os.Getenv("GIT_EDITOR")
|
||||
}
|
||||
if editor == "" {
|
||||
editor = c.os.Getenv("VISUAL")
|
||||
editor = self.os.Getenv("VISUAL")
|
||||
}
|
||||
if editor == "" {
|
||||
editor = c.os.Getenv("EDITOR")
|
||||
editor = self.os.Getenv("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"
|
||||
}
|
||||
}
|
||||
@ -71,10 +71,10 @@ func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, e
|
||||
|
||||
templateValues := map[string]string{
|
||||
"editor": editor,
|
||||
"filename": c.cmd.Quote(filename),
|
||||
"filename": self.cmd.Quote(filename),
|
||||
"line": strconv.Itoa(lineNumber),
|
||||
}
|
||||
|
||||
editCmdTemplate := c.UserConfig.OS.EditCommandTemplate
|
||||
editCmdTemplate := self.UserConfig.OS.EditCommandTemplate
|
||||
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"regexp"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"regexp"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"path/filepath"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"bufio"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -87,7 +87,7 @@ func (self *WorkingTreeCommands) UnStageFile(fileNames []string, reset bool) err
|
||||
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() {
|
||||
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
|
||||
// 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 afterFile *models.File
|
||||
@ -123,43 +123,43 @@ func (c *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*m
|
||||
}
|
||||
|
||||
// DiscardAllFileChanges directly
|
||||
func (c *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
||||
func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
||||
if file.IsRename() {
|
||||
beforeFile, afterFile, err := c.BeforeAndAfterFileForRename(file)
|
||||
beforeFile, afterFile, err := self.BeforeAndAfterFileForRename(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.DiscardAllFileChanges(beforeFile); err != nil {
|
||||
if err := self.DiscardAllFileChanges(beforeFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.DiscardAllFileChanges(afterFile); err != nil {
|
||||
if err := self.DiscardAllFileChanges(afterFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
quotedFileName := c.cmd.Quote(file.Name)
|
||||
quotedFileName := self.cmd.Quote(file.Name)
|
||||
|
||||
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
|
||||
}
|
||||
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 nil
|
||||
}
|
||||
|
||||
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 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
|
||||
}
|
||||
}
|
||||
@ -169,30 +169,30 @@ func (c *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
||||
}
|
||||
|
||||
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
|
||||
return node.ForEachFile(c.DiscardAllFileChanges)
|
||||
return node.ForEachFile(self.DiscardAllFileChanges)
|
||||
}
|
||||
|
||||
func (c *WorkingTreeCommands) DiscardUnstagedDirChanges(node *filetree.FileNode) error {
|
||||
if err := c.RemoveUntrackedDirFiles(node); err != nil {
|
||||
func (self *WorkingTreeCommands) DiscardUnstagedDirChanges(node *filetree.FileNode) error {
|
||||
if err := self.RemoveUntrackedDirFiles(node); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
quotedPath := c.cmd.Quote(node.GetPath())
|
||||
if err := c.cmd.New("git checkout -- " + quotedPath).Run(); err != nil {
|
||||
quotedPath := self.cmd.Quote(node.GetPath())
|
||||
if err := self.cmd.New("git checkout -- " + quotedPath).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WorkingTreeCommands) RemoveUntrackedDirFiles(node *filetree.FileNode) error {
|
||||
func (self *WorkingTreeCommands) RemoveUntrackedDirFiles(node *filetree.FileNode) error {
|
||||
untrackedFilePaths := node.GetPathsMatching(
|
||||
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
|
||||
func (c *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
||||
quotedFileName := c.cmd.Quote(file.Name)
|
||||
return c.cmd.New("git checkout -- " + quotedFileName).Run()
|
||||
func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
||||
quotedFileName := self.cmd.Quote(file.Name)
|
||||
return self.cmd.New("git checkout -- " + quotedFileName).Run()
|
||||
}
|
||||
|
||||
// Ignore adds a file to the gitignore for the repo
|
||||
func (c *WorkingTreeCommands) Ignore(filename string) error {
|
||||
return c.os.AppendLineToFile(".gitignore", filename)
|
||||
func (self *WorkingTreeCommands) Ignore(filename string) error {
|
||||
return self.os.AppendLineToFile(".gitignore", filename)
|
||||
}
|
||||
|
||||
// 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
|
||||
s, _ := c.WorktreeFileDiffCmdObj(file, plain, cached, ignoreWhitespace).RunWithOutput()
|
||||
s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached, ignoreWhitespace).RunWithOutput()
|
||||
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 := ""
|
||||
trackedArg := "--"
|
||||
colorArg := c.UserConfig.Git.Paging.ColorArg
|
||||
quotedPath := c.cmd.Quote(node.GetPath())
|
||||
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||
quotedPath := self.cmd.Quote(node.GetPath())
|
||||
ignoreWhitespaceArg := ""
|
||||
contextSize := c.UserConfig.Git.DiffContextSize
|
||||
contextSize := self.UserConfig.Git.DiffContextSize
|
||||
if 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)
|
||||
|
||||
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")
|
||||
c.Log.Infof("saving temporary patch to %s", filepath)
|
||||
if err := c.os.CreateFileWithContent(filepath, patch); err != nil {
|
||||
self.Log.Infof("saving temporary patch to %s", filepath)
|
||||
if err := self.os.CreateFileWithContent(filepath, patch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -262,18 +262,18 @@ func (c *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error {
|
||||
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
|
||||
// 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) {
|
||||
return c.ShowFileDiffCmdObj(from, to, reverse, fileName, plain).RunWithOutput()
|
||||
func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) {
|
||||
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 {
|
||||
colorArg := c.UserConfig.Git.Paging.ColorArg
|
||||
contextSize := c.UserConfig.Git.DiffContextSize
|
||||
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
||||
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||
contextSize := self.UserConfig.Git.DiffContextSize
|
||||
if plain {
|
||||
colorArg = "never"
|
||||
}
|
||||
@ -283,53 +283,53 @@ func (c *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse
|
||||
reverseFlag = " -R "
|
||||
}
|
||||
|
||||
return c.cmd.
|
||||
return self.cmd.
|
||||
New(
|
||||
fmt.Sprintf(
|
||||
"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()
|
||||
}
|
||||
|
||||
// CheckoutFile checks out the file for the given commit
|
||||
func (c *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
|
||||
return c.cmd.New(fmt.Sprintf("git checkout %s -- %s", commitSha, c.cmd.Quote(fileName))).Run()
|
||||
func (self *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
|
||||
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 -- .`
|
||||
func (c *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
||||
return c.cmd.New("git checkout -- .").Run()
|
||||
func (self *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
||||
return self.cmd.New("git checkout -- .").Run()
|
||||
}
|
||||
|
||||
// RemoveTrackedFiles will delete the given file(s) even if they are currently tracked
|
||||
func (c *WorkingTreeCommands) RemoveTrackedFiles(name string) error {
|
||||
return c.cmd.New("git rm -r --cached -- " + c.cmd.Quote(name)).Run()
|
||||
func (self *WorkingTreeCommands) RemoveTrackedFiles(name string) error {
|
||||
return self.cmd.New("git rm -r --cached -- " + self.cmd.Quote(name)).Run()
|
||||
}
|
||||
|
||||
// RemoveUntrackedFiles runs `git clean -fd`
|
||||
func (c *WorkingTreeCommands) RemoveUntrackedFiles() error {
|
||||
return c.cmd.New("git clean -fd").Run()
|
||||
func (self *WorkingTreeCommands) RemoveUntrackedFiles() error {
|
||||
return self.cmd.New("git clean -fd").Run()
|
||||
}
|
||||
|
||||
// ResetAndClean removes all unstaged changes and removes all untracked files
|
||||
func (c *WorkingTreeCommands) ResetAndClean() error {
|
||||
submoduleConfigs, err := c.submodule.GetConfigs()
|
||||
func (self *WorkingTreeCommands) ResetAndClean() error {
|
||||
submoduleConfigs, err := self.submodule.GetConfigs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(submoduleConfigs) > 0 {
|
||||
if err := c.submodule.ResetSubmodules(submoduleConfigs); err != nil {
|
||||
if err := self.submodule.ResetSubmodules(submoduleConfigs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.ResetHard("HEAD"); err != nil {
|
||||
if err := self.ResetHard("HEAD"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.RemoveUntrackedFiles()
|
||||
return self.RemoveUntrackedFiles()
|
||||
}
|
||||
|
||||
// ResetHardHead runs `git reset --hard`
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"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/utils"
|
||||
)
|
||||
@ -146,7 +146,7 @@ func (gui *Gui) handleForceCheckout() error {
|
||||
prompt: message,
|
||||
handleConfirm: func() error {
|
||||
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)
|
||||
}
|
||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||
@ -166,7 +166,7 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
|
||||
waitingStatus = gui.Tr.CheckingOutStatus
|
||||
}
|
||||
|
||||
cmdOptions := commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||
|
||||
onSuccess := func() {
|
||||
gui.State.Panels.Branches.SelectedLineIdx = 0
|
||||
@ -335,7 +335,7 @@ func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error {
|
||||
prompt: prompt,
|
||||
handleConfirm: func() error {
|
||||
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)
|
||||
},
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/updates"
|
||||
@ -16,6 +17,6 @@ func NewDummyUpdater() *updates.Updater {
|
||||
|
||||
func NewDummyGui() *Gui {
|
||||
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
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"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/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
@ -717,7 +717,7 @@ func (gui *Gui) pullWithLock(opts PullFilesOptions) error {
|
||||
gui.logAction(opts.action)
|
||||
|
||||
err := gui.GitCommand.Sync.Pull(
|
||||
commands.PullOptions{
|
||||
git_commands.PullOptions{
|
||||
RemoteName: opts.RemoteName,
|
||||
BranchName: opts.BranchName,
|
||||
FastForwardOnly: opts.FastForwardOnly,
|
||||
@ -742,7 +742,7 @@ func (gui *Gui) push(opts pushOpts) error {
|
||||
}
|
||||
go utils.Safe(func() {
|
||||
gui.logAction(gui.Tr.Actions.Push)
|
||||
err := gui.GitCommand.Sync.Push(commands.PushOpts{
|
||||
err := gui.GitCommand.Sync.Push(git_commands.PushOpts{
|
||||
Force: opts.force,
|
||||
UpstreamRemote: opts.upstreamRemote,
|
||||
UpstreamBranch: opts.upstreamBranch,
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
@ -215,7 +215,7 @@ func (gui *Gui) fetch() (err error) {
|
||||
defer gui.Mutexes.FetchMutex.Unlock()
|
||||
|
||||
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") {
|
||||
_ = gui.createErrorPanel(gui.Tr.PassUnameWrong)
|
||||
@ -230,7 +230,7 @@ func (gui *Gui) backgroundFetch() (err error) {
|
||||
gui.Mutexes.FetchMutex.Lock()
|
||||
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})
|
||||
|
||||
|
@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
@ -34,7 +33,3 @@ func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *common.Common
|
||||
UserConfig: userConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func NewDummyGitConfig() git_config.IGitConfig {
|
||||
return git_config.NewFakeGitConfig(map[string]string{})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user