-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathtag.js
More file actions
259 lines (234 loc) · 7.6 KB
/
tag.js
File metadata and controls
259 lines (234 loc) · 7.6 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
var assert = require("assert");
var path = require("path");
var local = path.join.bind(path, __dirname);
describe("Tag", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var Tag = NodeGit.Tag;
var Obj = NodeGit.Object;
var Oid = NodeGit.Oid;
var Reference = NodeGit.Reference;
var Signature = NodeGit.Signature;
var reposPath = local("../repos/workdir");
var tagName = "annotated-tag";
var tagPattern = "annotated*";
var tagFullName = "refs/tags/" + tagName;
var tagOid = "dc800017566123ff3c746b37284a24a66546667e";
var commitPointedTo = "32789a79e71fbc9e04d3eff7425e1771eb595150";
var commitPointedTo2 = "c82fb078a192ea221c9f1093c64321c60d64aa0d";
var tagMessage = "This is an annotated tag\n";
function testTag(tag, name) {
assert.equal(tag.name(), name || tagName);
assert.equal(tag.targetType(), Obj.TYPE.COMMIT);
assert.equal(tag.message(), tagMessage);
return tag.target()
.then(function(target) {
assert.ok(target.isCommit());
assert.equal(target.id().toString(), commitPointedTo);
});
}
beforeEach(function() {
var test = this;
return Repository.open(reposPath)
.then(function(repo) {
test.repository = repo;
});
});
it("can get a tag from a repo via the tag name", function() {
return this.repository.getTagByName(tagName)
.then(function(tag) {
return testTag(tag);
});
});
it("can get a tag from a repo via the long tag name", function() {
return this.repository.getTagByName(tagFullName)
.then(function(tag) {
return testTag(tag);
});
});
it("can get a tag from a repo via the tag's OID as a string", function() {
return this.repository.getTag(tagOid)
.then(function(tag) {
return testTag(tag);
});
});
it("can get a tag from a repo via the tag's OID object", function() {
var oid = Oid.fromString(tagOid);
return this.repository.getTag(oid)
.then(function(tag) {
return testTag(tag);
});
});
it("can list tags in a repo", function() {
return Tag.list(this.repository)
.then(function(tagNames) {
tagNames = tagNames.filter(function(tagNameTest) {
return tagNameTest == tagName;
});
assert.equal(tagNames.length, 1);
});
});
it("can list tags of a pattern in a repo", function() {
return Tag.listMatch(tagPattern, this.repository)
.then(function(tagNames) {
assert.equal(tagNames.length, 1);
});
});
it("can create a new annotated tag in a repo and delete it", function() {
var oid = Oid.fromString(commitPointedTo);
var name = "created-annotated-tag";
var repository = this.repository;
return repository.createTag(oid, name, tagMessage)
.then(function(tag) {
return testTag(tag, name);
})
.then(function() {
return repository.createTag(oid, name, tagMessage);
})
.then(function() {
return Promise.reject(new Error("should not be able to create the '" +
name + "' tag twice"));
}, function() {
return Promise.resolve();
})
.then(function() {
return repository.deleteTagByName(name);
})
.then(function() {
return Reference.lookup(repository, "refs/tags/" + name);
})
.then(function() {
return Promise.reject(new Error("the tag '" + name +
"' should not exist"));
}, function() {
return Promise.resolve();
});
});
it("can create a new lightweight tag in a repo and delete it", function() {
var oid = Oid.fromString(commitPointedTo);
var name = "created-lightweight-tag";
var repository = this.repository;
return repository.createLightweightTag(oid, name)
.then(function(reference) {
return reference.target();
})
.then(function(refOid) {
assert.equal(refOid.toString(), oid.toString());
})
.then(function() {
return repository.createLightweightTag(oid, name);
})
.then(function() {
return Promise.reject(new Error("should not be able to create the '" +
name + "' tag twice"));
}, function() {
return Promise.resolve();
})
.then(function() {
return repository.deleteTagByName(name);
})
.then(function() {
return Reference.lookup(repository, "refs/tags/" + name);
})
.then(function() {
return Promise.reject(new Error("the tag '" + name +
"' should not exist"));
}, function() {
return Promise.resolve();
});
});
it("can create a new signed tag with Tag.create and delete it", function() {
var name = "created-signed-tag-create";
var repository = this.repository;
var signature = Signature.default(repository);
var commit = null;
var commit2 = null;
return repository.getCommit(commitPointedTo)
.then(function(theCommit) {
commit = theCommit;
return repository.getCommit(commitPointedTo2);
})
.then(function(theCommit2) {
commit2 = theCommit2;
return Tag.create(repository, name, commit, signature, tagMessage, 1);
})
.then(function(oid) {
return repository.getTag(oid);
})
.then(function(tag) {
assert(tag.tagger(), signature);
return testTag(tag, name);
})
.then(function() {
// overwriting is okay
return Tag.create(repository, name, commit2, signature, tagMessage, 1);
})
.then(function() {
// overwriting is not okay
return Tag.create(repository, name, commit, signature, tagMessage, 0);
})
.then(function() {
return Promise.reject(new Error("should not be able to create the '" +
name + "' tag twice"));
}, function() {
return Promise.resolve()
.then(function() {
return repository.deleteTagByName(name);
})
.then(function() {
return Reference.lookup(repository, "refs/tags/" + name);
})
.then(function() {
return Promise.reject(new Error("the tag '" + name +
"' should not exist"));
}, function() {
return Promise.resolve();
});
});
});
it("can create a new signed tag with Tag.annotationCreate", function() {
var oid = Oid.fromString(commitPointedTo);
var name = "created-signed-tag-annotationCreate";
var repository = this.repository;
var signature = Signature.default(repository);
var odb = null;
return repository.odb()
.then(function(theOdb) {
odb = theOdb;
})
.then(function() {
return Tag.annotationCreate(
repository, name, oid, signature, tagMessage);
})
.then(function(oid) {
return odb.read(oid);
})
.then(function(object) {
assert(object.type(), Obj.TYPE.TAG);
});
});
it("can peel a tag", function() {
return this.repository.getTagByName(tagName)
.then(function(tag) {
return tag.peel();
})
.then(function(object) {
assert.equal(object.isCommit(), true);
});
});
it("can get tag's target id", function() {
return this.repository.getTagByName(tagName)
.then(function(tag) {
assert.equal(commitPointedTo, tag.targetId());
});
});
it("can get tag's owner", function() {
var repository = this.repository;
return this.repository.getTagByName(tagName)
.then(function(tag) {
var owner = tag.owner();
assert.ok(owner instanceof Repository);
assert.equal(repository.path(), owner.path());
});
});
});