Skip to content

Commit 33c7b24

Browse files
committed
Updated obj to object in lib, updated tree_entry
1 parent a06f16d commit 33c7b24

File tree

7 files changed

+88
-20
lines changed

7 files changed

+88
-20
lines changed

example/git_profanity_check.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
3+
// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
4+
// 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
8+
var git = require( 'nodegit' );
9+
10+
var curses = [ 'fuck', 'shit', 'bitch', 'ass' ]
11+
, path = './.git'
12+
, branch = 'master'
13+
, wordExp = /\b\w+\b/g;
14+
15+
// Set git path
16+
if ( process.argv.length < 3 ) {
17+
console.log( 'No path passed as argument, defaulting to ./.git' );
18+
}
19+
else {
20+
path = process.argv[2];
21+
22+
// Set repo branch
23+
if ( process.argv.length < 4 ) {
24+
console.log( 'No branch passed as argument, defaulting to master' );
25+
}
26+
else {
27+
branch = process.argv[3];
28+
}
29+
}
30+
31+
// Open repository
32+
git.repo( path, function( err, repo ) {
33+
if ( err ) {
34+
throw new Error( err );
35+
}
36+
37+
// Open branch
38+
repo.branch( branch, function( err, branch ) {
39+
if ( err ) {
40+
throw new Error( err );
41+
}
42+
43+
// Iterate history
44+
var history = branch.history();
45+
history.on( 'commit', function( idx, commit ) {
46+
// Check commit messages first
47+
curses.forEach(function( curse ) {
48+
var messageWords = commit.message.match( wordExp );
49+
50+
messageWords.forEach(function( word ) {
51+
if ( word == curse ) {
52+
console.log( 'Curse detected in commit', commit.sha, 'message' );
53+
54+
return;
55+
}
56+
});
57+
});
58+
});
59+
});
60+
});

lib/blob.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var _Blob = function( obj ) {
1313

1414
Object.defineProperty( self, 'raw', {
1515
get: function() {
16-
console.log( self.blob.rawContent() );
1716
return self.blob.rawContent().toString();
1817
},
1918
enumerable: true

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var util = require( './util.js' ).util,
88
error = require( './error.js' ).error,
99
sig = require( './sig.js' ).sig,
1010
oid = require( './oid.js' ).oid,
11-
obj = require( './obj.js' ).obj,
11+
object = require( './object.js' ).obj,
1212
ref = require( './ref.js' ).ref,
1313
revwalk = require( './revwalk.js' ).revwalk,
1414
commit = require( './commit.js' ).commit,
@@ -30,7 +30,7 @@ exports.util = util;
3030
exports.repo = repo;
3131
exports.ref = ref;
3232
exports.oid = oid;
33-
exports.obj = obj;
33+
exports.object = object;
3434
exports.sig = sig;
3535
exports.error = error;
3636
exports.revwalk = revwalk;

lib/obj.js renamed to lib/object.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var git = require( '../' );
33
var _Object = function( obj ) {
44
var self = {};
55

6-
if( obj instanceof git.raw.Object ) {
7-
self.obj = obj;
6+
if( object instanceof git.raw.Object ) {
7+
self.object = obj;
88
}
99
else {
10-
self.obj = new git.raw.Object();
10+
self.object = new git.raw.Object();
1111
}
1212

1313
Object.defineProperty( self, 'id', {
@@ -18,54 +18,54 @@ var _Object = function( obj ) {
1818

1919
Object.defineProperty( self, 'type', {
2020
get: function() {
21-
return self.obj.type();
21+
return self.object.type();
2222
},
2323
enumerable: true
2424
});
2525

2626
Object.defineProperty( self, 'length', {
2727
get: function() {
28-
return self.obj.size();
28+
return self.object.size();
2929
},
3030
enumerable: true
3131
});
3232

3333
Object.defineProperty( self, 'isLoose', {
3434
get: function() {
35-
return self.obj.typeIsLoose();
35+
return self.object.typeIsLoose();
3636
},
3737
enumerable: true
3838
});
3939

4040
self.id = function() {
4141
var oid = git.oid();
4242

43-
self.obj.id( oid.oid );
43+
self.object.id( oid.oid );
4444

4545
return oid;
4646
};
4747

4848
self.owner = function() {
4949
var repo = git.repo();
5050

51-
self.obj.owner( repo.repo );
51+
self.object.owner( repo.repo );
5252

5353
return repo;
5454
};
5555

5656
self.toString = function() {
57-
return self.obj.type2String();
57+
return self.object.type2String();
5858
};
5959

6060
self.toType = function( type ) {
61-
return self.obj.toType( type );
61+
return self.object.toType( type );
6262
};
6363

6464
self.free = function() {
65-
return self.obj.free();
65+
return self.object.free();
6666
};
6767

6868
return self;
6969
};
7070

71-
exports.obj = _Object;
71+
exports.object = _Object;

lib/tree_entry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ var _TreeEntry = function( obj ) {
2525
enumerable: true
2626
});
2727

28+
Object.defineProperty( self, 'object', {
29+
get: function() {
30+
return self.entry.toObject();
31+
},
32+
enumerable: true
33+
});
34+
2835
Object.defineProperty( self, 'content', {
2936
get: function() {
3037
if( self.isFile() ) {

src/tree_entry.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,18 @@ Handle<Value> GitTreeEntry::ToObject(const Arguments& args) {
104104
}
105105

106106
if(args.Length() == 1 || !args[1]->IsObject()) {
107-
return ThrowException(Exception::Error(String::New("Blob is required and must be an Object.")));
107+
return ThrowException(Exception::Error(String::New("Object is required and must be an Object.")));
108108
}
109109

110110
GitRepo* repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject());
111-
GitBlob* blob = ObjectWrap::Unwrap<GitBlob>(args[1]->ToObject());
111+
GitObject* object = ObjectWrap::Unwrap<GitObject(args[1]->ToObject());
112112

113113
git_object* out;
114114
entry->ToObject(repo->GetValue(), &out);
115-
blob->SetValue((git_blob *)out);
115+
116+
GitObject->SetValue(out);
116117

117-
return Undefined();
118+
return scope.Close(;
118119
}
119120
Persistent<FunctionTemplate> GitTreeEntry::constructor_template;
121+

util/hint-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ files = [
66
'lib/commit.js',
77
'lib/error.js',
88
'lib/index.js',
9-
'lib/obj.js',
9+
'lib/object.js',
1010
'lib/oid.js',
1111
'lib/ref.js',
1212
'lib/repo.js',

0 commit comments

Comments
 (0)