Skip to content

Instantly share code, notes, and snippets.

@jgornick
Created August 17, 2018 21:07
Show Gist options
  • Save jgornick/79a4d9334d914058ce0a9146b2a1d21f to your computer and use it in GitHub Desktop.
Save jgornick/79a4d9334d914058ce0a9146b2a1d21f to your computer and use it in GitHub Desktop.
git: Pre-push confirmation
#!/usr/bin/env node
const split = require('lodash/split');
const includes = require('lodash/includes');
const Confirm = require('prompt-confirm');
void async function() {
console.log(`HUSKY_GIT_PARAMS=${process.env.HUSKY_GIT_PARAMS}`)
console.log(`HUSKY_GIT_STDIN=${process.env.HUSKY_GIT_STDIN}`)
const [ remote, repositoryUri ] = split(process.env.HUSKY_GIT_PARAMS, ' ');
const [ localRef, localSha1, remoteRef, remoteSha1 ] = split(process.env.HUSKY_GIT_STDIN, ' ');
if (localRef === '') {
process.exit(0);
}
if (includes(remoteRef, 'feature/webui/')) {
const prompt = new Confirm(`Are you sure you want to push to ${remoteRef}?`);
const result = await prompt.run();
if (result === false) {
process.exit(1);
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment