Commit 113493a9 authored by Tyler Wanek's avatar Tyler Wanek Committed by GitHub

Merge pull request #1340 from cjhoward92/feature/add_branch_remote_name

Exposed libgit2 git_branch_remote_name method
parents 92a570fa f913d50a
......@@ -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": {
......@@ -221,7 +247,10 @@
"isErrorCode": true
}
}
}
},
"dependencies": [
"../include/buf.h"
]
},
"buf": {
"functions": {
......
......@@ -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",
......@@ -36087,6 +36119,7 @@
"git_branch_name",
"git_branch_next",
"git_branch_set_upstream",
"git_branch_remote_name",
"git_branch_upstream"
]
],
......@@ -37149,4 +37182,4 @@
"ex/HEAD/tag.html"
]
]
}
\ No newline at end of file
}
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();
});
};
......@@ -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";
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment