Skip to content
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

Merged
merged 2 commits into from
Apr 13, 2018

Conversation

faazshift
Copy link
Contributor

@faazshift faazshift commented Apr 10, 2018

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.

Copy link
Member

@BYK BYK left a 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. :)

@@ -130,6 +131,14 @@ export async function setVersion(
return () => Promise.resolve();
}

function buildCommitArgs(args): Array<string> {
Copy link
Member

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.

@@ -130,6 +131,14 @@ export async function setVersion(
return () => Promise.resolve();
}

function buildCommitArgs(args): Array<string> {
args = args || ['commit'];
Copy link
Member

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.

@@ -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')) {
Copy link
Member

@BYK BYK Apr 12, 2018

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});

@faazshift
Copy link
Contributor Author

@BYK Thanks for the feedback. I've made the requested changes and added test cases.

@faazshift faazshift force-pushed the commit-hook-control branch 3 times, most recently from 7846b8e to 2ec7d4d Compare April 13, 2018 00:38

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'));
Copy link
Member

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'];
Copy link
Member

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 ;)

@BYK BYK changed the title Ability to disable commit hooks on versioning feat(version): Ability to disable commit hooks on versioning Apr 13, 2018
@BYK BYK merged commit 75723f2 into yarnpkg:master Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants