-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(version): Ability to disable commit hooks on versioning #5640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR!
I've suggested some changes. Even if you don't make them, please add a test case that tests this new functionality so people don't break it inadvertently in the future. :)
src/cli/commands/version.js
Outdated
@@ -130,6 +131,14 @@ export async function setVersion( | |||
return () => Promise.resolve(); | |||
} | |||
|
|||
function buildCommitArgs(args): Array<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think abstracting this into a separate function adds much value unless you use it in a unit test.
src/cli/commands/version.js
Outdated
@@ -130,6 +131,14 @@ export async function setVersion( | |||
return () => Promise.resolve(); | |||
} | |||
|
|||
function buildCommitArgs(args): Array<string> { | |||
args = args || ['commit']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think allowing an empty args value is useful. It adds a new code path to be tested and currently this code path is not even being used. I'd rather us to enforce an array argument through proper flow definitions.
src/cli/commands/version.js
Outdated
@@ -130,6 +131,14 @@ export async function setVersion( | |||
return () => Promise.resolve(); | |||
} | |||
|
|||
function buildCommitArgs(args): Array<string> { | |||
args = args || ['commit']; | |||
if (!flags.commitHooks || !config.getOption('version-commit-hooks')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part would be more useful as a separate function: isCommitHooksDisabled()
. Then you'd use it like as follows:
// create git commit
await spawnGit(['commit', ...(isCommitHooksDisabled() ? ['-n'] : []), '-m', message], {cwd: gitRoot});
d388277
to
c965f30
Compare
@BYK Thanks for the feedback. I've made the requested changes and added test cases. |
7846b8e
to
2ec7d4d
Compare
2ec7d4d
to
633c7fa
Compare
|
||
test('run version and make sure git commit hooks are enabled by default', async (): Promise<void> => { | ||
const fixture = 'no-args'; | ||
await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever :)
await fs.mkdirp(path.join(fixturesLoc, fixture, '.git')); | ||
|
||
return runRun([], {newVersion, gitTagVersion}, fixture, (): ?Promise<void> => { | ||
const gitArgs = ['commit', '-m', 'v2.0.0', '-n']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#protip: since this looks a lot like snapshot testing, you can probably do expect(spawn.mock.calls).toMatchSnapshot('no-hooks-from-config')
and similar in other tests ;)
Summary
Last year I contributed the ability to disable commit hooks when versioning with npm (See this commit). It makes sense to add the same functionality to yarn.
The original motivation for this feature is based on a pre-commit hook that included linting and testing a large code base, taking ~20 seconds to run. When that hook is run on the preceding commits, it's unnecessary and time-taking to do so on versioning. Because of that, it's nice to have the option to disable that git hook.
Test plan
Added lower level integration tests.