|
1 | 1 | #!/usr/bin/env node |
| 2 | +// vim: ft=javascript |
2 | 3 |
|
3 | | -// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> |
| 4 | +// Copyright 2011-2014, Tim Branyen @tbranyen <tim@tabdeveloper.com> |
4 | 5 | // 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 | +// |
8 | 13 | var git = require('../../'); |
9 | 14 |
|
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'); |
15 | 19 |
|
| 20 | +// Default path is `.git`. |
16 | 21 | 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 { |
19 | 26 | path = process.argv[2]; |
20 | 27 |
|
| 28 | + // Set repo branch |
21 | 29 | 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]; |
25 | 34 | } |
26 | 35 | } |
27 | 36 |
|
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 | + } |
30 | 42 |
|
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 | + } |
33 | 48 |
|
| 49 | + // Iterate history |
34 | 50 | var history = branch.history(); |
| 51 | + |
| 52 | + // Iterate over every commit message and test for words. |
35 | 53 | 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(); |
39 | 65 | }); |
40 | 66 | }); |
0 commit comments