sds / overcommit

A fully configurable and extendable Git hook manager
MIT License
3.92k stars 281 forks source link

PrepareCommitMsg ReplaceBranch: No possibility to insert whitespace between new_template and old_content #761

Closed michalstanczyk closed 2 years ago

michalstanczyk commented 3 years ago

It's not possible to define template with whitespace between ticket number and commit message.

Example config:

PrepareCommitMsg:
  ReplaceBranch:
    enabled: true
    description: 'Prepends the commit message with text based on the branch name'
    branch_pattern: '(.*?)(?<ticket>[A-Z][A-Z0-9]+-[0-9]+)(.*)'
    replacement_text: '\k<ticket> '
    skipped_commit_types:
      - 'merge'    # if merging
      - 'squash'   # if squashing
    on_fail: fail

Steps to reproduce:

on branch JIRA-1-new-feature git commit -m "New commit"

Actual result:

JIRA-1New Commit

Expected result:

JIRA-1 New Commit

Additional info:

Here is strip for new template: https://github.com/sds/overcommit/blob/8622f9e83fcd2b1e1bc1d19494d4c25843dbea5c/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb#L56

And here there is no space between variables: https://github.com/sds/overcommit/blob/8622f9e83fcd2b1e1bc1d19494d4c25843dbea5c/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb#L46