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

feat: Support multiple commit prefixes #4261

Conversation

ChrisMcD1
Copy link
Contributor

@ChrisMcD1 ChrisMcD1 commented Feb 14, 2025

  • PR Description
    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

  • 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 mentioned this pull request Feb 14, 2025
7 tasks
@ChrisMcD1 ChrisMcD1 marked this pull request as ready for review February 14, 2025 01:38
Comment on lines -344 to -351
# 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: ""

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

@ChrisMcD1
Copy link
Contributor Author

The failed integration test custom_commands/suggestions_preset seems flaky. I'm unable to reproduce it locally on this branch, but it fails intermittently on a different branch I'm working on. Is that a known issue?

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.

This is really nice, great work. I like the added tests. Just two minor things below.

Comment on lines -344 to -351
# 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: ""

Copy link
Collaborator

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] '
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

@@ -99,14 +99,55 @@ func lookupKey(node *yaml.Node, key string) (*yaml.Node, *yaml.Node) {
return nil, nil
}

func TransformNode(yamlBytes []byte, path []string, transform func(node *yaml.Node) (bool, error)) ([]byte, error) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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!

Copy link
Collaborator

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.

@ChrisMcD1 ChrisMcD1 force-pushed the multiple-commit-prefixes-auto-migrations branch 2 times, most recently from 8ab32f2 to c9d6f2f Compare February 16, 2025 21:24
@stefanhaller stefanhaller force-pushed the multiple-commit-prefixes-auto-migrations branch from c9d6f2f to 1ea96eb Compare February 17, 2025 18:55
@stefanhaller
Copy link
Collaborator

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.
@stefanhaller stefanhaller force-pushed the multiple-commit-prefixes-auto-migrations branch from 1ea96eb to 2fa4ee2 Compare February 17, 2025 18:58
@stefanhaller stefanhaller added the enhancement New feature or request label Feb 17, 2025
@stefanhaller stefanhaller merged commit 0d155e1 into jesseduffield:master Feb 17, 2025
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants