Skip to content

Commit c7c961f

Browse files
committed
Unrelated commit: Updated the git_profanity_check app.
1 parent 7f6f64d commit c7c961f

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed
Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
11
#!/usr/bin/env node
2+
// vim: ft=javascript
23

3-
// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
4+
// Copyright 2011-2014, Tim Branyen @tbranyen <tim@tabdeveloper.com>
45
// Dual licensed under the MIT and GPL licenses.
5-
// Script to detect cursewords in commit messages and provide the
6-
// offending commit sha's.
7-
// vim: ft=javascript
6+
// Script to detect cursewords in commit messages and provide the offending
7+
// commit sha's.
8+
//
9+
// Usage:
10+
//
11+
// node git_profanity_check some/repo/.git
12+
//
813
var git = require('../../');
914

10-
var curses = ['add', 'swears', 'here'],
11-
path = '../../.git',
12-
branchName = 'master',
13-
reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi');
14-
15+
var curses = ['put', 'curse', 'words', 'here'];
16+
var path = './.git';
17+
var branch = 'master';
18+
var reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi');
1519

20+
// Default path is `.git`.
1621
if (process.argv.length < 3) {
17-
console.log('No git path passed as argument, defaulting to ./.git');
18-
} else {
22+
console.log('No path passed as argument, defaulting to .git.');
23+
}
24+
// Otherwise defaults.
25+
else {
1926
path = process.argv[2];
2027

28+
// Set repo branch
2129
if (process.argv.length < 4) {
22-
console.log('No repo branchName passed as argument, defaulting to master');
23-
} else {
24-
branchName = process.argv[3];
30+
console.log('No branch passed as argument, defaulting to master.');
31+
}
32+
else {
33+
branch = process.argv[3];
2534
}
2635
}
2736

28-
git.Repo.open(path, function(error, repo) {
29-
if (error) throw error;
37+
// Open repository.
38+
git.Repo.open(path, function(err, repo) {
39+
if (err) {
40+
throw new Error(err);
41+
}
3042

31-
repo.getBranch(branchName, function(error, branch) {
32-
if (error) throw error;
43+
// Open branch, default to master.
44+
repo.getBranch(branch, function(err, branch) {
45+
if (err) {
46+
throw new Error(err);
47+
}
3348

49+
// Iterate history
3450
var history = branch.history();
51+
52+
// Iterate over every commit message and test for words.
3553
history.on('commit', function(commit) {
36-
if (reCurse.test(commit.message()))
37-
console.log('Curse detected in commit', commit.sha(), 'message', commit.message());
38-
}).start();
54+
var message = commit.message();
55+
56+
if (reCurse.test(message)) {
57+
console.log('Curse detected in commit', commit.sha());
58+
console.log('=> ', message);
59+
return;
60+
}
61+
});
62+
63+
// Start history iteration.
64+
history.start();
3965
});
4066
});

0 commit comments

Comments
 (0)