Remove the unused AppState field from Common

Nothing reads it. It's a pointer to the AppConfig's in-memory copy of
state.yml, which the following commits replace with fresh reads of the
file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-15 08:10:58 +01:00
1 parent 5a6d5de3b8
commit 90039cf7e2
10 files changed
+16 -21

No files matched your search

+4 -6
View File
@@ -63,17 +63,15 @@ func Run(
func NewCommon(config config.AppConfigurer, log *logrus.Entry) (*common.Common, error) {
userConfig := config.GetUserConfig()
appState := config.GetAppState()
// Initialize with English for the time being; the real translation set for
// the configured language will be read after reading the user config
tr := i18n.EnglishTranslationSet()
cmn := &common.Common{
Log: log,
Tr: tr,
AppState: appState,
Debug: config.GetDebug(),
Fs: afero.NewOsFs(),
Log: log,
Tr: tr,
Debug: config.GetDebug(),
Fs: afero.NewOsFs(),
}
cmn.SetUserConfig(userConfig)
return cmn, nil
+1 -1
View File
@@ -339,7 +339,7 @@ func TestCommitShowCmdObj(t *testing.T) {
repoPaths := RepoPaths{
worktreePath: "/path/to/worktree",
}
instance := buildCommitCommands(commonDeps{userConfig: userConfig, appState: &config.AppState{}, runner: runner, repoPaths: &repoPaths})
instance := buildCommitCommands(commonDeps{userConfig: userConfig, runner: runner, repoPaths: &repoPaths})
assert.NoError(t, instance.ShowCmdObj("1234567890", s.filterPaths, DiffModeRendered).Run())
runner.CheckForMissingCalls()
+1 -2
View File
@@ -14,7 +14,6 @@ import (
type commonDeps struct {
runner *oscommands.FakeCmdObjRunner
userConfig *config.UserConfig
appState *config.AppState
gitVersion *GitVersion
gitConfig *git_config.FakeGitConfig
getenv func(string) string
@@ -32,7 +31,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
gitCommon.Common = deps.common
if gitCommon.Common == nil {
gitCommon.Common = common.NewDummyCommonWithUserConfigAndAppState(deps.userConfig, deps.appState)
gitCommon.Common = common.NewDummyCommonWithUserConfig(deps.userConfig)
}
if deps.fs != nil {
@@ -319,7 +319,7 @@ func TestFileGetStatusFiles(t *testing.T) {
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
loader := &FileLoader{
GitCommon: buildGitCommon(commonDeps{appState: &config.AppState{}, userConfig: userConfig}),
GitCommon: buildGitCommon(commonDeps{userConfig: userConfig}),
cmd: cmd,
config: &FakeFileLoaderConfig{showUntrackedFiles: "yes"},
getFileType: func(string) string { return "file" },
+1 -1
View File
@@ -172,7 +172,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
repoPaths := RepoPaths{
worktreePath: "/path/to/worktree",
}
instance := buildStashCommands(commonDeps{userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths})
instance := buildStashCommands(commonDeps{userConfig: userConfig, repoPaths: &repoPaths})
cmdStr := instance.ShowStashEntryCmdObj(s.index, DiffModeRendered).Args()
assert.Equal(t, s.expected, cmdStr)
@@ -325,7 +325,7 @@ func TestWorkingTreeDiff(t *testing.T) {
worktreePath: "/path/to/worktree",
}
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths})
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, repoPaths: &repoPaths})
result := instance.WorktreeFileDiff(s.file, s.mode, s.cached)
assert.Equal(t, expectedResult, result)
s.runner.CheckForMissingCalls()
@@ -410,7 +410,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
worktreePath: "/path/to/worktree",
}
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths})
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, repoPaths: &repoPaths})
result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, s.fileName, s.previousPath, s.mode)
assert.NoError(t, err)
-1
View File
@@ -14,7 +14,6 @@ type Common struct {
Log *logrus.Entry
Tr *i18n.TranslationSet
userConfig atomic.Pointer[config.UserConfig]
AppState *config.AppState
Debug bool
// for interacting with the filesystem. We use afero rather than the default
// `os` package for the sake of mocking the filesystem in tests
+3 -4
View File
@@ -18,12 +18,11 @@ func NewDummyCommon() *Common {
return cmn
}
func NewDummyCommonWithUserConfigAndAppState(userConfig *config.UserConfig, appState *config.AppState) *Common {
func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *Common {
tr := i18n.EnglishTranslationSet()
cmn := &Common{
Log: utils.NewDummyLog(),
Tr: tr,
AppState: appState,
Log: utils.NewDummyLog(),
Tr: tr,
// TODO: remove dependency on actual filesystem in tests and switch to using
// in-memory for everything
Fs: afero.NewOsFs(),
+1 -1
View File
@@ -169,7 +169,7 @@ func TestFileTreeSortOrderConfig(t *testing.T) {
userConfig.Gui.ShowRootItemInFileTree = false
userConfig.Gui.FileTreeSortOrder = s.sortOrder
userConfig.Gui.FileTreeSortCaseSensitive = s.caseSensitive
cmn := common.NewDummyCommonWithUserConfigAndAppState(userConfig, nil)
cmn := common.NewDummyCommonWithUserConfig(userConfig)
tree := NewFileTree(func() []*models.File { return files }, cmn, true)
tree.SetTree()
@@ -55,7 +55,7 @@ func TestSetTreeSelectsNewFileWhenSelectedRenameSplits(t *testing.T) {
t.Run(s.name, func(t *testing.T) {
userConfig := config.GetDefaultConfig()
userConfig.Gui.ShowRootItemInFileTree = s.showRootItem
cmn := common.NewDummyCommonWithUserConfigAndAppState(userConfig, nil)
cmn := common.NewDummyCommonWithUserConfig(userConfig)
files := []*models.File{
{Path: "dir/new.go", PreviousPath: "dir/old.go"},
@@ -102,7 +102,7 @@ func TestSetTreeFollowsRenameIntoCollapsedDir(t *testing.T) {
t.Run(s.name, func(t *testing.T) {
userConfig := config.GetDefaultConfig()
userConfig.Gui.ShowRootItemInFileTree = s.showRootItem
cmn := common.NewDummyCommonWithUserConfigAndAppState(userConfig, nil)
cmn := common.NewDummyCommonWithUserConfig(userConfig)
files := []*models.File{
{Path: "a/b.go"},