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

Don't preserve commit message when it's unchanged from initial message #4110

Merged
merged 3 commits into from
Dec 23, 2024

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

Sometimes we populate the commit message panel with a pre-created commit
message. The two cases where this happens is:

  • you type w to commit, in which case we put the skipHookPrefix in the subject
  • you have a commitPrefix pattern, in which case we match it against the branch
    name and populate the subject with the replacement string if it matches

In either case, if you have a preserved commit message, we use that.

Now, when you use either of these and then cancel, we preserve that initial,
unchanged message and reuse it the next time you commit. This has two problems:
it strips spaces, which is a problem for the commitPrefix patterns, which often
end with a space. And also, when you change your config to experiment with
commitPrefix patterns, the change seemingly doesn't take effect, which can be
very confusing.

To fix both of these problems, only preserve the commit message when it is not
identical to the initial message.

  • 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

@stefanhaller stefanhaller added the bug Something isn't working label Dec 12, 2024
Copy link

codacy-production bot commented Dec 12, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for e29ddf41 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (e29ddf4) Report Missing Report Missing Report Missing
Head commit (3a30211) 51441 44418 86.35%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4110) 23 23 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

- break it to separate lines
- use backticks for pattern so we need less quoting
- don't unnecessarily quote forward slash in pattern
The test shows that we lose a space when cancelling and committing again.
Sometimes we populate the commit message panel with a pre-created commit
message. The two cases where this happens is:
- you type `w` to commit, in which case we put the skipHookPrefix in the subject
- you have a commitPrefix pattern, in which case we match it against the branch
  name and populate the subject with the replacement string if it matches

In either case, if you have a preserved commit message, we use that.

Now, when you use either of these and then cancel, we preserve that initial,
unchanged message and reuse it the next time you commit. This has two problems:
it strips spaces, which is a problem for the commitPrefix patterns, which often
end with a space. And also, when you change your config to experiment with
commitPrefix patterns, the change seemingly doesn't take effect, which can be
very confusing.

To fix both of these problems, only preserve the commit message when it is not
identical to the initial message.
@stefanhaller stefanhaller force-pushed the fix-preserving-commit-message branch from 9704072 to 3a30211 Compare December 23, 2024 11:29
@stefanhaller stefanhaller merged commit ec410b2 into master Dec 23, 2024
15 checks passed
@stefanhaller stefanhaller deleted the fix-preserving-commit-message branch December 23, 2024 11:32
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.

2 participants