Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add in remote listing support and test
  • Loading branch information
tbranyen committed Jul 18, 2014
commit 15315cf41ad76400d9189c85a5827b77b8c392f1
24 changes: 24 additions & 0 deletions generate/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,26 @@
},

"remote": {
"dependencies": [
"../include/functions/copy.h",
"../include/remote.h",
"../include/strarray.h",
"../include/repository.h",
"../include/transport.h"
],

"functions": {
"git_remote_list": {
"ignore": false,
"isConstructorMethod": true,
"args": [
{ "shouldAlloc": true }
],
"return": {
"copy": "git_strarray_copy"
}
}
}
},

"repository": {
Expand Down Expand Up @@ -648,6 +668,10 @@
"cType": null
},

"strarray": {
"cType": "git_strarray"
},

"submodule": {
},

Expand Down
2 changes: 1 addition & 1 deletion generate/templates/binding.gyp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],

"cflags": [
"-Wall",
"-Wall"
],

"conditions": [
Expand Down
19 changes: 11 additions & 8 deletions generate/templates/convertToV8.cc.ejs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<% toName = to.name || 'result' -%>
<% if (to.cppClassName == "String") { -%>
<% if (typeof to.size != 'undefined') { -%>
to = NanNew<String>(<%- toName %>, <%- to.size %>);
<% } else { -%>
to = NanNew<String>(<%- toName %>);
<% } -%>
<% if (to.freeFunctionName) { -%>
<%- to.freeFunctionName %>(<%- toName %>);
<% } -%>
<% if (typeof to.size != 'undefined') { -%>
to = NanNew<String>(<%- toName %>, <%- to.size %>);
<% } else if (to.cType === "char **") { -%>
to = NanNew<String>(*<%- toName %>);
<% } else { -%>
to = NanNew<String>(<%- toName %>);
<% } -%>

<% if (to.freeFunctionName) { -%>
<%- to.freeFunctionName %>(<%- toName %>);
<% } -%>
<% } else if (isV8Value(to.cppClassName)) { -%>
<% if (~['Uint32', 'Int32'].indexOf(to.cppClassName)) { -%>
<% var className = to.cppClassName.toLowerCase()+'_t' -%>
Expand Down
22 changes: 17 additions & 5 deletions generate/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1993,8 +1993,8 @@
"js": "list"
},
"git_strarray *": {
"js": "Strarray",
"cpp": "Strarray"
"cpp": "GitStrarray",
"js": "Strarray"
},
"git_tag_list_match": {
"cpp": "ListMatch",
Expand Down Expand Up @@ -2062,7 +2062,7 @@
},
"git_strarray*": {
"js": "Strarray*",
"cpp": "Strarray*"
"cpp": "GitStrarray*"
},
"git_revparse_single": {
"cpp": "RevparseSingle",
Expand Down Expand Up @@ -2213,8 +2213,8 @@
"js": "strarrayCopy"
},
"const git_strarray *": {
"js": "Strarray",
"cpp": "Strarray"
"cpp": "GitStrarray",
"js": "Strarray"
},
"git_submodule_foreach": {
"cpp": "Foreach",
Expand Down Expand Up @@ -9043,5 +9043,17 @@
"const git_diff_line *": {
"cpp": "GitDiffLine",
"js": "DiffLine"
},
"git_strarray": {
"cpp": "GitStrarray",
"js": "Strarray"
},
"git_strarray **": {
"cpp": "GitStrarray",
"js": "Strarray"
},
"const git_strarray **": {
"cpp": "GitStrarray",
"js": "Strarray"
}
}
5 changes: 5 additions & 0 deletions lib/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var NodeGit = require("../");

var Remote = NodeGit.Remote;

module.exports = Remote;
17 changes: 17 additions & 0 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Tree = require("./tree");
var Reference = require("./refs");
var Revwalk = require("./revwalk");
var Commit = require("./commit");
var Remote = require("./remote");

var TreeBuilder = NodeGit.Treebuilder;
var Repository = NodeGit.Repository;
Expand Down Expand Up @@ -35,6 +36,22 @@ Repository.prototype.getBranch = function(name, callback) {
}, callback);
};

/**
* Lists out the remotes in the given repository.
*
* @param {Function} Optional callback
* @return {Object} Promise object.
*/
Repository.prototype.getRemotes = function(callback) {
return Remote.list(this).then(function(remotes) {
if (typeof callback === "function") {
callback(null, remotes);
}

return remotes;
}, callback);
};

/**
* Lookup the reference with the given name.
*
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"test": "npm run lint && npm run mocha",
"publish": "node-pre-gyp package && node-pre-gyp publish",
"generate": "node generate/setup && node generate",
"install": "npm run generate && node install"
"install": "npm run generate && node install",
"rebuild": "npm run generate && node-gyp configure build"
}
}
7 changes: 7 additions & 0 deletions test/tests/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ describe("Repository", function() {
assert.ok(index instanceof Index);
});
});

it("can list remotes", function() {
return this.repository.getRemotes().then(function(remotes) {
assert.equal(remotes.count(), 1);
assert.equal(remotes.strings(), "origin");
});
});
});