Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate git.log.showGraph and git.log.order to app state #3197

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ git:
# one of date-order, author-date-order, topo-order or default.
# topo-order makes it easier to read the git log graph, but commits may not
# appear chronologically. See https://git-scm.com/docs/git-log#_commit_ordering
#
# Deprecated: Configure this with `Log menu -> Commit sort order` (<c-l> in the commits window by default).
order: 'topo-order'
# one of always, never, when-maximised
# this determines whether the git graph is rendered in the commits panel
#
# Deprecated: Configure this with `Log menu -> Show git graph` (<c-l> in the commits window by default).
showGraph: 'always'
# displays the whole git graph by default in the commits panel (equivalent to passing the `--all` argument to `git log`)
showWholeGraph: false
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/commit_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {

// getLog gets the git log.
func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
config := self.UserConfig.Git.Log
gitLogOrder := self.AppState.GitLogOrder

refSpec := opts.RefName
if opts.RefToShowDivergenceFrom != "" {
Expand All @@ -659,7 +659,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {

cmdArgs := NewGitCmd("log").
Arg(refSpec).
ArgIf(config.Order != "default", "--"+config.Order).
ArgIf(gitLogOrder != "default", "--"+gitLogOrder).
ArgIf(opts.All, "--all").
Arg("--oneline").
Arg(prettyFormat).
Expand Down
4 changes: 3 additions & 1 deletion pkg/commands/git_commands/commit_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -305,7 +306,8 @@ func TestGetCommits(t *testing.T) {
scenario := scenario
t.Run(scenario.testName, func(t *testing.T) {
common := utils.NewDummyCommon()
common.UserConfig.Git.Log.Order = scenario.logOrder
common.AppState = &config.AppState{}
common.AppState.GitLogOrder = scenario.logOrder

builder := &CommitLoader{
Common: common,
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ func NewAppConfig(
return nil, err
}

// Temporary: the defaults for these are set to empty strings in
// getDefaultAppState so that we can migrate them from userConfig (which is
// now deprecated). Once we remove the user configs, we can remove this code
// and set the proper defaults in getDefaultAppState.
if appState.GitLogOrder == "" {
appState.GitLogOrder = userConfig.Git.Log.Order
}
if appState.GitLogShowGraph == "" {
appState.GitLogShowGraph = userConfig.Git.Log.ShowGraph
}

appConfig := &AppConfig{
Name: name,
Version: version,
Expand Down Expand Up @@ -325,6 +336,15 @@ type AppState struct {
DiffContextSize int
LocalBranchSortOrder string
RemoteBranchSortOrder string

// One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'
// 'topo-order' makes it easier to read the git log graph, but commits may not
// appear chronologically. See https://git-scm.com/docs/
GitLogOrder string

// This determines whether the git graph is rendered in the commits panel
// One of 'always' | 'never' | 'when-maximised'
GitLogShowGraph string
}

func getDefaultAppState() *AppState {
Expand All @@ -335,6 +355,8 @@ func getDefaultAppState() *AppState {
DiffContextSize: 3,
LocalBranchSortOrder: "recency",
RemoteBranchSortOrder: "alphabetical",
GitLogOrder: "", // should be "topo-order" eventually
GitLogShowGraph: "", // should be "always" eventually
hosaka marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,17 @@ type MergingConfig struct {
}

type LogConfig struct {
// One of: 'date-order' | 'author-date-order' | 'topo-order | default'
// One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'
// 'topo-order' makes it easier to read the git log graph, but commits may not
// appear chronologically. See https://git-scm.com/docs/
Order string `yaml:"order" jsonschema:"enum=date-order,enum=author-date-order,enum=topo-order,enum=default"`
//
// Deprecated: Configure this with `Log menu -> Commit sort order` (<c-l> in the commits window by default).
Order string `yaml:"order" jsonschema:"deprecated,enum=date-order,enum=author-date-order,enum=topo-order,enum=default,deprecated"`
// This determines whether the git graph is rendered in the commits panel
// One of 'always' | 'never' | 'when-maximised'
ShowGraph string `yaml:"showGraph" jsonschema:"enum=always,enum=never,enum=when-maximised"`
//
// Deprecated: Configure this with `Log menu -> Show git graph` (<c-l> in the commits window by default).
ShowGraph string `yaml:"showGraph" jsonschema:"deprecated,enum=always,enum=never,enum=when-maximised"`
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
ShowWholeGraph bool `yaml:"showWholeGraph"`
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/gui/context/local_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func shouldShowGraph(c *ContextCommon) bool {
return false
}

value := c.UserConfig.Git.Log.ShowGraph
value := c.GetAppState().GitLogShowGraph

switch value {
case "always":
return true
Expand Down
11 changes: 8 additions & 3 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,12 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
OnPress: func() error {
onPress := func(value string) func() error {
return func() error {
self.c.UserConfig.Git.Log.ShowGraph = value
return nil
self.c.GetAppState().GitLogShowGraph = value
self.c.SaveAppStateAndLogError()
if err := self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits); err != nil {
return err
}
return self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
}
}
return self.c.Menu(types.CreateMenuOptions{
Expand Down Expand Up @@ -957,7 +961,8 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
OnPress: func() error {
onPress := func(value string) func() error {
return func() error {
self.c.UserConfig.Git.Log.Order = value
self.c.GetAppState().GitLogOrder = value
self.c.SaveAppStateAndLogError()
return self.c.WithWaitingStatus(self.c.Tr.LoadingCommits, func(gocui.Task) error {
return self.c.Refresh(
types.RefreshOptions{
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/bisect/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
CreateNCommits(10)
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.Git.Log.ShowGraph = "never"
cfg.AppState.GitLogShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
markCommitAsBad := func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/bisect/choose_terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var ChooseTerms = NewIntegrationTest(NewIntegrationTestArgs{
CreateNCommits(10)
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.Git.Log.ShowGraph = "never"
cfg.AppState.GitLogShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
markCommitAsFixed := func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/bisect/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Skip = NewIntegrationTest(NewIntegrationTestArgs{
CreateNCommits(10)
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.Git.Log.ShowGraph = "never"
cfg.AppState.GitLogShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/commit/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Highlight = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.Log.ShowGraph = "always"
config.AppState.GitLogShowGraph = "always"
config.GetUserConfig().Gui.AuthorColors = map[string]string{
"CI": "red",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var DropTodoCommitWithUpdateRef = NewIntegrationTest(NewIntegrationTestArgs{
GitVersion: AtLeast("2.38.0"),
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.MainBranches = []string{"master"}
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var QuickStartKeepSelection = NewIntegrationTest(NewIntegrationTestArgs{
GitVersion: AtLeast("2.38.0"),
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.MainBranches = []string{"master"}
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var QuickStartKeepSelectionRange = NewIntegrationTest(NewIntegrationTestArgs{
GitVersion: AtLeast("2.38.0"),
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.MainBranches = []string{"master"}
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var ViewFilesOfTodoEntries = NewIntegrationTest(NewIntegrationTestArgs{
Skip: false,
GitVersion: AtLeast("2.38.0"),
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var DoNotShowBranchMarkersInReflogSubcommits = NewIntegrationTest(NewIntegration
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.Log.ShowGraph = "never"
config.AppState.GitLogShowGraph = "never"
},
SetupRepo: func(shell *Shell) {
shell.NewBranch("branch1")
Expand Down
4 changes: 2 additions & 2 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
"topo-order",
"default"
],
"description": "One of: 'date-order' | 'author-date-order' | 'topo-order | default'\n'topo-order' makes it easier to read the git log graph, but commits may not\nappear chronologically. See https://git-scm.com/docs/",
"description": "One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'\n'topo-order' makes it easier to read the git log graph, but commits may not\nappear chronologically. See https://git-scm.com/docs/\n\nDeprecated: Configure this with `Log menu -\u003e Commit sort order` (\u003cc-l\u003e in the commits window by default).",
"default": "topo-order"
},
"showGraph": {
Expand All @@ -529,7 +529,7 @@
"never",
"when-maximised"
],
"description": "This determines whether the git graph is rendered in the commits panel\nOne of 'always' | 'never' | 'when-maximised'",
"description": "This determines whether the git graph is rendered in the commits panel\nOne of 'always' | 'never' | 'when-maximised'\n\nDeprecated: Configure this with `Log menu -\u003e Show git graph` (\u003cc-l\u003e in the commits window by default).",
"default": "always"
},
"showWholeGraph": {
Expand Down
Loading