Skip to content

Migrate deprecated AllBranchesLogCmd to AllBranchesLogCmds #4345

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChrisMcD1
Copy link
Contributor

@ChrisMcD1 ChrisMcD1 commented Feb 28, 2025

  • PR Description

Fixes #3961

Their issue where the default allBranchesLogCmd default remains present is because we just do a lo.Uniq(lo.WithoutEmpty()) on the combined list of allBranchesLogCmd and allBranchesLogCmds.

At the point of this code, it is not possible to tell whether the value present in allBranchesLogCmd is user-provided or not. We have already merged the config with the default config, so the user not setting anything, and the user explicitly setting "Yes, I want the default", are indistinguishable.

Based on that bug report, I'm assuming that users that have not set anything for allBranchesLogCmd, but have set something for allBranchesLogCmds, just want the list they have specified in the plural version. Some users have likely figured out they can explicitly set allBranchesLogCmd: "" to get this behavior, but most would not.

To achieve this desired behavior, I figure it is easiest to just migrate all user config to allBranchesLogCmds. If they have explicitly set a non-empty value in allBranchesLogCmd, it will be pulled over. If they set an empty string, it will be excluded.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@ChrisMcD1 ChrisMcD1 marked this pull request as ready for review February 28, 2025 22:31
@ChrisMcD1 ChrisMcD1 force-pushed the 3961-all-branches-log branch from 1ce80ef to aefa6e5 Compare February 28, 2025 22:32
@ChrisMcD1
Copy link
Contributor Author

@stefanhaller Could you give this a look?

Also, is there somewhere I should include a notice of breaking changes on re-write? Last time we did this there were some nix people using immutable config files that ran into issues because they don't let LazyGit do write-back.

@stefanhaller stefanhaller added the bug Something isn't working label Apr 29, 2025
Copy link
Collaborator

@stefanhaller stefanhaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Looks mostly good, just my usual bunch of minor nitpicks below.

And sorry for taking so long to review.


cmdsKeyNode, cmdsValueNode := yaml_utils.LookupKey(gitNode, "allBranchesLogCmds")
if cmdsKeyNode == nil {
// Create dummy node and attach it onto the root git node
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's "dummy" about this? I find this comment more confusing than helpful, and I think we might just delete it.

Comment on lines +373 to +375
if cmdsValueNode.Kind != yaml.SequenceNode {
return fmt.Errorf("You should have an allBranchesLogCmds defined as a sequence!")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it slightly confusing to do this here, where in half of the cases we have just created this ourselves and know it's the right type. I would move this up to an else block after line 370. (Yes, it then runs unnecessarily even when cmdValueNode is empty and there's nothing to migrate, but it doesn't hurt to throw the error in that case too; loading the non-migrated config file would have failed anyway.)

return fmt.Errorf("You should have an allBranchesLogCmds defined as a sequence!")
}
// Prepending the individual element to make it show up first in the list, which was prior behavior
cmdsValueNode.Content = append([]*yaml.Node{{Kind: yaml.ScalarNode, Value: cmdValueNode.Value}}, cmdsValueNode.Content...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have utils.Prepend for this.

Comment on lines +770 to +772
if err != nil {
t.Error(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's assert.NoError for this.

@@ -100,6 +100,19 @@ func lookupKey(node *yaml.Node, key string) (*yaml.Node, *yaml.Node) {
return nil, nil
}

// Returns the key and value if they were present
func RemoveKey(node *yaml.Node, key string) (*yaml.Node, *yaml.Node) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to add a test for this, we have tests for most other things in yaml_utils.

@stefanhaller
Copy link
Collaborator

Also, is there somewhere I should include a notice of breaking changes on re-write? Last time we did this there were some nix people using immutable config files that ran into issues because they don't let LazyGit do write-back.

It would be good if we could do one or both of the suggestions from #4210 (comment). Would you be up for giving that a try? I'll hold off merging this one before next Saturday's release to give us a bit more time for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allBranchesLogCmds always includes default log command
2 participants