Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Implement --hook option for git hooks integration (#615)
fixes #448 (re #462) This pr allows project maintainers to enforce Commitizen generated commit messages as part of the workflow triggered by the `git commit` command. * implements the `--hook` flag, which directs Commitizen to edit the `.git/COMMIT_EDITMSG` file directly. * documents the use of the `--hook` flag in the `README`, both through traditional `git hooks` and `husky`.
- Loading branch information
Showing
5 changed files
with
162 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { expect } from 'chai'; | ||
import { parse } from '../../src/cli/parsers/git-cz'; | ||
import { gitCz as gitCzParser, commitizen as commitizenParser } from '../../src/cli/parsers'; | ||
|
||
describe('parsers', () => { | ||
describe('git-cz', () => { | ||
it('should parse --message "Hello, World!"', () => { | ||
expect(parse(['--amend', '--message', 'Hello, World!'])).to.deep.equal(['--amend']); | ||
expect(gitCzParser.parse(['--amend', '--message', 'Hello, World!'])).to.deep.equal(['--amend']); | ||
}); | ||
|
||
it('should parse --message="Hello, World!"', () => { | ||
expect(parse(['--amend', '--message=Hello, World!'])).to.deep.equal(['--amend']); | ||
expect(gitCzParser.parse(['--amend', '--message=Hello, World!'])).to.deep.equal(['--amend']); | ||
}); | ||
|
||
it('should parse -amwip', () => { | ||
expect(parse(['-amwip'])).to.deep.equal(['-a']); | ||
expect(gitCzParser.parse(['-amwip'])).to.deep.equal(['-a']); | ||
}); | ||
|
||
it('should parse -am=wip', () => { | ||
expect(parse(['-am=wip'])).to.deep.equal(['-a']); | ||
expect(gitCzParser.parse(['-am=wip'])).to.deep.equal(['-a']); | ||
}); | ||
|
||
it('should parse -am wip', () => { | ||
expect(parse(['-am', 'wip'])).to.deep.equal(['-a']); | ||
expect(gitCzParser.parse(['-am', 'wip'])).to.deep.equal(['-a']); | ||
}); | ||
|
||
it('should parse -a -m wip -n', () => { | ||
expect(parse(['-a', '-m', 'wip', '-n'])).to.deep.equal(['-a', '-n']); | ||
expect(gitCzParser.parse(['-a', '-m', 'wip', '-n'])).to.deep.equal(['-a', '-n']); | ||
}); | ||
|
||
it('should parse -a -m=wip -n', () => { | ||
expect(parse(['-a', '-m=wip', '-n'])).to.deep.equal(['-a', '-n']); | ||
expect(gitCzParser.parse(['-a', '-m=wip', '-n'])).to.deep.equal(['-a', '-n']); | ||
}); | ||
}); | ||
|
||
describe('commitizen', () => { | ||
it('should parse out the --amend option', () => { | ||
expect(commitizenParser.parse(['--amend'])).to.deep.equal({ _: [], amend: true }) | ||
}); | ||
it('should parse out the --hook option', () => { | ||
expect(commitizenParser.parse(['--hook'])).to.deep.equal({ _: [], hook: true }) | ||
}); | ||
}); | ||
}); |