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
31 changes: 30 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@
"git_branch_next": {
"ignore": true
},
"git_branch_remote_name": {
"cppFunctionName": "RemoteName",
"jsFunctionName": "remoteName",
"isAsync": true,
"args": {
"out": {
"isReturn": true,
"cppClassName": "GitBuf",
"jsClassName": "Buffer",
"cType": "git_buf *"
},
"repo": {
"cppClassName": "GitRepository",
"jsClassName": "Repo",
"cType": "git_repository *"
},
"canonical_branch_name": {
"cppClassName": "String",
"jsClassName": "String",
"cType": "const char *"
}
},
"return": {
"isErrorCode": true
}
},
"git_branch_set_upstream": {
"isAsync": true,
"args": {
Expand All @@ -221,7 +247,10 @@
"isErrorCode": true
}
}
}
},
"dependencies": [
"../include/buf.h"
]
},
"buf": {
"functions": {
Expand Down
35 changes: 34 additions & 1 deletion generate/input/libgit2-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,38 @@
"comments": "<p>The name of the branch matches the definition of the name for git_branch_lookup. That is, if the returned name is given to git_branch_lookup() then the reference is returned that was given to this function.</p>\n",
"group": "branch"
},
"git_branch_remote_name": {
"type": "function",
"file": "branch.h",
"line": 274,
"lineto": 277,
"args": [
{
"name": "out",
"type": "git_buf *",
"comment": "where the name is stored."
},
{
"name": "repo",
"type": "git_respository *",
"comment": "the repo to check."
},
{
"name": "canonical_branch_name",
"type": "const char *",
"comment": "the ref name of the branch"
}
],
"argline": "git_buf *out, git_repository *repo, const char *canonical_branch_name",
"sig": "git_buf *::git_repository *::const char *",
"return": {
"type": "int",
"comment": " 0 on success; otherwise an error code (e.g., if the\n ref is no local or remote branch)."
},
"description": "<p>Return the name of the given remote branch.</p>\n",
"comments": "<p></p>\n",
"group": "branch"
},
"git_branch_upstream": {
"type": "function",
"file": "branch.h",
Expand Down Expand Up @@ -36087,6 +36119,7 @@
"git_branch_name",
"git_branch_next",
"git_branch_set_upstream",
"git_branch_remote_name",
"git_branch_upstream"
]
],
Expand Down Expand Up @@ -37149,4 +37182,4 @@
"ex/HEAD/tag.html"
]
]
}
}
19 changes: 19 additions & 0 deletions lib/branch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var NodeGit = require("../");
var Branch = NodeGit.Branch;

var _remoteName = Branch.remoteName;

/**
* Retrieve the Branch's Remote Name as a String.
*
* @async
* @param {Repository} repo The repo to get the remote name from
* @param {String} the refname of the branch
* @return {String} remote name as a string.
*/
Branch.remoteName = function(repo, remoteRef) {
return _remoteName.call(this, repo, remoteRef)
.then(function(remoteNameBuffer) {
return remoteNameBuffer.toString();
});
};
22 changes: 22 additions & 0 deletions test/tests/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("Branch", function() {
var branchName2 = "test-branch2";
var fullBranchName = "refs/heads/" + branchName;
var fullBranchName2 = "refs/heads/" + branchName2;
var remoteName = "origin";
var upstreamName = "origin/master";
var fullUpstreamName = "refs/remotes/origin/master";
var nonHeadCommit = "c82fb078a192ea221c9f1093c64321c60d64aa0d";
Expand Down Expand Up @@ -85,6 +86,27 @@ describe("Branch", function() {
});
});

it("can get the remote name of a branch", function() {
var repo = this.repository;

return NodeGit.Branch.remoteName(repo, fullUpstreamName)
.then(function(remoteNameToTest) {
assert.equal(remoteNameToTest, remoteName);
});
});

it("cannot get remote name from a non-remote branch", function() {
var repo = this.repository;

return NodeGit.Branch.remoteName(repo, fullBranchName)
.then(function() {
assert.fail("The ref should not have been a remote");
})
.catch(function(err) {
assert.strictEqual(err.errno, -1);
});
});

it("can rename a branch", function() {
var branch = this.branch;

Expand Down