-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathbranch.js
More file actions
146 lines (124 loc) · 4.3 KB
/
branch.js
File metadata and controls
146 lines (124 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
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");
beforeEach(function() {
var test = this;
return Repository.open(reposPath)
.then(function(repository) {
test.repository = repository;
return repository.getMasterCommit();
})
.then(function(masterCommit) {
test.masterCommit = masterCommit;
return test.repository.createBranch(branchName, masterCommit, true);
})
.then(function(branch) {
test.branch = branch;
return test.repository.createBranch(
branchName2, test.masterCommit, true);
});
});
it("can create a branch", function() {
var branch = this.branch;
var masterCommit = this.masterCommit;
assert.equal(branch.name(), fullBranchName);
assert.equal(branch.target().toString(), masterCommit.sha());
});
it("can delete a branch", function() {
var repo = this.repository;
Branch.delete(this.branch);
return repo.getBranch(branchName)
// Reverse the results, since if we found it it wasn't deleted
.then(Promise.reject.bind(Promise), Promise.resolve.bind(Promise));
});
it("can see if the branch is pointed to by head", function() {
var repo = this.repository;
return repo.getBranch("master")
.then(function(branch) {
assert.ok(branch.isHead());
});
});
it("can set an upstream for a branch", function() {
var branch = this.branch;
return NodeGit.Branch.setUpstream(branch, upstreamName)
.then(function() {
return NodeGit.Branch.upstream(branch);
})
.then(function(upstream) {
assert.equal(upstream.shorthand(), upstreamName);
});
});
it("can get the name of a branch", function() {
var branch = this.branch;
return NodeGit.Branch.name(branch)
.then(function(branchNameToTest) {
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);
});
});
});
});