Created
November 25, 2010 20:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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