Skip to content

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.

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
stefanhaller added a commit that referenced this pull request Mar 9, 2025
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.
stefanhaller added a commit that referenced this pull request Mar 12, 2025
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.
stefanhaller added a commit that referenced this pull request Mar 12, 2025
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.
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