diff --git a/src/adapters/base.ts b/src/adapters/base.ts index 5873fce9..65a7df17 100644 --- a/src/adapters/base.ts +++ b/src/adapters/base.ts @@ -25,9 +25,9 @@ interface IRepoAdapter { resetRepoBeforeApply(repo: IRepo, force: boolean): Promise; - commitRepo(repo: IRepo): Promise; + commitRepo(repo: IRepo, noVerify: boolean): Promise; - pushRepo(repo: IRepo, force: boolean): Promise; + pushRepo(repo: IRepo, force: boolean, noVerify:boolean): Promise; createPullRequest(repo: IRepo, message: string): Promise; diff --git a/src/adapters/git.ts b/src/adapters/git.ts index cce2043e..dbfd39c3 100644 --- a/src/adapters/git.ts +++ b/src/adapters/git.ts @@ -55,12 +55,13 @@ abstract class GitAdapter implements IRepoAdapter { } } - public async commitRepo(repo: IRepo): Promise { + public async commitRepo(repo: IRepo, noVerify:boolean): Promise { const { migration: { spec }, } = this.migrationContext; + const options = noVerify ? ['--no-verify'] : undefined; await this.git(repo).add('.'); - await this.git(repo).commit(`${spec.title} [shepherd]`); + await this.git(repo).commit(`${spec.title} [shepherd]`, options); } public async resetChangedFiles(repo: IRepo): Promise { @@ -68,9 +69,10 @@ abstract class GitAdapter implements IRepoAdapter { await this.git(repo).clean('f', ['-d']); } - public async pushRepo(repo: IRepo, force: boolean): Promise { - const options = force ? ['--force'] : undefined; - + public async pushRepo(repo: IRepo, force: boolean, noVerify: boolean): Promise { + const options = [] + if (force) { options.push('--force') } + if (noVerify) { options.push('--no-verify') } await this.git(repo).push('origin', 'HEAD', options); } diff --git a/src/adapters/github.ts b/src/adapters/github.ts index ba1c86a3..c1e7fd64 100644 --- a/src/adapters/github.ts +++ b/src/adapters/github.ts @@ -106,7 +106,7 @@ class GithubAdapter extends GitAdapter { await this.git(repo).reset(['--hard', `origin/${defaultBranch}`]); } - public async pushRepo(repo: IRepo, force: boolean): Promise { + public async pushRepo(repo: IRepo, force: boolean, noVerify: boolean): Promise { let shouldForce = false; // First, get any changes from the remote @@ -127,7 +127,7 @@ class GithubAdapter extends GitAdapter { shouldForce = true; } - await super.pushRepo(repo, force || shouldForce); + await super.pushRepo(repo, force || shouldForce, noVerify); } public async createPullRequest(repo: IRepo, message: string): Promise { diff --git a/src/cli.ts b/src/cli.ts index 4939bb13..086695ff 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -120,11 +120,16 @@ applyCommand.option( ); applyCommand.action(handleCommand(apply)); -addCommand('commit', 'Commit all changes for the specified migration', true, commit); +const commitCommand = buildCommand('commit', 'Commit all changes for the specified migration'); +addReposOption(commitCommand) +commitCommand.option('-n, --no-verify', 'Skips pre-commit hooks'); +commitCommand.action(handleCommand(commit)); + addCommand('reset', 'Reset all changes for the specified migration', true, reset); const pushCommand = buildCommand('push', 'Push all changes for the specified migration'); addReposOption(pushCommand); +pushCommand.option('-n, --no-verify', 'Skips pre-push hooks'); pushCommand.option('-f, --force', 'Force push, skipping any safety checks'); pushCommand.action(handleCommand(push)); diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 4da3bbd6..a406e29f 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -1,13 +1,14 @@ import { IMigrationContext } from '../migration-context'; import forEachRepo from '../util/for-each-repo'; -export default async (context: IMigrationContext) => { +export default async (context: IMigrationContext, options: any) => { const { adapter, logger } = context; await forEachRepo(context, async (repo) => { const spinner = logger.spinner('Committing changes'); try { - await adapter.commitRepo(repo); + await adapter.commitRepo(repo, options.noVerify); + spinner.succeed('Changes committed'); } catch (e) { logger.error(e); diff --git a/src/commands/push.ts b/src/commands/push.ts index 996fc6e9..5e303943 100644 --- a/src/commands/push.ts +++ b/src/commands/push.ts @@ -7,7 +7,7 @@ export default async (context: IMigrationContext, options: any) => { await forEachRepo(context, async (repo) => { const spinner = logger.spinner('Pushing changes'); try { - await adapter.pushRepo(repo, options.force); + await adapter.pushRepo(repo, options.force, options.noVerify); spinner.succeed('Changes pushed'); } catch (e) { logger.error(e);