-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: master
Are you sure you want to change the base?
Conversation
1ce80ef
to
aefa6e5
Compare
aefa6e5
to
f0c591e
Compare
@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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
if cmdsValueNode.Kind != yaml.SequenceNode { | ||
return fmt.Errorf("You should have an allBranchesLogCmds defined as a sequence!") | ||
} |
There was a problem hiding this comment.
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...) |
There was a problem hiding this comment.
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.
if err != nil { | ||
t.Error(err) | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
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. |
Fixes #3961
Their issue where the default
allBranchesLogCmd
default remains present is because we just do alo.Uniq(lo.WithoutEmpty())
on the combined list ofallBranchesLogCmd
andallBranchesLogCmds
.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 forallBranchesLogCmds
, just want the list they have specified in the plural version. Some users have likely figured out they can explicitly setallBranchesLogCmd: ""
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 inallBranchesLogCmd
, it will be pulled over. If they set an empty string, it will be excluded.go generate ./...
)