mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-27 22:01:46 +02:00
refactor to group up more commonly used git command stuff
This commit is contained in:
parent
9706416a41
commit
3e80a9e886
@ -92,32 +92,27 @@ 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.
|
||||
// common ones are: cmn, osCommand, dotGitDir, configCommands
|
||||
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)
|
||||
statusCommands := git_commands.NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||
gitCommon := git_commands.NewGitCommon(cmn, cmd, osCommand, dotGitDir, repo, configCommands)
|
||||
|
||||
statusCommands := git_commands.NewStatusCommands(gitCommon)
|
||||
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
||||
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,
|
||||
commitCommands,
|
||||
workingTreeCommands,
|
||||
configCommands,
|
||||
dotGitDir,
|
||||
)
|
||||
stashCommands := git_commands.NewStashCommands(cmn, cmd, osCommand, fileLoader, workingTreeCommands)
|
||||
flowCommands := git_commands.NewFlowCommands(gitCommon)
|
||||
remoteCommands := git_commands.NewRemoteCommands(gitCommon)
|
||||
branchCommands := git_commands.NewBranchCommands(gitCommon)
|
||||
syncCommands := git_commands.NewSyncCommands(gitCommon)
|
||||
tagCommands := git_commands.NewTagCommands(gitCommon)
|
||||
commitCommands := git_commands.NewCommitCommands(gitCommon)
|
||||
customCommands := git_commands.NewCustomCommands(gitCommon)
|
||||
fileCommands := git_commands.NewFileCommands(gitCommon)
|
||||
submoduleCommands := git_commands.NewSubmoduleCommands(gitCommon)
|
||||
workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader)
|
||||
rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands)
|
||||
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
|
||||
// TODO: have patch manager take workingTreeCommands in its entirety
|
||||
patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch, workingTreeCommands.ShowFileDiff)
|
||||
patchCommands := git_commands.NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
|
||||
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchManager)
|
||||
|
||||
return &GitCommand{
|
||||
Branch: branchCommands,
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
@ -17,18 +16,12 @@ import (
|
||||
const CurrentBranchNameRegex = `(?m)^\*.*?([^ ]*?)\)?$`
|
||||
|
||||
type BranchCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewBranchCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
) *BranchCommands {
|
||||
func NewBranchCommands(gitCommon *GitCommon) *BranchCommands {
|
||||
return &BranchCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,9 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func NewBranchCommandsWithRunner(runner *oscommands.FakeCmdObjRunner) *BranchCommands {
|
||||
builder := oscommands.NewDummyCmdObjBuilder(runner)
|
||||
return NewBranchCommands(utils.NewDummyCommon(), builder)
|
||||
}
|
||||
|
||||
func TestBranchGetCommitDifferences(t *testing.T) {
|
||||
type scenario struct {
|
||||
testName string
|
||||
@ -48,7 +42,7 @@ func TestBranchGetCommitDifferences(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
instance := NewBranchCommandsWithRunner(s.runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: s.runner})
|
||||
pushables, pullables := instance.GetCommitDifferences("HEAD", "@{u}")
|
||||
assert.EqualValues(t, s.expectedPushables, pushables)
|
||||
assert.EqualValues(t, s.expectedPullables, pullables)
|
||||
@ -60,7 +54,7 @@ func TestBranchGetCommitDifferences(t *testing.T) {
|
||||
func TestBranchNewBranch(t *testing.T) {
|
||||
runner := oscommands.NewFakeRunner(t).
|
||||
Expect(`git checkout -b "test" "master"`, "", nil)
|
||||
instance := NewBranchCommandsWithRunner(runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: runner})
|
||||
|
||||
assert.NoError(t, instance.New("test", "master"))
|
||||
runner.CheckForMissingCalls()
|
||||
@ -96,7 +90,7 @@ func TestBranchDeleteBranch(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
instance := NewBranchCommandsWithRunner(s.runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: s.runner})
|
||||
|
||||
s.test(instance.Delete("test", s.force))
|
||||
s.runner.CheckForMissingCalls()
|
||||
@ -107,7 +101,7 @@ func TestBranchDeleteBranch(t *testing.T) {
|
||||
func TestBranchMerge(t *testing.T) {
|
||||
runner := oscommands.NewFakeRunner(t).
|
||||
Expect(`git merge --no-edit "test"`, "", nil)
|
||||
instance := NewBranchCommandsWithRunner(runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: runner})
|
||||
|
||||
assert.NoError(t, instance.Merge("test", MergeOpts{}))
|
||||
runner.CheckForMissingCalls()
|
||||
@ -143,7 +137,7 @@ func TestBranchCheckout(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
instance := NewBranchCommandsWithRunner(s.runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: s.runner})
|
||||
s.test(instance.Checkout("test", CheckoutOptions{Force: s.force}))
|
||||
s.runner.CheckForMissingCalls()
|
||||
})
|
||||
@ -154,7 +148,7 @@ func TestBranchGetBranchGraph(t *testing.T) {
|
||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
||||
"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--",
|
||||
}, "", nil)
|
||||
instance := NewBranchCommandsWithRunner(runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: runner})
|
||||
_, err := instance.GetGraph("test")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@ -163,7 +157,7 @@ func TestBranchGetAllBranchGraph(t *testing.T) {
|
||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
||||
"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium",
|
||||
}, "", nil)
|
||||
instance := NewBranchCommandsWithRunner(runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: runner})
|
||||
err := instance.AllBranchesLogCmdObj().Run()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@ -223,7 +217,7 @@ func TestBranchCurrentBranchName(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
instance := NewBranchCommandsWithRunner(s.runner)
|
||||
instance := buildBranchCommands(commonDeps{runner: s.runner})
|
||||
s.test(instance.CurrentBranchName())
|
||||
s.runner.CheckForMissingCalls()
|
||||
})
|
||||
|
@ -5,22 +5,15 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type CommitCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewCommitCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
) *CommitCommands {
|
||||
func NewCommitCommands(gitCommon *GitCommon) *CommitCommands {
|
||||
return &CommitCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
34
pkg/commands/git_commands/common.go
Normal file
34
pkg/commands/git_commands/common.go
Normal file
@ -0,0 +1,34 @@
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
gogit "github.com/jesseduffield/go-git/v5"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type GitCommon struct {
|
||||
*common.Common
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
os *oscommands.OSCommand
|
||||
dotGitDir string
|
||||
repo *gogit.Repository
|
||||
config *ConfigCommands
|
||||
}
|
||||
|
||||
func NewGitCommon(
|
||||
cmn *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
osCommand *oscommands.OSCommand,
|
||||
dotGitDir string,
|
||||
repo *gogit.Repository,
|
||||
config *ConfigCommands,
|
||||
) *GitCommon {
|
||||
return &GitCommon{
|
||||
Common: cmn,
|
||||
cmd: cmd,
|
||||
os: osCommand,
|
||||
dotGitDir: dotGitDir,
|
||||
repo: repo,
|
||||
config: config,
|
||||
}
|
||||
}
|
@ -1,23 +1,12 @@
|
||||
package git_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type CustomCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewCustomCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
) *CustomCommands {
|
||||
func NewCustomCommands(gitCommon *GitCommon) *CustomCommands {
|
||||
return &CustomCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,120 +22,123 @@ type commonDeps struct {
|
||||
cmd *oscommands.CmdObjBuilder
|
||||
}
|
||||
|
||||
func completeDeps(deps commonDeps) commonDeps {
|
||||
if deps.runner == nil {
|
||||
deps.runner = oscommands.NewFakeRunner(nil)
|
||||
func buildGitCommon(deps commonDeps) *GitCommon {
|
||||
gitCommon := &GitCommon{}
|
||||
|
||||
gitCommon.Common = deps.common
|
||||
if gitCommon.Common == nil {
|
||||
gitCommon.Common = utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
||||
}
|
||||
|
||||
if deps.userConfig == nil {
|
||||
deps.userConfig = config.GetDefaultConfig()
|
||||
runner := deps.runner
|
||||
if runner == nil {
|
||||
runner = oscommands.NewFakeRunner(nil)
|
||||
}
|
||||
|
||||
if deps.gitConfig == nil {
|
||||
deps.gitConfig = git_config.NewFakeGitConfig(nil)
|
||||
cmd := deps.cmd
|
||||
// gotta check deps.cmd because it's not an interface type and an interface value of nil is not considered to be nil
|
||||
if cmd == nil {
|
||||
cmd = oscommands.NewDummyCmdObjBuilder(runner)
|
||||
}
|
||||
gitCommon.cmd = cmd
|
||||
|
||||
gitCommon.Common.UserConfig = deps.userConfig
|
||||
if gitCommon.Common.UserConfig == nil {
|
||||
gitCommon.Common.UserConfig = config.GetDefaultConfig()
|
||||
}
|
||||
|
||||
if deps.getenv == nil {
|
||||
deps.getenv = func(string) string { return "" }
|
||||
gitConfig := deps.gitConfig
|
||||
if gitConfig == nil {
|
||||
gitConfig = git_config.NewFakeGitConfig(nil)
|
||||
}
|
||||
|
||||
if deps.removeFile == nil {
|
||||
deps.removeFile = func(string) error { return errors.New("unexpected call to removeFile") }
|
||||
gitCommon.repo = buildRepo()
|
||||
gitCommon.config = NewConfigCommands(gitCommon.Common, gitConfig, gitCommon.repo)
|
||||
|
||||
getenv := deps.getenv
|
||||
if getenv == nil {
|
||||
getenv = func(string) string { return "" }
|
||||
}
|
||||
|
||||
if deps.dotGitDir == "" {
|
||||
deps.dotGitDir = ".git"
|
||||
removeFile := deps.removeFile
|
||||
if removeFile == nil {
|
||||
removeFile = func(string) error { return errors.New("unexpected call to removeFile") }
|
||||
}
|
||||
|
||||
if deps.common == nil {
|
||||
deps.common = utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
||||
}
|
||||
|
||||
if deps.cmd == nil {
|
||||
deps.cmd = oscommands.NewDummyCmdObjBuilder(deps.runner)
|
||||
}
|
||||
|
||||
return deps
|
||||
}
|
||||
|
||||
func buildConfigCommands(deps commonDeps) *ConfigCommands {
|
||||
deps = completeDeps(deps)
|
||||
common := utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
||||
|
||||
// TODO: think of a way to actually mock this outnil
|
||||
var repo *gogit.Repository = nil
|
||||
|
||||
return NewConfigCommands(common, deps.gitConfig, repo)
|
||||
}
|
||||
|
||||
func buildOSCommand(deps commonDeps) *oscommands.OSCommand {
|
||||
deps = completeDeps(deps)
|
||||
|
||||
return oscommands.NewDummyOSCommandWithDeps(oscommands.OSCommandDeps{
|
||||
Common: deps.common,
|
||||
GetenvFn: deps.getenv,
|
||||
Cmd: deps.cmd,
|
||||
RemoveFileFn: deps.removeFile,
|
||||
gitCommon.os = oscommands.NewDummyOSCommandWithDeps(oscommands.OSCommandDeps{
|
||||
Common: gitCommon.Common,
|
||||
GetenvFn: getenv,
|
||||
Cmd: cmd,
|
||||
RemoveFileFn: removeFile,
|
||||
})
|
||||
|
||||
gitCommon.dotGitDir = deps.dotGitDir
|
||||
if gitCommon.dotGitDir == "" {
|
||||
gitCommon.dotGitDir = ".git"
|
||||
}
|
||||
|
||||
return gitCommon
|
||||
}
|
||||
|
||||
func buildFileLoader(deps commonDeps) *loaders.FileLoader {
|
||||
deps = completeDeps(deps)
|
||||
func buildRepo() *gogit.Repository {
|
||||
// TODO: think of a way to actually mock this out
|
||||
var repo *gogit.Repository = nil
|
||||
return repo
|
||||
}
|
||||
|
||||
configCommands := buildConfigCommands(deps)
|
||||
|
||||
return loaders.NewFileLoader(deps.common, deps.cmd, configCommands)
|
||||
func buildFileLoader(gitCommon *GitCommon) *loaders.FileLoader {
|
||||
return loaders.NewFileLoader(gitCommon.Common, gitCommon.cmd, gitCommon.config)
|
||||
}
|
||||
|
||||
func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands {
|
||||
deps = completeDeps(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
|
||||
return NewSubmoduleCommands(deps.common, deps.cmd, deps.dotGitDir)
|
||||
return NewSubmoduleCommands(gitCommon)
|
||||
}
|
||||
|
||||
func buildCommitCommands(deps commonDeps) *CommitCommands {
|
||||
deps = completeDeps(deps)
|
||||
return NewCommitCommands(deps.common, deps.cmd)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
return NewCommitCommands(gitCommon)
|
||||
}
|
||||
|
||||
func buildWorkingTreeCommands(deps commonDeps) *WorkingTreeCommands {
|
||||
deps = completeDeps(deps)
|
||||
osCommand := buildOSCommand(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
submoduleCommands := buildSubmoduleCommands(deps)
|
||||
fileLoader := buildFileLoader(deps)
|
||||
fileLoader := buildFileLoader(gitCommon)
|
||||
|
||||
return NewWorkingTreeCommands(deps.common, deps.cmd, submoduleCommands, osCommand, fileLoader)
|
||||
return NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader)
|
||||
}
|
||||
|
||||
func buildStashCommands(deps commonDeps) *StashCommands {
|
||||
deps = completeDeps(deps)
|
||||
osCommand := buildOSCommand(deps)
|
||||
fileLoader := buildFileLoader(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
fileLoader := buildFileLoader(gitCommon)
|
||||
workingTreeCommands := buildWorkingTreeCommands(deps)
|
||||
|
||||
return NewStashCommands(deps.common, deps.cmd, osCommand, fileLoader, workingTreeCommands)
|
||||
return NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
|
||||
}
|
||||
|
||||
func buildRebaseCommands(deps commonDeps) *RebaseCommands {
|
||||
deps = completeDeps(deps)
|
||||
configCommands := buildConfigCommands(deps)
|
||||
osCommand := buildOSCommand(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
workingTreeCommands := buildWorkingTreeCommands(deps)
|
||||
commitCommands := buildCommitCommands(deps)
|
||||
|
||||
return NewRebaseCommands(deps.common, deps.cmd, osCommand, commitCommands, workingTreeCommands, configCommands, deps.dotGitDir)
|
||||
return NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands)
|
||||
}
|
||||
|
||||
func buildSyncCommands(deps commonDeps) *SyncCommands {
|
||||
deps = completeDeps(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
|
||||
return NewSyncCommands(deps.common, deps.cmd)
|
||||
return NewSyncCommands(gitCommon)
|
||||
}
|
||||
|
||||
func buildFileCommands(deps commonDeps) *FileCommands {
|
||||
deps = completeDeps(deps)
|
||||
configCommands := buildConfigCommands(deps)
|
||||
osCommand := buildOSCommand(deps)
|
||||
gitCommon := buildGitCommon(deps)
|
||||
|
||||
return NewFileCommands(deps.common, deps.cmd, configCommands, osCommand)
|
||||
return NewFileCommands(gitCommon)
|
||||
}
|
||||
|
||||
func buildBranchCommands(deps commonDeps) *BranchCommands {
|
||||
gitCommon := buildGitCommon(deps)
|
||||
|
||||
return NewBranchCommands(gitCommon)
|
||||
}
|
||||
|
@ -5,34 +5,16 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
type FileCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
config *ConfigCommands
|
||||
os FileOSCommand
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
type FileOSCommand interface {
|
||||
Getenv(string) string
|
||||
}
|
||||
|
||||
func NewFileCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
config *ConfigCommands,
|
||||
osCommand FileOSCommand,
|
||||
) *FileCommands {
|
||||
func NewFileCommands(gitCommon *GitCommon) *FileCommands {
|
||||
return &FileCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
config: config,
|
||||
os: osCommand,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,25 +6,17 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type FlowCommands struct {
|
||||
*common.Common
|
||||
|
||||
config *ConfigCommands
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewFlowCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
config *ConfigCommands,
|
||||
gitCommon *GitCommon,
|
||||
) *FlowCommands {
|
||||
return &FlowCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
config: config,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,40 +5,34 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type PatchCommands struct {
|
||||
*common.Common
|
||||
*GitCommon
|
||||
rebase *RebaseCommands
|
||||
commit *CommitCommands
|
||||
status *StatusCommands
|
||||
stash *StashCommands
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
rebase *RebaseCommands
|
||||
commit *CommitCommands
|
||||
config *ConfigCommands
|
||||
stash *StashCommands
|
||||
status *StatusCommands
|
||||
PatchManager *patch.PatchManager
|
||||
}
|
||||
|
||||
func NewPatchCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
rebaseCommands *RebaseCommands,
|
||||
commitCommands *CommitCommands,
|
||||
configCommands *ConfigCommands,
|
||||
statusCommands *StatusCommands,
|
||||
gitCommon *GitCommon,
|
||||
rebase *RebaseCommands,
|
||||
commit *CommitCommands,
|
||||
status *StatusCommands,
|
||||
stash *StashCommands,
|
||||
patchManager *patch.PatchManager,
|
||||
) *PatchCommands {
|
||||
return &PatchCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
rebase: rebaseCommands,
|
||||
commit: commitCommands,
|
||||
config: configCommands,
|
||||
status: statusCommands,
|
||||
GitCommon: gitCommon,
|
||||
rebase: rebase,
|
||||
commit: commit,
|
||||
status: status,
|
||||
stash: stash,
|
||||
PatchManager: patchManager,
|
||||
}
|
||||
}
|
||||
|
@ -9,39 +9,25 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type RebaseCommands struct {
|
||||
*common.Common
|
||||
*GitCommon
|
||||
commit *CommitCommands
|
||||
workingTree *WorkingTreeCommands
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
osCommand *oscommands.OSCommand
|
||||
|
||||
commit *CommitCommands
|
||||
workingTree *WorkingTreeCommands
|
||||
config *ConfigCommands
|
||||
dotGitDir string
|
||||
onSuccessfulContinue func() error
|
||||
}
|
||||
|
||||
func NewRebaseCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
osCommand *oscommands.OSCommand,
|
||||
gitCommon *GitCommon,
|
||||
commitCommands *CommitCommands,
|
||||
workingTreeCommands *WorkingTreeCommands,
|
||||
configCommands *ConfigCommands,
|
||||
dotGitDir string,
|
||||
) *RebaseCommands {
|
||||
return &RebaseCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
osCommand: osCommand,
|
||||
GitCommon: gitCommon,
|
||||
commit: commitCommands,
|
||||
workingTree: workingTreeCommands,
|
||||
config: configCommands,
|
||||
dotGitDir: dotGitDir,
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +105,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseSha string, todo
|
||||
if todo == "" {
|
||||
gitSequenceEditor = "true"
|
||||
} else {
|
||||
self.osCommand.LogCommand(fmt.Sprintf("Creating TODO file for interactive rebase: \n\n%s", todo), false)
|
||||
self.os.LogCommand(fmt.Sprintf("Creating TODO file for interactive rebase: \n\n%s", todo), false)
|
||||
}
|
||||
|
||||
cmdObj.AddEnvVars(
|
||||
@ -328,7 +314,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm
|
||||
|
||||
// check if file exists in previous commit (this command returns an error if the file doesn't exist)
|
||||
if err := self.cmd.New("git cat-file -e HEAD^:" + self.cmd.Quote(fileName)).Run(); err != nil {
|
||||
if err := self.osCommand.Remove(fileName); err != nil {
|
||||
if err := self.os.Remove(fileName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.workingTree.StageFile(fileName); err != nil {
|
||||
|
@ -2,24 +2,15 @@ package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type RemoteCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewRemoteCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
) *RemoteCommands {
|
||||
func NewRemoteCommands(gitCommon *GitCommon) *RemoteCommands {
|
||||
return &RemoteCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,30 +5,22 @@ import (
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type StashCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
fileLoader *loaders.FileLoader
|
||||
osCommand *oscommands.OSCommand
|
||||
workingTree *WorkingTreeCommands
|
||||
}
|
||||
|
||||
func NewStashCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
osCommand *oscommands.OSCommand,
|
||||
gitCommon *GitCommon,
|
||||
fileLoader *loaders.FileLoader,
|
||||
workingTree *WorkingTreeCommands,
|
||||
) *StashCommands {
|
||||
return &StashCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
fileLoader: fileLoader,
|
||||
osCommand: osCommand,
|
||||
workingTree: workingTree,
|
||||
}
|
||||
}
|
||||
@ -73,7 +65,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.osCommand.PipeCommands("git stash show -p", "git apply -R"); err != nil {
|
||||
if err := self.os.PipeCommands("git stash show -p", "git apply -R"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -4,43 +4,32 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
gogit "github.com/jesseduffield/go-git/v5"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type StatusCommands struct {
|
||||
*common.Common
|
||||
osCommand *oscommands.OSCommand
|
||||
repo *gogit.Repository
|
||||
dotGitDir string
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewStatusCommands(
|
||||
common *common.Common,
|
||||
osCommand *oscommands.OSCommand,
|
||||
repo *gogit.Repository,
|
||||
dotGitDir string,
|
||||
gitCommon *GitCommon,
|
||||
) *StatusCommands {
|
||||
return &StatusCommands{
|
||||
Common: common,
|
||||
osCommand: osCommand,
|
||||
repo: repo,
|
||||
dotGitDir: dotGitDir,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
|
||||
// and "interactive" for interactive rebase
|
||||
func (self *StatusCommands) RebaseMode() (enums.RebaseMode, error) {
|
||||
exists, err := self.osCommand.FileExists(filepath.Join(self.dotGitDir, "rebase-apply"))
|
||||
exists, err := self.os.FileExists(filepath.Join(self.dotGitDir, "rebase-apply"))
|
||||
if err != nil {
|
||||
return enums.REBASE_MODE_NONE, err
|
||||
}
|
||||
if exists {
|
||||
return enums.REBASE_MODE_NORMAL, nil
|
||||
}
|
||||
exists, err = self.osCommand.FileExists(filepath.Join(self.dotGitDir, "rebase-merge"))
|
||||
exists, err = self.os.FileExists(filepath.Join(self.dotGitDir, "rebase-merge"))
|
||||
if exists {
|
||||
return enums.REBASE_MODE_INTERACTIVE, err
|
||||
} else {
|
||||
@ -62,7 +51,7 @@ func (self *StatusCommands) WorkingTreeState() enums.RebaseMode {
|
||||
|
||||
// IsInMergeState states whether we are still mid-merge
|
||||
func (self *StatusCommands) IsInMergeState() (bool, error) {
|
||||
return self.osCommand.FileExists(filepath.Join(self.dotGitDir, "MERGE_HEAD"))
|
||||
return self.os.FileExists(filepath.Join(self.dotGitDir, "MERGE_HEAD"))
|
||||
}
|
||||
|
||||
func (self *StatusCommands) IsBareRepo() bool {
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
// .gitmodules looks like this:
|
||||
@ -19,17 +18,12 @@ import (
|
||||
// url = git@github.com:subbo.git
|
||||
|
||||
type SubmoduleCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
dotGitDir string
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewSubmoduleCommands(common *common.Common, cmd oscommands.ICmdObjBuilder, dotGitDir string) *SubmoduleCommands {
|
||||
func NewSubmoduleCommands(gitCommon *GitCommon) *SubmoduleCommands {
|
||||
return &SubmoduleCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
dotGitDir: dotGitDir,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,22 +5,15 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type SyncCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewSyncCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
) *SyncCommands {
|
||||
func NewSyncCommands(gitCommon *GitCommon) *SyncCommands {
|
||||
return &SyncCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,21 +2,15 @@ package git_commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
)
|
||||
|
||||
type TagCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
*GitCommon
|
||||
}
|
||||
|
||||
func NewTagCommands(common *common.Common, cmd oscommands.ICmdObjBuilder) *TagCommands {
|
||||
func NewTagCommands(gitCommon *GitCommon) *TagCommands {
|
||||
return &TagCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
GitCommon: gitCommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,38 +10,24 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
type WorkingTreeCommands struct {
|
||||
*common.Common
|
||||
|
||||
cmd oscommands.ICmdObjBuilder
|
||||
os WorkingTreeOSCommand
|
||||
*GitCommon
|
||||
submodule *SubmoduleCommands
|
||||
fileLoader *loaders.FileLoader
|
||||
}
|
||||
|
||||
type WorkingTreeOSCommand interface {
|
||||
RemoveFile(string) error
|
||||
CreateFileWithContent(string, string) error
|
||||
AppendLineToFile(string, string) error
|
||||
}
|
||||
|
||||
func NewWorkingTreeCommands(
|
||||
common *common.Common,
|
||||
cmd oscommands.ICmdObjBuilder,
|
||||
submoduleCommands *SubmoduleCommands,
|
||||
osCommand WorkingTreeOSCommand,
|
||||
gitCommon *GitCommon,
|
||||
submodule *SubmoduleCommands,
|
||||
fileLoader *loaders.FileLoader,
|
||||
) *WorkingTreeCommands {
|
||||
return &WorkingTreeCommands{
|
||||
Common: common,
|
||||
cmd: cmd,
|
||||
os: osCommand,
|
||||
submodule: submoduleCommands,
|
||||
GitCommon: gitCommon,
|
||||
submodule: submodule,
|
||||
fileLoader: fileLoader,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user