Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git profanity check
#!/usr/bin/env node
// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
// Dual licensed under the MIT and GPL licenses.
// Script to detect cursewords in commit messages and provide the
// offending commit sha's.
// vim: ft=javascript
var git = require( 'nodegit' );
var curses = [ 'removed', 'inappropriate', 'swear', 'words' ]
, path = './.git'
, branch = 'master'
, reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi');
// Set git path
if ( process.argv.length < 3 ) {
console.log( 'No path passed as argument, defaulting to ./.git' );
}
else {
path = process.argv[2];
// Set repo branch
if ( process.argv.length < 4 ) {
console.log( 'No branch passed as argument, defaulting to master' );
}
else {
branch = process.argv[3];
}
}
// Open repository
git.repo( path, function( err, repo ) {
if ( err ) {
throw new Error( err );
}
// Open branch
repo.branch( branch, function( err, branch ) {
if ( err ) {
throw new Error( err );
}
// Iterate history
var history = branch.history();
history.on( 'commit', function( idx, commit ) {
// Check commit messages first
if ( reCurse.test(commit.message) ) {
console.log( 'Curse detected in commit', commit.sha, 'message' );
return;
}
});
});
});
@cowboy

This comment has been minimized.

Copy link

cowboy commented May 9, 2011

This was definitely not created for a specific reason.

@miketaylr

This comment has been minimized.

Copy link

miketaylr commented May 9, 2011

Quit cursing in the fscking commit message, jeeze.

@tbranyen

This comment has been minimized.

Copy link
Owner Author

tbranyen commented May 9, 2011

Updated it with a new regex generation snippet (by cowboy) to eliminate all forEach statements, so much nicer! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.