Last active
October 13, 2015 09:13
-
-
Save harry1989/2eb259d250b688cf17a9 to your computer and use it in GitHub Desktop.
This git hook checks for the existence of gender pronouns in the commit message and aborts the commit if it finds one
This file contains 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
Using gender pronouns in your git messages can put you in difficult situations. | |
Refer https://github.com/joyent/libuv/pull/1015 for drama caused by this in nodejs community. | |
If you ever thought what power does a pronoun in a commit message, go read https://www.joyent.com/blog/the-power-of-a-pronoun | |
So its best if you can avoid them while composing the commit message. Since 'To err is human', you need a | |
gaurdian to make sure that you don't have gender pronouns, hence this script. | |
You need to place the Gender Pronoun check file contents inside `.git/hooks/commit-msg` file. | |
There are the pronouns considered for validatomg ['he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself'] | |
After adding this, any attempt to use gender pronouns will result in failure of git commit. | |
harry@vnc12[~/git/users](master| +1 ✴)$git commit add-user.pl -m 'Provides ability for user to add himself' | |
Found the gender pronoun "himself" in the commit message in the line: Provides ability for user to add himself | |
Aborting the commit due to usage of gender pronoun | |
harry@vnc12[~/git/users](master| +1 ✴)$ |
This file contains 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
#!/bin/env node | |
/** | |
* This scripts check of the existence of gender pronouns | |
* and aborts the commit if any of them are found | |
* | |
* Don't consider it as silly, because its really 'NOT!'. | |
* One of the core contributor of libuv had to depart since didn't | |
* accept a PR related to gender pronoun fix, so think | |
* carefully before using gender pronouns | |
* | |
* Read the drama @https://github.com/joyent/libuv/pull/1015 | |
*/ | |
// Modules | |
var fs = require('fs'), | |
readline = require('readline'), | |
stream = require('stream'); | |
var GENDER_PRONONUS = ['he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself'], | |
found_gender_pronoun = false, | |
argvs = Array.prototype.splice.call(process.argv,0), | |
commit_msg_file = argvs[2]; | |
/** | |
* Empty commit | |
*/ | |
if (!commit_msg_file){ | |
process.exit(1); | |
} | |
// Use stream since they are insanely faster than reading the whole file | |
// Power of asynchronus!! | |
var file_stream = fs.createReadStream(commit_msg_file, {encodig: 'utf8'}); | |
var out_stream = new stream; | |
var rl = readline.createInterface(file_stream, out_stream); | |
rl.on('line', function(line){ | |
line = line.trim(); | |
if (line.match('^#')){ | |
// this is a comment, so skip it | |
return; | |
} | |
// Check for all the gender pronouns | |
GENDER_PRONONUS.forEach(function(pronoun){ | |
// match whole words | |
var regex = new RegExp('\\b' + pronoun + '\\b', 'i'); | |
if(regex.test(line)){ | |
console.log('Found the gender pronoun "' + pronoun + | |
'" in the commit message in the line: ' + line); | |
console.log('Aborting the commit due to usage of gender pronoun'); | |
process.exit(1); | |
} | |
}); | |
}); | |
rl.on('end', function(){ | |
// No gender pronoun, so exit gracefully | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment