FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added tests for Branch by rcjsuen · Pull Request #1181 · nodegit/nodegit · GitHub

Repository navigation

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

Filter by extension

Filter by extension .js  (1) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions generate/input/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
}
},
"git_branch_create_from_annotated": {
"isAsync": true,
"args": {
"ref_out": {
"isReturn": true
Expand All @@ -193,6 +194,9 @@
"force": {
"isOptional": true
}
},
"return": {
"isErrorCode": true
}
},
"git_branch_next": {
Expand Down
66 changes: 66 additions & 0 deletions test/tests/branch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ describe("Branch", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var Branch = NodeGit.Branch;
var AnnotatedCommit = NodeGit.AnnotatedCommit;
var branchName = "test-branch";
var branchName2 = "test-branch2";
var fullBranchName = "refs/heads/" + branchName;
var fullBranchName2 = "refs/heads/" + branchName2;
var upstreamName = "origin/master";
var fullUpstreamName = "refs/remotes/origin/master";
var nonHeadCommit = "c82fb078a192ea221c9f1093c64321c60d64aa0d";

var reposPath = local("../repos/workdir");

Expand All @@ -27,6 +32,8 @@ describe("Branch", function() {
})
.then(function(branch) {
test.branch = branch;
return test.repository.createBranch(
branchName2, test.masterCommit, true);
});
});

Expand Down Expand Up @@ -77,4 +84,63 @@ describe("Branch", function() {
assert.equal(branchNameToTest, branchName);
});
});

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

// don't force the move
return Branch.move(branch, branchName2, 0)
.then(function(branch) {
return Promise.reject(new Error(
"should not be able to rename the branch"));
}, function(error) {
return Promise.resolve()
.then(function() {
// force the move
return Branch.move(branch, branchName2, 1);
})
.then(function(branch) {
assert.equal(branch.name(), fullBranchName2);
});
});
});

it("can lookup a branch", function() {
var repo = this.repository;

return Branch.lookup(repo, branchName, Branch.BRANCH.LOCAL)
.then(function(branch) {
assert.equal(branch.name(), fullBranchName);
return Branch.lookup(repo, upstreamName, Branch.BRANCH.REMOTE);
})
.then(function(branch) {
assert.equal(branch.name(), fullUpstreamName);
});
});

it("can create branch from annotated commit", function() {
var repo = this.repository;
var annotatedCommit = null;

return AnnotatedCommit.fromRevspec(repo, nonHeadCommit)
.then(function(theAnnotatedCommit) {
annotatedCommit = theAnnotatedCommit;
return Branch.createFromAnnotated(
repo, branchName, annotatedCommit, 0);
})
.then(function(branch) {
return Promise.reject(new Error(
"should not be able to create the branch"));
}, function(error) {
return Promise.resolve()
.then(function() {
// force the branch creation
return Branch.createFromAnnotated(
repo, branchName, annotatedCommit, 1);
})
.then(function(branch) {
assert.equal(branch.name(), fullBranchName);
});
});
});
});

Back | FazBrowse Home | New Git URL