1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
package commands
import (
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type commonDeps struct {
runner *oscommands.FakeCmdObjRunner
userConfig *config.UserConfig
gitConfig *git_config.FakeGitConfig
getenv func(string) string
removeFile func(string) error
dotGitDir string
common *common.Common
cmd *oscommands.CmdObjBuilder
}
func completeDeps(deps commonDeps) commonDeps {
if deps.runner == nil {
deps.runner = oscommands.NewFakeRunner(nil)
}
if deps.userConfig == nil {
deps.userConfig = config.GetDefaultConfig()
}
if deps.gitConfig == nil {
deps.gitConfig = git_config.NewFakeGitConfig(nil)
}
if deps.getenv == nil {
deps.getenv = func(string) string { return "" }
}
if deps.removeFile == nil {
deps.removeFile = func(string) error { return errors.New("unexpected call to removeFile") }
}
if deps.dotGitDir == "" {
deps.dotGitDir = ".git"
}
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)
return NewConfigCommands(common, deps.gitConfig)
}
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,
})
}
func buildFileLoader(deps commonDeps) *loaders.FileLoader {
deps = completeDeps(deps)
configCommands := buildConfigCommands(deps)
return loaders.NewFileLoader(deps.common, deps.cmd, configCommands)
}
func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands {
deps = completeDeps(deps)
return NewSubmoduleCommands(deps.common, deps.cmd, deps.dotGitDir)
}
func buildCommitCommands(deps commonDeps) *CommitCommands {
deps = completeDeps(deps)
return NewCommitCommands(deps.common, deps.cmd)
}
func buildWorkingTreeCommands(deps commonDeps) *WorkingTreeCommands {
deps = completeDeps(deps)
osCommand := buildOSCommand(deps)
submoduleCommands := buildSubmoduleCommands(deps)
fileLoader := buildFileLoader(deps)
return NewWorkingTreeCommands(deps.common, deps.cmd, submoduleCommands, osCommand, fileLoader)
}
func buildStashCommands(deps commonDeps) *StashCommands {
deps = completeDeps(deps)
osCommand := buildOSCommand(deps)
fileLoader := buildFileLoader(deps)
workingTreeCommands := buildWorkingTreeCommands(deps)
return NewStashCommands(deps.common, deps.cmd, osCommand, fileLoader, workingTreeCommands)
}
func buildRebaseCommands(deps commonDeps) *RebaseCommands {
deps = completeDeps(deps)
configCommands := buildConfigCommands(deps)
osCommand := buildOSCommand(deps)
workingTreeCommands := buildWorkingTreeCommands(deps)
commitCommands := buildCommitCommands(deps)
return NewRebaseCommands(deps.common, deps.cmd, osCommand, commitCommands, workingTreeCommands, configCommands, deps.dotGitDir)
}
func buildSyncCommands(deps commonDeps) *SyncCommands {
deps = completeDeps(deps)
return NewSyncCommands(deps.common, deps.cmd)
}
func buildFileCommands(deps commonDeps) *FileCommands {
deps = completeDeps(deps)
configCommands := buildConfigCommands(deps)
osCommand := buildOSCommand(deps)
return NewFileCommands(deps.common, deps.cmd, configCommands, osCommand)
}
|