| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,50 +5,36 @@ | |||
| 5 | 5 | // Script to detect cursewords in commit messages and provide the | |
| 6 | 6 | // offending commit sha's. | |
| 7 | 7 | // vim: ft=javascript | |
| 8 | - var git = require( 'nodegit' ); | ||
| 8 | + var git = require('../../'); | ||
| 9 | 9 | ||
| 10 | - var curses = [ 'add', 'swears', 'here' ] | ||
| 11 | - , path = './.git' | ||
| 12 | - , branch = 'master' | ||
| 13 | - , reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); | ||
| 10 | + var curses = ['add', 'swears', 'here'], | ||
| 11 | + path = './.git', | ||
| 12 | + branchName = 'master', | ||
| 13 | + reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | - // Set git path | ||
| 17 | - if ( process.argv.length < 3 ) { | ||
| 18 | - console.log( 'No path passed as argument, defaulting to ./.git' ); | ||
| 19 | - } | ||
| 20 | - else { | ||
| 16 | + if (process.argv.length < 3) { | ||
| 17 | + console.log('No git path passed as argument, defaulting to ./.git'); | ||
| 18 | + } else { | ||
| 21 | 19 | path = process.argv[2]; | |
| 22 | 20 | ||
| 23 | - // Set repo branch | ||
| 24 | - if ( process.argv.length < 4 ) { | ||
| 25 | - console.log( 'No branch passed as argument, defaulting to master' ); | ||
| 26 | - } | ||
| 27 | - else { | ||
| 28 | - branch = process.argv[3]; | ||
| 21 | + if (process.argv.length < 4) { | ||
| 22 | + console.log('No repo branchName passed as argument, defaulting to master'); | ||
| 23 | + } else { | ||
| 24 | + branchName = process.argv[3]; | ||
| 29 | 25 | } | |
| 30 | 26 | } | |
| 31 | 27 | ||
| 32 | - // Open repository | ||
| 33 | - git.repo( path, function( err, repo ) { | ||
| 34 | - if ( err ) { | ||
| 35 | - throw new Error( err ); | ||
| 36 | - } | ||
| 28 | + git.Repo.open(path, function(error, repo) { | ||
| 29 | + if (error) throw error; | ||
| 37 | 30 | ||
| 38 | - // Open branch | ||
| 39 | - repo.branch( branch, function( err, branch ) { | ||
| 40 | - if ( err ) { | ||
| 41 | - throw new Error( err ); | ||
| 42 | - } | ||
| 31 | + repo.getBranch(branchName, function(error, branch) { | ||
| 32 | + if (error) throw error; | ||
| 43 | 33 | ||
| 44 | - // Iterate history | ||
| 45 | 34 | var history = branch.history(); | |
| 46 | - history.on( 'commit', function( idx, commit ) { | ||
| 47 | - // Check commit messages first | ||
| 48 | - if ( reCurse.test(commit.message) ) { | ||
| 49 | - console.log( 'Curse detected in commit', commit.sha, 'message' ); | ||
| 50 | - return; | ||
| 51 | - } | ||
| 52 | - }); | ||
| 35 | + 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(); | ||
| 53 | 39 | }); | |
| 54 | 40 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + var git = require('../'), | ||
| 2 | + path = require('path'); | ||
| 3 | + | ||
| 4 | + // This code examines the diffs between a particular commit and all of its | ||
| 5 | + // parents. Since this commit is not a merge, it only has one parent. This is | ||
| 6 | + // similar to doing `git show`. | ||
| 7 | + | ||
| 8 | + git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { | ||
| 9 | + if (error) throw error; | ||
| 10 | + | ||
| 11 | + repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) { | ||
| 12 | + if (error) throw error; | ||
| 13 | + | ||
| 14 | + console.log('commit ' + commit.sha()); | ||
| 15 | + console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>'); | ||
| 16 | + console.log('Date:', commit.date()); | ||
| 17 | + console.log('\n ' + commit.message()); | ||
| 18 | + | ||
| 19 | + commit.getDiff(function(error, diffList) { | ||
| 20 | + if (error) throw error; | ||
| 21 | + | ||
| 22 | + diffList.forEach(function(diff) { | ||
| 23 | + diff.patches().forEach(function(patch) { | ||
| 24 | + console.log("diff", patch.oldFile().path(), patch.newFile().path()); | ||
| 25 | + patch.hunks().forEach(function(hunk) { | ||
| 26 | + console.log(hunk.header().trim()); | ||
| 27 | + hunk.lines().forEach(function(line) { | ||
| 28 | + console.log(String.fromCharCode(line.lineOrigin) + line.content.trim()); | ||
| 29 | + }); | ||
| 30 | + }); | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | + }); | ||
| 34 | + }); | ||
| 35 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | - var git = require('../index.js'); | ||
| 1 | + var git = require('../'), | ||
| 2 | + path = require('path'); | ||
| 2 | 3 | ||
| 3 | 4 | // **nodegit** is a javascript library for node.js that wraps libgit2, a | |
| 4 | 5 | // pure C implementation of the Git core. It provides an asynchronous | |
@@ -15,7 +16,7 @@ var git = require('../index.js'); | |||
| 15 | 16 | // Nearly, all git operations in the context of a repository. | |
| 16 | 17 | // To open a repository, | |
| 17 | 18 | ||
| 18 | - git.Repo.open('.git', function(error, repo) { | ||
| 19 | + git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { | ||
| 19 | 20 | // For all of the following examples, error-handling will be performed in | |
| 20 | 21 | // this naive way: | |
| 21 | 22 | if (error) throw error; | |
@@ -201,7 +202,7 @@ git.Repo.open('.git', function(error, repo) { | |||
| 201 | 202 | ||
| 202 | 203 | // You can also access tree entries by path if you know the path of the | |
| 203 | 204 | // entry you're looking for. | |
| 204 | - tree.getFile("example/general.js", function(error, entry) { | ||
| 205 | + tree.getEntry("example/general.js", function(error, entry) { | ||
| 205 | 206 | if (error) throw error; | |
| 206 | 207 | ||
| 207 | 208 | // Entries which are files have blobs associated with them: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments