forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmodule.js
More file actions
319 lines (277 loc) · 9.26 KB
/
submodule.js
File metadata and controls
319 lines (277 loc) · 9.26 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
var assert = require("assert");
var path = require("path");
var fse = require("fs-extra");
var local = path.join.bind(path, __dirname);
describe("Submodule", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var RepoUtils = require("../utils/repository_setup");
var Submodule = NodeGit.Submodule;
var repoPath = local("../repos/submodule");
beforeEach(function() {
var test = this;
return RepoUtils.createRepository(repoPath)
.then(function(repo) {
test.repository = repo;
return Repository.open(local("../repos/workdir"));
})
.then(function(repo) {
test.workdirRepository = repo;
});
});
it("can walk over the submodules", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
return repo.getSubmoduleNames()
.then(function(submodules) {
assert.equal(submodules.length, 1);
var submodule = submodules[0];
assert.equal(submodule, submoduleName);
return submodule;
})
.then(function(submodule) {
return Submodule.lookup(repo, submodule);
})
.then(function(submodule) {
assert.equal(submodule.name(), submoduleName);
});
});
it("can get submodule status", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
return Submodule.status(repo, submoduleName, Submodule.IGNORE.NONE)
.then(function(status) {
assert.equal(Submodule.STATUS.IN_CONFIG, status);
});
});
it("can get submodule location", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
return Submodule.lookup(repo, submoduleName)
.then(function(submodule) {
return submodule.location();
})
.then(function(status) {
assert.equal(Submodule.STATUS.IN_CONFIG, status);
});
});
it("can set submodule ignore", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
return Submodule.setIgnore(repo, submoduleName, Submodule.IGNORE.ALL)
.then(function() {
return Submodule.lookup(repo, submoduleName);
})
.then(function(submodule) {
assert.equal(Submodule.IGNORE.ALL, submodule.ignore());
});
});
it("can set submodule url", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
var submoduleUrl = "https://github.com/githubtraining/hellogitworld.git";
return Submodule.setUrl(repo, submoduleName, submoduleUrl)
.then(function() {
return Submodule.lookup(repo, submoduleName);
})
.then(function(submodule) {
assert.equal(submoduleUrl, submodule.url());
});
});
it("can set submodule update", function() {
var repo = this.workdirRepository;
var submoduleName = "vendor/libgit2";
return Submodule.setUpdate(repo, submoduleName, Submodule.UPDATE.NONE)
.then(function() {
return Submodule.lookup(repo, submoduleName);
})
.then(function(submodule) {
assert.equal(Submodule.UPDATE.NONE, submodule.updateStrategy());
});
});
it("can setup and finalize submodule add", function() {
this.timeout(30000);
var repo = this.repository;
var submodulePath = "nodegittest";
var submoduleUrl = "https://github.com/nodegit/test.git";
var submodule;
var submoduleRepo;
return NodeGit.Submodule.addSetup(repo, submoduleUrl, submodulePath, 0)
.then(function(_submodule) {
submodule = _submodule;
return submodule.init(0);
})
.then(function() {
return submodule.open();
})
.then(function(_submoduleRepo) {
submoduleRepo = _submoduleRepo;
return submoduleRepo.fetch("origin", null, null);
})
.then(function() {
return submoduleRepo.getReference("origin/master");
})
.then(function(reference) {
return reference.peel(NodeGit.Object.TYPE.COMMIT);
})
.then(function(commit) {
return submoduleRepo.createBranch("master", commit.id());
})
.then(function() {
return submodule.addFinalize();
})
.then(function() {
// check whether the submodule exists
return Submodule.lookup(repo, submodulePath);
})
.then(function(submodule) {
assert.equal(submodule.name(), submodulePath);
// check whether .gitmodules and the submodule are in the index
return repo.refreshIndex();
})
.then(function(index) {
var entries = index.entries();
assert.equal(entries.length, 2);
assert.equal(entries[0].path, ".gitmodules");
assert.equal(entries[1].path, submodulePath);
});
});
// THIS TEST MAKES IT FAIL
it.skip("make remove repo fail 01", function() {
this.timeout(30000);
var repo = this.repository;
var submodulePath = "nodegittest";
var submoduleUrl = "https://github.com/nodegit/test.git";
var submodule;
var submoduleRepo;
return NodeGit.Submodule.addSetup(repo, submoduleUrl, submodulePath, 0)
.then(function(_submodule) {
submodule = _submodule;
return submodule.init(0);
})
.then(function() {
return submodule.open();
})
.then(function(_submoduleRepo) {
submoduleRepo = _submoduleRepo;
return submoduleRepo.fetch("origin", null, null);
})
.then(function() {
return submoduleRepo.getReference("origin/master");
})
.then(function(reference) {
return reference.peel(NodeGit.Object.TYPE.COMMIT);
})
.then(function(commit) {
return submoduleRepo.createBranch("master", commit.id());
})
.then(function() {
return submodule.addFinalize();
})
.then(function() {
// check whether the submodule exists
return Submodule.lookup(repo, submodulePath);
})
.then(function(submodule) {
assert.equal(submodule.name(), submodulePath);
// check whether .gitmodules and the submodule are in the index
return repo.refreshIndex();
})
.then(function(index) {
var entries = index.entries();
assert.equal(entries.length, 2);
assert.equal(entries[0].path, ".gitmodules");
assert.equal(entries[1].path, submodulePath);
return fse.remove(repoPath);
})
.then(function() {
assert.equal(false, fse.existsSync(repoPath));
});
});
// THIS TEST MAKES IT FAIL
it.skip("make remove repo fail 02", function() {
this.timeout(30000);
var repo = this.repository;
var submodulePath = "nodegittest";
var submoduleUrl = "https://github.com/nodegit/test.git";
var submodule;
var submoduleRepo;
return NodeGit.Submodule.addSetup(repo, submoduleUrl, submodulePath, 0)
.then(function(_submodule) {
submodule = _submodule;
return submodule.init(0);
})
.then(function() {
return submodule.open();
})
.then(function(_submoduleRepo) {
submoduleRepo = _submoduleRepo;
return submoduleRepo.fetch("origin", null, null);
})
.then(function() {
return repo.refreshIndex();
})
.then(function(index) {
return fse.remove(repoPath);
})
.then(function() {
assert.equal(false, fse.existsSync(repoPath));
});
});
// THIS TEST MAKES IT FAIL
it.only("make remove repo fail 03", function() {
this.timeout(30000);
var repo = this.repository;
var submodulePath = "nodegittest";
var submoduleUrl = "https://github.com/nodegit/test.git";
var submodule;
var submoduleRepo;
return NodeGit.Submodule.addSetup(repo, submoduleUrl, submodulePath, 0)
.then(function(_submodule) {
submodule = _submodule;
return submodule.init(0);
})
.then(function() {
return submodule.open();
})
.then(function(_submoduleRepo) {
submoduleRepo = _submoduleRepo;
return submoduleRepo.fetch("origin", null, null);
})
.then(function() {
return fse.remove(repoPath);
})
.then(function() {
assert.equal(false, fse.existsSync(repoPath));
});
});
it("can run sync callback without deadlocking", function() {
var repo = this.workdirRepository;
var submodules = [];
var submoduleCallback = function(submodule, name, payload) {
var submoduleName = submodule.name();
assert.equal(submoduleName, name);
submodules.push(name);
};
return Submodule.foreach(repo, submoduleCallback).then(function() {
assert.equal(submodules.length, 1);
});
});
// 'Submodule.foreach' and 'Submodule.lookup' do work with the repo locked.
// They should work together without deadlocking.
it("can run async callback without deadlocking", function() {
var repo = this.workdirRepository;
var submodules = [];
var submoduleCallback = function(submodule, name, payload) {
var owner = submodule.owner();
return Submodule.lookup(owner, name)
.then(function(submodule) {
assert.equal(submodule.name(), name);
submodules.push(name);
});
};
return Submodule.foreach(repo, submoduleCallback).then(function() {
assert.equal(submodules.length, 1);
});
});
});