Closed joaocunha closed 6 years ago
I'm fairly certain that you could actually use this with the post-rewrite
hook. This is where it gets the commit message file. What changes do you think would be needed to support post-rewrite
?
Squashing commits through rebase will bypass the validation. On the example below, I'll commit twice and rebase to squash them into one single commit:
# some changes...
❯ git add . & git commit -m 'WIP 1'
Commit message validation ignored.
[reb-test 0393464] WIP 1
1 file changed, 2 insertions(+), 1 deletion(-)
# more changes...
❯ git add . & git commit -m 'WIP 2'
Commit message validation ignored.
[reb-test 0393464] WIP 2
1 file changed, 2 insertions(+), 1 deletion(-)
All good up to this point. We have two fine WIP commits, now I'll squash them into one and change the commit message to an invalid format:
❯ git rebase -i master
The editor opens up:
# pick 544b0d3 WIP 1
# squash 7a9db3e WIP 2
# save and close
The editor opens up once again for the new commit message:
# write "invalid commit message"
# save and close
Then I'm presented with:
INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !
invalid commit message
[detached HEAD 7df25ab] invalid commit message
Date: Tue Jul 26 20:55:32 2016 -0300
1 file changed, 3 insertions(+), 2 deletions(-)
INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !
invalid commit message
Successfully rebased and updated refs/heads/reb-test.
As you can see, the validation routine ran twice, but the rebase was actually successful.
Also, it doesn't validate rebases without a post-rewrite
hook (expected behavior).
Adding to that, if I write a valid commit message, it runs only once and works as expected.
Using WIP whatever
as a commit message after squashing to bypass the validation:
❯ git rebase -i master
Commit message validation ignored.
[detached HEAD 3f690b0] WIP whatever
Date: Tue Jul 26 21:10:22 2016 -0300
1 file changed, 3 insertions(+), 5 deletions(-)
Commit message validation ignored.
Successfully rebased and updated refs/heads/another-test.
Using feat(valid): this is valid
as a commit message after squashing to conform with the validation format:
❯ git rebase -i master
[detached HEAD dd1fb04] feat(valid): this is valid
Date: Tue Jul 26 21:10:22 2016 -0300
1 file changed, 3 insertions(+), 5 deletions(-)
Successfully rebased and updated refs/heads/another-test.
Hope this helps, @kentcdodds!
Not certain I understand exactly 100%, but if you know what needs to happen, feel free to makeapullrequest.com :)
@kentcdodds
I have a similar issue. I was trying to rebase like this:
$ git rebase -i HEAD~2
INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !
hook demo
[detached HEAD b4785fe] hook demo
Date: Fri Jul 29 10:34:17 2016 -0400
6 files changed, 97 insertions(+), 15 deletions(-)
create mode 100644 myfolder/easecoverage.js
INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !
hook demo
Successfully rebased and updated refs/heads/hook.
The commit was created without the commit message format. It shown the error, but it is not canceling or rejecting the commit action for rebase (squashing commits)
Thanks
@kentcdodds I have edited my comment so you can better understand what's up: https://github.com/kentcdodds/validate-commit-msg/issues/38#issuecomment-235443884
Yeah, I'm not sure how to solve this issue, but if you come up with something a pull request would be welcome :)
This package has been deprecated. Please use https://github.com/marionebl/commitlint instead.
I'm not entirely sure if it's possible... but a great enhancement would be to also validate on
git rebase -i
.We squash our commits prior to opening a PR, so running
git rebase -i master
will bypass thecommit-msg
validation.From the docs: