Skip to content

Instantly share code, notes, and snippets.

@paularmstrong
Created November 25, 2010 20:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paularmstrong/715890 to your computer and use it in GitHub Desktop.
Save paularmstrong/715890 to your computer and use it in GitHub Desktop.
Pre-Commit Hook for Git to add the SHA to a file in your working directory.
#!/usr/bin/env node
var child_process = require('child_process'),
fs = require('fs'),
root = __dirname + '/../../',
configFile = root + 'config/config.js',
jslint = require(root + 'lib/jslint/jslint.js');
function setPushVersion() {
child_process.exec('git rev-parse HEAD', { cwd: root }, function (error, stdout, stderr) {
var hash = stdout,
version = hash.slice(0, 7),
data = fs.readFileSync(configFile, 'utf-8'),
position = data.indexOf('push_version: \'') + 15,
fd = fs.openSync(configFile, 'a', 0666);
fs.writeSync(fd, version, position);
child_process.exec('git add ' + configFile, { cwd: root }, function (error, stdout, stderr) {});
console.log('Push version set to ' + version);
});
}
jslint.run(root, function(errors) {
if (errors > 0) {
console.log("\033[31m" + 'DID NOT COMMIT YOUR FILES' + "\033[39m");
process.exit(1);
}
setPushVersion();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment