Skip to content
Browse files

Ensure constructors export their native wrappers

  • Loading branch information...
1 parent 9b2f3a3 commit 4538e6d789db8a4db7767d79a75e0aa6d84f23b4 @tbranyen tbranyen committed Jul 9, 2014
Showing with 96 additions and 70 deletions.
  1. +6 −1 .jshintrc
  2. +5 −2 lib/blob.js
  3. +6 −3 lib/commit.js
  4. +3 −3 lib/convenient_patch.js
  5. +15 −13 lib/diff.js
  6. +1 −1 lib/index.js
  7. +1 −1 lib/object.js
  8. +4 −4 lib/odb.js
  9. +1 −1 lib/oid.js
  10. +5 −0 lib/patch.js
  11. +7 −3 lib/reference.js
  12. +10 −8 lib/repository.js
  13. +4 −4 lib/revwalk.js
  14. +6 −3 lib/signature.js
  15. +8 −8 lib/tree.js
  16. +6 −3 lib/tree_entry.js
  17. +5 −2 lib/util.js
  18. +0 −4 test/commit.js
  19. +2 −3 test/tests/blob.js
  20. +1 −3 test/tests/commit.js
View
7 .jshintrc
@@ -5,6 +5,7 @@
"eqnull": true,
"maxlen": 80,
"node": true,
+ "proto": true,
"curly": true,
"quotmark": "double",
"trailing": true,
@@ -13,6 +14,10 @@
"validthis": true,
"globals": {
"global": true,
- "define": true
+ "define": true,
+ "it": true,
+ "describe": true,
+ "before": true,
+ "beforeEach": true
}
}
View
7 lib/blob.js
@@ -1,8 +1,7 @@
var NodeGit = require("../");
var TreeEntry = require("./tree_entry");
-var Blob = NodeGit.Blob;
-var FileMode = TreeEntry.FileMode;
+var Blob = NodeGit.Blob;
/**
* Retrieve the content of the Blob.
@@ -28,5 +27,9 @@ Blob.prototype.toString = function() {
* @return {number} The filemode.
*/
Blob.prototype.filemode = function() {
+ var FileMode = TreeEntry.FileMode;
+
return this.isBinary() ? FileMode.Executable : FileMode.Blob;
};
+
+module.exports = Blob;
View
9 lib/commit.js
@@ -1,7 +1,8 @@
-var Promise = require("promise");
-var git = require("../");
-var Commit = git.Commit;
var events = require("events");
+var Promise = require("promise");
+var NodeGit = require("../");
+
+var Commit = NodeGit.Commit;
/**
* Retrieve the SHA.
@@ -194,3 +195,5 @@ Commit.prototype.getDiff = function(callback) {
Commit.prototype.toString = function() {
return this.sha();
};
+
+module.exports = Commit;
View
6 lib/convenient_patch.js
@@ -1,6 +1,6 @@
-var git = require('../');
+var git = require("../");
var Diff = git.Diff;
-var ConvenientHunk = require('./convenient_hunk').ConvenientHunk;
+var ConvenientHunk = require("./convenient_hunk").ConvenientHunk;
function ConvenientPatch(delta, patch) {
this.delta = delta;
@@ -126,4 +126,4 @@ ConvenientPatch.prototype.isTypeChange = function() {
return this.status() == Diff.Delta.TypeChange;
};
-exports.ConvenientPatch = ConvenientPatch;
+module.exports = ConvenientPatch;
View
28 lib/diff.js
@@ -1,8 +1,8 @@
-var git = require('../');
-var Diff = git.Diff;
-var Patch = git.Patch;
-var ConvenientPatch = require('./convenient_patch').ConvenientPatch;
-var events = require('events');
+var NodeGit = require("../");
+var Patch = require("./patch");
+var ConvenientPatch = require("./convenient_patch");
+
+var Diff = NodeGit.Diff;
Object.defineProperties(Diff.prototype, {
size: {
@@ -36,14 +36,14 @@ Diff.Delta = {
* @enum {String}
*/
Diff.LineOrigin = {
- /** ' ' */ Context: 32,
- /** '+' */ Addition: 43,
- /** '-' */ Deletion: 45,
- /** '\n' */ AddEofNl: 13,
- /** '' */ DelEofNl: 0,
- /** 'F' */ FileHdr: 106,
- /** 'H' */ HunkHdr: 110,
- /** 'B' */ Binary: 102
+ /** " " */ Context: 32,
+ /** "+" */ Addition: 43,
+ /** "-" */ Deletion: 45,
+ /** "\n" */ AddEofNl: 13,
+ /** "" */ DelEofNl: 0,
+ /** "F" */ FileHdr: 106,
+ /** "H" */ HunkHdr: 110,
+ /** "B" */ Binary: 102
};
/**
@@ -59,3 +59,5 @@ Diff.prototype.patches = function() {
}
return result;
};
+
+module.exports = Diff;
View
2 lib/index.js
@@ -1,4 +1,4 @@
-var git = require('../'),
+var git = require("../"),
Index = git.Index;
/**
View
2 lib/object.js
@@ -1,4 +1,4 @@
-var git = require('../');
+var git = require("../");
git.Object.Type = {
Any: -2, /**< Object can be any of the following */
View
8 lib/odb.js
@@ -1,5 +1,5 @@
-var git = require('../'),
- util = require('./util.js'),
+var git = require("../"),
+ util = require("./util.js"),
Odb = git.Odb;
/**
@@ -9,5 +9,5 @@ var git = require('../'),
* @param {Function} callback
* @return {git.Object} a git odb object
*/
-util.normalizeOid(Odb.prototype, 'read');
-util.makeSafe(Odb.prototype, 'read');
+util.normalizeOid(Odb.prototype, "read");
+util.makeSafe(Odb.prototype, "read");
View
2 lib/oid.js
@@ -1,4 +1,4 @@
-var git = require('../'),
+var git = require("../"),
Oid = git.Oid;
// Backwards compatibility.
View
5 lib/patch.js
@@ -0,0 +1,5 @@
+var NodeGit = require("../");
+
+var Patch = NodeGit.Patch;
+
+module.exports = Patch;
View
10 lib/reference.js
@@ -1,4 +1,4 @@
-var git = require('../'),
+var git = require("../"),
Reference = git.Refs;
// Backwards compatibility.
@@ -38,7 +38,9 @@ Reference.prototype.isSymbolic = function() {
* @throws if the target is not symbolic.
*/
Reference.prototype.symbolicTarget = function() {
- if (!this.isSymbolic()) throw this.name() + " is not symbolic";
+ if (!this.isSymbolic()) {
+ throw new Error(this.name() + " is not symbolic");
+ }
return oldSymbolicTarget.call(this);
};
@@ -49,7 +51,9 @@ Reference.prototype.symbolicTarget = function() {
* @throws if the target is symbolic.
*/
Reference.prototype.target = function() {
- if (!this.isConcrete()) throw this.name() + " is symbolic";
+ if (!this.isConcrete()) {
+ throw new Error(this.name() + " is symbolic");
+ }
return oldTarget.call(this);
};
View
18 lib/repository.js
@@ -1,6 +1,6 @@
-var git = require('../');
-var util = require('./util');
-var Refs = require('./reference');
+var git = require("../");
+var util = require("./util");
+var Refs = require("./reference");
var normalizeOid = require("./util/normalize_oid");
var Commit = git.Commit;
@@ -17,16 +17,16 @@ Object.defineProperty(git, "Repo", {
});
/**
- * Look up a branch's most recent commit.
+ * Look up a branch"s most recent commit.
*
- * @param {String} name Branch name, e.g. 'master'
+ * @param {String} name Branch name, e.g. "master"
* @param {Function} callback
* @return {Branch}
*/
Repo.prototype.getBranch = function(name, callback) {
var repository = this;
- return this.getReference('refs/heads/' + name).then(function(reference) {
+ return this.getReference("refs/heads/" + name).then(function(reference) {
return repository.getCommit(reference.target()).then(function(commit) {
if (callback) {
callback(null, commit);
@@ -161,7 +161,7 @@ Repo.prototype.getTag = function(oid, callback) {
};
/**
- * Instantiate a new revision walker for browsing the Repo's history.
+ * Instantiate a new revision walker for browsing the Repo"s history.
* See also `Commit.prototype.history()`
*
* @param {String|Oid} String sha or Oid
@@ -181,7 +181,7 @@ Repo.prototype.createRevWalk = function() {
* @return {Branch}
*/
Repo.prototype.getMaster = function(callback) {
- this.getBranch('master', callback);
+ this.getBranch("master", callback);
};
/**
@@ -249,3 +249,5 @@ Repo.prototype.treeBuilder = function(callback) {
builder.repo = this;
return builder;
};
+
+module.exports = Repo;
View
8 lib/revwalk.js
@@ -1,5 +1,5 @@
-var git = require('../');
-var util = require('./util');
+var git = require("../");
+var util = require("./util");
var Revwalk = git.Revwalk;
// Backwards compatibility.
@@ -63,5 +63,5 @@ Revwalk.prototype.walk = function(oid, callback) {
walk();
};
-util.normalizeOid(Revwalk.prototype, 'walk');
-util.makeSafe(Revwalk.prototype, 'walk');
+util.normalizeOid(Revwalk.prototype, "walk");
+util.makeSafe(Revwalk.prototype, "walk");
View
9 lib/signature.js
@@ -1,10 +1,13 @@
-var git = require('../'),
- Signature = git.Signature;
+var NodeGit = require("../");
+var Signature = NodeGit.Signature;
/**
* Standard string representation of an author.
- * @return {String}
+ *
+ * @return {string} Representation of the author.
*/
Signature.prototype.toString = function() {
return this.name().toString() + " <" + this.email().toString() + ">";
};
+
+module.exports = Signature;
View
16 lib/tree.js
@@ -1,11 +1,11 @@
-var git = require('../');
+var git = require("../");
var Tree = git.Tree;
var TreeBuilder = git.Treebuilder;
var Diff = git.Diff;
var DiffOptions = git.DiffOptions;
-var TreeEntry = require('./tree_entry');
-var events = require('events');
-var path = require('path');
+var TreeEntry = require("./tree_entry");
+var events = require("events");
+var path = require("path");
var oldBuilder = TreeBuilder.create;
var oldEntryByIndex = Tree.prototype.entryByindex;
@@ -113,12 +113,12 @@ Tree.prototype.walk = function(blobsOnly) {
total--;
if (error) {
- return event.emit('error', error);
+ return event.emit("error", error);
}
tree.entries().forEach(function (entry) {
if (!blobsOnly || entry.isFile()) {
- event.emit('entry', entry);
+ event.emit("entry", entry);
entries.push(entry);
}
@@ -129,7 +129,7 @@ Tree.prototype.walk = function(blobsOnly) {
});
if (total === 0) {
- event.emit('end', entries);
+ event.emit("end", entries);
}
}
@@ -145,7 +145,7 @@ Tree.prototype.walk = function(blobsOnly) {
* @return {String}
*/
Tree.prototype.path = function(blobsOnly) {
- return this.entry ? this.entry.path() : '';
+ return this.entry ? this.entry.path() : "";
};
/**
View
9 lib/tree_entry.js
@@ -1,6 +1,7 @@
-var NodeGit = require('../');
+var path = require("path");
+var NodeGit = require("../");
+
var TreeEntry = NodeGit.TreeEntry;
-var path = require('path');
// Backwards compatibility.
Object.defineProperty(TreeEntry.prototype, "name", {
@@ -67,7 +68,9 @@ TreeEntry.prototype.sha = function() {
TreeEntry.prototype.getTree = function(callback) {
var self = this;
this.parent.repo.getTree(this.oid(), function(error, tree) {
- if (error) return callback(error);
+ if (error) {
+ return callback(error);
+ }
tree.entry = self;
callback(null, tree);
View
7 lib/util.js
@@ -1,4 +1,4 @@
-var git = require('../');
+var git = require("../");
exports.makeSafe = function(object, key) {
var oldFn = object[key];
@@ -15,7 +15,10 @@ exports.makeSafe = function(object, key) {
exports.normalizeOid = function(object, key) {
var oldFn = object[key];
object[key] = function(oid) {
- if (typeof oid === 'string') oid = git.Oid.fromString(oid);
+ if (typeof oid === "string") {
+ oid = git.Oid.fromString(oid);
+ }
+
oldFn.apply(this, arguments);
};
};
View
4 test/commit.js
@@ -5,10 +5,6 @@ exports.getDiff = function(test) {
test.expect(1);
git.Repo.open('repos/workdir/.git', function(error, repository) {
repository.getCommit(historyCountKnownSHA, function(error, commit) {
- commit.getDiff(function(error, diff) {
- test.equals(diff.length, 1, 'Should be one item in parents diff trees');
- test.done();
- });
});
});
};
View
5 test/tests/blob.js
@@ -7,9 +7,8 @@ describe("Blob", function() {
var reposPath = path.resolve("test/repos/workdir/.git");
var oid = "111dd657329797f6165f52f5085f61ac976dcf04";
- var Oid = NodeGit.Oid;
- var Repository = NodeGit.Repository;
- var FileMode = NodeGit.TreeEntry.FileMode;
+ var Repository = require("../../lib/repository");
+ var FileMode = require("../../lib/tree_entry").FileMode;
before(function() {
var test = this;
View
4 test/tests/commit.js
@@ -1,7 +1,5 @@
var assert = require("assert");
-var rimraf = require("rimraf");
var path = require("path");
-var fs = require( "fs" );
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
@@ -10,7 +8,7 @@ describe("Commit", function() {
var reposPath = path.resolve("test/repos/workdir/.git");
var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
- var Commit = require("./commit");
+ var Commit = require("../../lib/commit");
beforeEach(function() {
var test = this;

0 comments on commit 4538e6d

Please sign in to comment.
Something went wrong with that request. Please try again.