diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-08 14:00:36 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-09 14:09:53 +1100 |
commit | c9a0cc6b30dca6ff6c520268c10afff4e99a68e9 (patch) | |
tree | 74a03be28aafb5fba5c8391ca611aeb25ca89445 | |
parent | 3621854dc79baf2064b00b561ebea0ecc8fcb5df (diff) |
refactor
-rw-r--r-- | pkg/commands/dummies.go | 28 | ||||
-rw-r--r-- | pkg/commands/git.go | 61 | ||||
-rw-r--r-- | pkg/commands/git_commands/branch.go (renamed from pkg/commands/branches.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/branch_test.go (renamed from pkg/commands/branches_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/commit.go (renamed from pkg/commands/commits.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/commit_test.go (renamed from pkg/commands/commits_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/config.go (renamed from pkg/commands/config.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/custom.go (renamed from pkg/commands/custom.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/deps_test.go (renamed from pkg/commands/deps_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/file.go (renamed from pkg/commands/files.go) | 20 | ||||
-rw-r--r-- | pkg/commands/git_commands/file_test.go (renamed from pkg/commands/files_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/flow.go (renamed from pkg/commands/flow.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/patch.go (renamed from pkg/commands/patch_rebases.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/rebase.go (renamed from pkg/commands/rebasing.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/rebase_test.go (renamed from pkg/commands/rebasing_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/remote.go (renamed from pkg/commands/remotes.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/stash.go (renamed from pkg/commands/stash_entries.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/stash_test.go (renamed from pkg/commands/stash_entries_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/status.go (renamed from pkg/commands/status.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/submodule.go (renamed from pkg/commands/submodules.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/sync.go (renamed from pkg/commands/sync.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/sync_test.go (renamed from pkg/commands/sync_test.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/tag.go (renamed from pkg/commands/tags.go) | 2 | ||||
-rw-r--r-- | pkg/commands/git_commands/working_tree.go (renamed from pkg/commands/working_tree.go) | 114 | ||||
-rw-r--r-- | pkg/commands/git_commands/working_tree_test.go (renamed from pkg/commands/working_tree_test.go) | 2 | ||||
-rw-r--r-- | pkg/gui/branches_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/dummies.go | 3 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/global_handlers.go | 6 | ||||
-rw-r--r-- | pkg/utils/dummies.go | 5 |
30 files changed, 131 insertions, 162 deletions
diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go deleted file mode 100644 index 38982b93a..000000000 --- a/pkg/commands/dummies.go +++ /dev/null @@ -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) -} diff --git a/pkg/commands/git.go b/pkg/commands/git.go index e0a7a8635..70aa859e9 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -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, diff --git a/pkg/commands/branches.go b/pkg/commands/git_commands/branch.go index c9cd444ae..50dfc036b 100644 --- a/pkg/commands/branches.go +++ b/pkg/commands/git_commands/branch.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/branches_test.go b/pkg/commands/git_commands/branch_test.go index 102e5f661..447ccaaff 100644 --- a/pkg/commands/branches_test.go +++ b/pkg/commands/git_commands/branch_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "testing" diff --git a/pkg/commands/commits.go b/pkg/commands/git_commands/commit.go index 7ae0fe4bd..5b36d7950 100644 --- a/pkg/commands/commits.go +++ b/pkg/commands/git_commands/commit.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/commits_test.go b/pkg/commands/git_commands/commit_test.go index b8a5cebc3..6408f440a 100644 --- a/pkg/commands/commits_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "testing" diff --git a/pkg/commands/config.go b/pkg/commands/git_commands/config.go index 5d296ddb8..1818edc2d 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/git_commands/config.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "os" diff --git a/pkg/commands/custom.go b/pkg/commands/git_commands/custom.go index a9bf64bf4..27a0bf93f 100644 --- a/pkg/commands/custom.go +++ b/pkg/commands/git_commands/custom.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "github.com/jesseduffield/lazygit/pkg/commands/oscommands" diff --git a/pkg/commands/deps_test.go b/pkg/commands/git_commands/deps_test.go index 59eeb8a0e..f0d7a2a7b 100644 --- a/pkg/commands/deps_test.go +++ b/pkg/commands/git_commands/deps_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "github.com/go-errors/errors" diff --git a/pkg/commands/files.go b/pkg/commands/git_commands/file.go index 5b4f7fb1f..070a50790 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/git_commands/file.go @@ -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 } diff --git a/pkg/commands/files_test.go b/pkg/commands/git_commands/file_test.go index ed8a41783..a26699b3e 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/git_commands/file_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "testing" diff --git a/pkg/commands/flow.go b/pkg/commands/git_commands/flow.go index 0e0186f96..6a061b537 100644 --- a/pkg/commands/flow.go +++ b/pkg/commands/git_commands/flow.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "regexp" diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/git_commands/patch.go index a006f3b71..2949c6ac2 100644 --- a/pkg/commands/patch_rebases.go +++ b/pkg/commands/git_commands/patch.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/rebasing.go b/pkg/commands/git_commands/rebase.go index 4bc92238d..08c8b4cb5 100644 --- a/pkg/commands/rebasing.go +++ b/pkg/commands/git_commands/rebase.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/rebasing_test.go b/pkg/commands/git_commands/rebase_test.go index 582da91b7..e4731ad83 100644 --- a/pkg/commands/rebasing_test.go +++ b/pkg/commands/git_commands/rebase_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "regexp" diff --git a/pkg/commands/remotes.go b/pkg/commands/git_commands/remote.go index 46acd49d8..fe8ab57b0 100644 --- a/pkg/commands/remotes.go +++ b/pkg/commands/git_commands/remote.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/stash_entries.go b/pkg/commands/git_commands/stash.go index 1e02ddaa5..9141c1702 100644 --- a/pkg/commands/stash_entries.go +++ b/pkg/commands/git_commands/stash.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/stash_entries_test.go b/pkg/commands/git_commands/stash_test.go index 9f51ea3f3..f9f2428e0 100644 --- a/pkg/commands/stash_entries_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "testing" diff --git a/pkg/commands/status.go b/pkg/commands/git_commands/status.go index c6f038ac8..fe89646d2 100644 --- a/pkg/commands/status.go +++ b/pkg/commands/git_commands/status.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "path/filepath" diff --git a/pkg/commands/submodules.go b/pkg/commands/git_commands/submodule.go index 9ccf29be2..3630f531f 100644 --- a/pkg/commands/submodules.go +++ b/pkg/commands/git_commands/submodule.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "bufio" diff --git a/pkg/commands/sync.go b/pkg/commands/git_commands/sync.go index c926aef64..56060f008 100644 --- a/pkg/commands/sync.go +++ b/pkg/commands/git_commands/sync.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/sync_test.go b/pkg/commands/git_commands/sync_test.go index af9942aa0..a1eae5dbb 100644 --- a/pkg/commands/sync_test.go +++ b/pkg/commands/git_commands/sync_test.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "testing" diff --git a/pkg/commands/tags.go b/pkg/commands/git_commands/tag.go index b802aef8c..a2dd82850 100644 --- a/pkg/commands/tags.go +++ b/pkg/commands/git_commands/tag.go @@ -1,4 +1,4 @@ -package commands +package git_commands import ( "fmt" diff --git a/pkg/commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index a44caceb5..084643532 100644 --- a/pkg/commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -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.UserCon |