From 90039cf7e2a0c1a331eb85c4da45233329162c75 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 2 Nov 2026 19:56:18 +0100 Subject: [PATCH] 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 --- pkg/app/app.go | 10 ++++------ pkg/commands/git_commands/commit_test.go | 2 +- pkg/commands/git_commands/deps_test.go | 3 +-- pkg/commands/git_commands/file_loader_test.go | 2 +- pkg/commands/git_commands/stash_test.go | 2 +- pkg/commands/git_commands/working_tree_test.go | 4 ++-- pkg/common/common.go | 1 - pkg/common/dummies.go | 7 +++---- pkg/gui/filetree/file_tree_test.go | 2 +- pkg/gui/filetree/file_tree_view_model_test.go | 4 ++-- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 11f50c8b5..38558aeb8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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 diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index fe3b227c5..81f6e1d8f 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -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() diff --git a/pkg/commands/git_commands/deps_test.go b/pkg/commands/git_commands/deps_test.go index 91332cff6..b378df47d 100644 --- a/pkg/commands/git_commands/deps_test.go +++ b/pkg/commands/git_commands/deps_test.go @@ -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 { diff --git a/pkg/commands/git_commands/file_loader_test.go b/pkg/commands/git_commands/file_loader_test.go index 755923da7..d7fd465c0 100644 --- a/pkg/commands/git_commands/file_loader_test.go +++ b/pkg/commands/git_commands/file_loader_test.go @@ -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" }, diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index ddedffd00..b0062e4fd 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -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) diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index 520e57121..6792d0778 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -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) diff --git a/pkg/common/common.go b/pkg/common/common.go index 837af7bea..72b162d88 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -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 diff --git a/pkg/common/dummies.go b/pkg/common/dummies.go index c689bca09..9808bdd8b 100644 --- a/pkg/common/dummies.go +++ b/pkg/common/dummies.go @@ -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(), diff --git a/pkg/gui/filetree/file_tree_test.go b/pkg/gui/filetree/file_tree_test.go index 3058e8db9..31d2b45c0 100644 --- a/pkg/gui/filetree/file_tree_test.go +++ b/pkg/gui/filetree/file_tree_test.go @@ -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() diff --git a/pkg/gui/filetree/file_tree_view_model_test.go b/pkg/gui/filetree/file_tree_view_model_test.go index 088b2b859..bccc755f9 100644 --- a/pkg/gui/filetree/file_tree_view_model_test.go +++ b/pkg/gui/filetree/file_tree_view_model_test.go @@ -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"},