-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Support multiple commit prefixes #4261
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
feat: Support multiple commit prefixes #4261
Conversation
| # See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
| commitPrefix: | ||
| # pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*" | ||
| pattern: "" | ||
|
|
||
| # Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] " | ||
| replace: "" | ||
|
|
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.
Once again, go generate removed this. I guess it just doesn't support sequences?
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.
Yes, that's true. The config doc is generated from the default values specified in the schema, and arrays don't have the concept of a default value.
It's actually a good thing that this is removed from the docs. We had several cases of people copying the entire defaults section from the docs to their config file, and then it doesn't work as expected; see here for more information.
|
The failed integration test |
stefanhaller
left a comment
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.
This is really nice, great work. I like the added tests. Just two minor things below.
| # See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
| commitPrefix: | ||
| # pattern to match on. E.g. for 'feature/AB-123' to match on the AB-123 use "^\\w+\\/(\\w+-\\w+).*" | ||
| pattern: "" | ||
|
|
||
| # Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] " | ||
| replace: "" | ||
|
|
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.
Yes, that's true. The config doc is generated from the default values specified in the schema, and arrays don't have the concept of a default value.
It's actually a good thing that this is removed from the docs. We had several cases of people copying the entire defaults section from the docs to their config file, and then it doesn't work as expected; see here for more information.
| pattern: "^\\w+\\/(\\w+-\\w+).*" | ||
| replace: '[$1] ' | ||
| - pattern: "^\\w+\\/(\\w+-\\w+).*" | ||
| replace: '[$1] ' |
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.
It would be good to have an example with multiple entries here (like you have for commitPrefixes below), and maybe say explicitly that they are tried in order, first match wins.
The reason why I prefer to have this here rather than below is that I'd like to deprecate (and eventually remove) commitPrefixes; now that we have repo-local config files, it's no longer needed.
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.
Added an example with multiple prefixes!
I left the example down below as well, want me to remove?
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.
No, it's fine to keep them. We'll remove that section at some point anyway.
| return nil, nil | ||
| } | ||
|
|
||
| func TransformNode(yamlBytes []byte, path []string, transform func(node *yaml.Node) (bool, error)) ([]byte, error) { |
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.
Some brief documentation would be nice; e.g. what the path parameter means, and what the bool return value of the callback means.
Would it maybe be useful to add a test with some simple transformation like converting int values to string values to illustrate the usage?
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.
Added some docs, and a test. The test didn't end up being as simple as I would like because of the complexity of expressing the conversion of int values to string, but it is a test!
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.
Very nice. I pushed a fixup (1ea96eb) to address a linter error; yaml.Node.Value is a string no matter whether the type is int or str, so it's unnecessary to sprintf it again.
8ab32f2 to
c9d6f2f
Compare
c9d6f2f to
1ea96eb
Compare
|
Cool, happy with this now. I had to push one more fixup (d81cf52) to remove some trailing whitespace that triggered my OCD. 😄 Merging. |
This implementation, unlike that proposed in jesseduffield#4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
1ea96eb to
2fa4ee2
Compare
Before we changed the commitPrefix config to a list in #4261, we had this bug where the defaults section in Config.md would erroneously list the default for commitPrefix as git: commitPrefix: pattern: "" replace: "" This was not correct, commitPrefix was a pointer, and the default for that was nil, which is not the same. Now, some people copied and pasted the entire defaults section into their config files, setting the commitPrefix to an empty pattern (which is not the same as not setting it at all). And this caused the branch name to be filled in to the subject field for every commit; see for example #3632. New users copying the defaults section into their config file in the current version no longer have this problem because now that commitPrefix is a list, it is no longer included in the defaults section. However, the migration that we added in #4261 would happily carry over those empty strings into a list entry, so people migrating from an older version still have the broken config in their config files. To work around the issue, ignore commit prefix settings whose pattern is an empty string. I can't imagine a valid reason why people would actually want to set the pattern to an empty string, so I assume this only comes from the broken defaults problem described above.
Before we changed the commitPrefix config to a list in #4261, we had this bug where the defaults section in Config.md would erroneously list the default for commitPrefix as git: commitPrefix: pattern: "" replace: "" This was not correct, commitPrefix was a pointer, and the default for that was nil, which is not the same. Now, some people copied and pasted the entire defaults section into their config files, setting the commitPrefix to an empty pattern (which is not the same as not setting it at all). And this caused the branch name to be filled in to the subject field for every commit; see for example #3632. New users copying the defaults section into their config file in the current version no longer have this problem because now that commitPrefix is a list, it is no longer included in the defaults section. However, the migration that we added in #4261 would happily carry over those empty strings into a list entry, so people migrating from an older version still have the broken config in their config files. To work around the issue, ignore commit prefix settings whose pattern is an empty string. I can't imagine a valid reason why people would actually want to set the pattern to an empty string, so I assume this only comes from the broken defaults problem described above.
Before we changed the commitPrefix config to a list in #4261, we had this bug where the defaults section in `Config.md` would erroneously list the default for commitPrefix as ```yml git: commitPrefix: pattern: "" replace: "" ``` This was not correct, commitPrefix was a pointer, and the default for that was nil, which is not the same. Now, some people copied and pasted the entire defaults section into their config files, setting the commitPrefix to an empty pattern (which is not the same as not setting it at all). And this caused the branch name to be filled in to the subject field for every commit; see for example #3632. New users copying the defaults section into their config file in the current version no longer have this problem because now that commitPrefix is a list, it is no longer included in the defaults section. However, the migration that we added in #4261 would happily carry over those empty strings into a list entry, so people migrating from an older version still have the broken config in their config files. To work around the issue, ignore commit prefix settings whose pattern is an empty string. I can't imagine a valid reason why people would actually want to set the pattern to an empty string, so I assume this only comes from the broken defaults problem described above.
This implementation, unlike that proposed in Allow multiple commit prefixes #4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
Addresses #4194
go generate ./...)