Skip to content

Conversation

@claytonrcarter
Copy link
Collaborator

As discussed in discord, this trims ending newlines from commit messages when they are compared with message(). In particular, this provides for more intuitive (to me) usage of message(exact:...) and message(regex:...) because I feel that most folks would assume that the commit message would not include the trailing newline anyway. This is a 1 line change and includes supporting tests.

Behavior without this change (on master):

❯ git commit -am 'My commit'
❯ git query 'message(exact:My commit)'
# nothing found
❯ git query 'message(regex:My commit$)'
# nothing found
❯ git query 'message(exact:My commit\n)'
abc123 My commit
❯ git query 'message(regex:My commit\n$)'
abc123 My commit

With this change:

❯ git commit -am 'My commit'
❯ git query 'message(exact:My commit)'
abc123 My commit
❯ git query 'message(regex:My commit$)'
abc123 My commit

Notes

  • This only trims the subject (commit message), not the pattern. With this change exact:My commit\n will not work b/c the pattern will include the newline but the commit message won't. Trying to alter the pattern seemed like a can of worms, and I think that stripping just the message will make most usages more intuitive.
  • I'm only stripping newlines from the end of the string. I considered trimming all whitespace but that felt unnecessary since git does that to commit messages already, and this just targets something that git adds on it's own.
  • I have not done anything to consider line endings on Windows. Can you remind me if there's anything special I should be doing for those?

Thank you!

Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

Git ensures that all commit messages end with a newline, even if one is not
supplied. If these are not ignored, then the user will have to explicitly
include them in order for some text patterns to succeed. For example, a
commit with message `foo` would not match `message(exact:foo)` but would
match `message(exact:foo\n)`. Similarly, `message(regex:foo$)` would not
match, but `message(regex:foo\n$)` would. This change allows for more
intuitive usage, making the '\n' unnessecary.
@claytonrcarter claytonrcarter force-pushed the revset-message-newline branch from 7232f87 to 7fa0766 Compare August 23, 2022 08:44
@claytonrcarter claytonrcarter enabled auto-merge (rebase) August 23, 2022 08:44
@claytonrcarter claytonrcarter merged commit 060a706 into master Aug 23, 2022
@claytonrcarter claytonrcarter deleted the revset-message-newline branch August 23, 2022 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants