Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created December 18, 2015 08:56
Show Gist options
  • Save yurenju/f0615da030d18dfdbe3b to your computer and use it in GitHub Desktop.
Save yurenju/f0615da030d18dfdbe3b to your computer and use it in GitHub Desktop.
prepare-commit-msg
#!/usr/bin/env node
/**
* This git hook requires shelljs, please use |npm install shelljs --save-dev|
* to install it.
*/
require('shelljs/global');
var issueNum;
var msg;
var file = process.argv[2];
var branch = exec('git rev-parse --abbrev-ref HEAD').output;
var matched = branch.match(/-*(\d+)-*/);
var type = process.argv[3];
if (type) return exit(0);
// comment message for git status
var status = exec('git status').output.split('\n')
.map(function(line) { return '# ' + line; })
.join('\n');
if (matched) {
issueNum = matched[1];
msg = 'Fixed #' + issueNum + ': \n\n' + status;
msg.to(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment