I’m using the pygrep in pre-commit
and here is my settings:
JavaScript
x
9
1
- repo: local
2
hooks:
3
- id: jira-ticket
4
name: check for jira ticket
5
entry: '(ERP-[0-9]+ #(feat|fix|docs|style|refactor|perf|test|chore) .+)'
6
args: [--multiline]
7
language: pygrep
8
stages: [commit-msg]
9
I want to check the commit message format but no mater what I entered, it always returns true.
JavaScript
1
12
12
1
$ git commit -m "why"
2
[WARNING] Unstaged files detected.
3
[INFO] Stashing unstaged files to C:Usersoliver.chiu.cachepre-commitpatch1657183664-20160.
4
[INFO] Restored changes from C:Usersoliver.chiu.cachepre-commitpatch1657183664-20160.
5
[WARNING] Unstaged files detected.
6
[INFO] Stashing unstaged files to C:Usersoliver.chiu.cachepre-commitpatch1657183666-11436.
7
check for jira ticket .Passed
8
[INFO] Restored changes from C:Usersoliver.chiu.cachepre-commitpatch1657183666-11436.
9
[purchase_merge_ui dc8bafc9] why
10
1 file changed, 1 deletion(-)
11
12
Advertisement
Answer
you also commented on github! pick one in the future not both!
your regex doesn’t follow the pattern I outlined in that issue you commented on — here is the example I used:
JavaScript
1
10
10
1
repos:
2
- repo: local
3
hooks:
4
- id: jira-ticket
5
name: check for jira ticket
6
language: pygrep
7
entry: 'A(?![A-Z]+-[0-9]+)'
8
args: [--multiline]
9
stages: [commit-msg]
10
note that we’re using a negative lookahead — by default pygrep
is used to find problems with things and you’re trying to do the opposite
right now your current pattern will only fail on correctly named things rather than only allow correctly named things
adapting your pattern to the one I outlined in the issue you’d want something like:
JavaScript
1
2
1
entry: 'A(?!ERP-[0-9]+ #(feat|fix|docs|style|refactor|perf|test|chore) .+)'
2
disclaimer: I created pre-commit