1 | fs = require "fs"
|
2 | path = require "path"
|
3 |
|
4 | should = require "should"
|
5 | uuid = require "uuid"
|
6 |
|
7 | HGRepo = require "../lib/HGRepo"
|
8 | Parsers = require "../lib/parsers"
|
9 |
|
10 | describe "HGRepo", ->
|
11 |
|
12 | it "can create a temporary repo", (done) ->
|
13 | HGRepo.MakeTempRepo (err, repo) ->
|
14 | throw err if err
|
15 |
|
16 | should.exist repo
|
17 |
|
18 | fs.exists repo.path, (exists) ->
|
19 | exists.should.equal true
|
20 |
|
21 | done()
|
22 |
|
23 | it "can init a new repo", (done) ->
|
24 | HGRepo.MakeTempRepo (err, repo) ->
|
25 | throw err if err
|
26 |
|
27 | newRepoPath = path.resolve path.join(repo.path, "..", uuid.v1())
|
28 |
|
29 | repo.init newRepoPath, (err, output) ->
|
30 | throw err if err
|
31 |
|
32 | should.exist output
|
33 |
|
34 | otherRepo = new HGRepo(newRepoPath)
|
35 |
|
36 | otherRepo.summary (err, output) ->
|
37 | throw err if err
|
38 |
|
39 | should.exist output
|
40 |
|
41 | done()
|
42 |
|
43 | it "can add files to a repo", (done) ->
|
44 | HGRepo.MakeTempRepo (err, repo) ->
|
45 |
|
46 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
47 | throw err if err
|
48 |
|
49 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
50 | throw err if err
|
51 |
|
52 | repo.add ['.'], (err, output) ->
|
53 | throw err if err
|
54 |
|
55 | output.length.should.equal 3
|
56 |
|
57 | done()
|
58 |
|
59 | it "can commit changes to a repo", (done) ->
|
60 | HGRepo.MakeTempRepo (err, repo) ->
|
61 |
|
62 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
63 | throw err if err
|
64 |
|
65 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
66 | throw err if err
|
67 |
|
68 | repo.add ['.'], (err, output) ->
|
69 | throw err if err
|
70 |
|
71 | output.length.should.equal 3
|
72 |
|
73 | commitOpts =
|
74 | "-m": "A Test Commit"
|
75 |
|
76 | repo.commit commitOpts, (err, output) ->
|
77 | throw err if err
|
78 |
|
79 | should.exist output
|
80 | output.length.should.equal 1
|
81 | output[0].channel.should.equal "r"
|
82 |
|
83 | repo.log (err, output) ->
|
84 | throw err if err
|
85 |
|
86 | output.length.should.be.above 0
|
87 | output[0].body.indexOf("A Test Commit").should.be.above -1
|
88 |
|
89 | done()
|
90 |
|
91 | it "can commit specific files", (done) ->
|
92 | HGRepo.MakeTempRepo (err, repo) ->
|
93 |
|
94 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
95 | throw err if err
|
96 |
|
97 | repo.add ['.'], (err, output) ->
|
98 | throw err if err
|
99 |
|
100 | commitOpts = ["-m", "A Test Commit"]
|
101 |
|
102 | repo.commit "one.txt", commitOpts, (err, output) ->
|
103 | throw err if err
|
104 |
|
105 | should.exist output
|
106 | output.length.should.equal 1
|
107 | output[0].channel.should.equal "r"
|
108 |
|
109 | done()
|
110 |
|
111 | it "can clone a repo from a local path", (done) ->
|
112 | HGRepo.MakeTempRepo (err, repo) ->
|
113 |
|
114 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
115 | throw err if err
|
116 |
|
117 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
118 | throw err if err
|
119 |
|
120 | repo.add ['.'], (err, output) ->
|
121 | throw err if err
|
122 |
|
123 | output.length.should.equal 3
|
124 |
|
125 | commitOpts =
|
126 | "-m": "A Test Commit"
|
127 |
|
128 | repo.commit commitOpts, (err, output) ->
|
129 | throw err if err
|
130 |
|
131 | should.exist output
|
132 |
|
133 | otherPath = path.resolve(path.join(repo.path, "..", uuid.v1()))
|
134 |
|
135 | repo.clone repo.path, otherPath, (err, output) ->
|
136 | throw err if err
|
137 |
|
138 | should.exist output
|
139 |
|
140 | otherRepo = new HGRepo(otherPath)
|
141 |
|
142 | otherRepo.summary (err, output) ->
|
143 | throw err if err
|
144 |
|
145 | should.exist output
|
146 |
|
147 | done()
|
148 |
|
149 | it "can clone a repo from a remote path", (done) ->
|
150 |
|
151 | @timeout 5000
|
152 |
|
153 | HGRepo.MakeTempRepo (err, repo) ->
|
154 |
|
155 | otherPath = path.resolve(path.join(repo.path, "..", uuid.v1()))
|
156 |
|
157 | repo.clone "https://bitbucket.org/jacob4u2/node-hg", otherPath, (err, output) ->
|
158 | throw err if err
|
159 |
|
160 | should.exist output
|
161 |
|
162 | otherRepo = new HGRepo(otherPath)
|
163 |
|
164 | otherRepo.summary (err, output) ->
|
165 | throw err if err
|
166 |
|
167 | should.exist output
|
168 |
|
169 | done()
|
170 |
|
171 | it "can pull changes from another repo", (done) ->
|
172 | HGRepo.MakeTempRepo (err, repo) ->
|
173 |
|
174 | otherPath = path.resolve(path.join(repo.path, "..", uuid.v1()))
|
175 |
|
176 | repo.clone repo.path, otherPath, (err, output) ->
|
177 | throw err if err
|
178 |
|
179 | should.exist output
|
180 |
|
181 | otherRepo = new HGRepo(otherPath)
|
182 |
|
183 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
184 | throw err if err
|
185 |
|
186 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
187 | throw err if err
|
188 |
|
189 | repo.add ['.'], (err, output) ->
|
190 | throw err if err
|
191 |
|
192 | output.length.should.equal 3
|
193 |
|
194 | commitOpts =
|
195 | "-m": "A Test Commit"
|
196 |
|
197 | repo.commit commitOpts, (err, output) ->
|
198 | throw err if err
|
199 |
|
200 | should.exist output
|
201 |
|
202 | otherRepo.pull repo.path, (err, output) ->
|
203 | throw err if err
|
204 |
|
205 | should.exist output
|
206 |
|
207 | otherRepo.update (err, output) ->
|
208 | throw err if err
|
209 |
|
210 | should.exist output
|
211 |
|
212 | done()
|
213 |
|
214 | it "can push changes to another repo", (done) ->
|
215 | HGRepo.MakeTempRepo (err, repo) ->
|
216 |
|
217 | otherPath = path.resolve(path.join(repo.path, "..", uuid.v1()))
|
218 |
|
219 | repo.clone repo.path, otherPath, (err, output) ->
|
220 | throw err if err
|
221 |
|
222 | should.exist output
|
223 |
|
224 | otherRepo = new HGRepo(otherPath)
|
225 |
|
226 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
227 | throw err if err
|
228 |
|
229 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
230 | throw err if err
|
231 |
|
232 | repo.add ['.'], (err, output) ->
|
233 | throw err if err
|
234 |
|
235 | output.length.should.equal 3
|
236 |
|
237 | commitOpts =
|
238 | "-m": "A Test Commit"
|
239 |
|
240 | repo.commit commitOpts, (err, output) ->
|
241 | throw err if err
|
242 |
|
243 | should.exist output
|
244 |
|
245 | repo.push otherRepo.path, (err, output) ->
|
246 | throw err if err
|
247 |
|
248 | should.exist output
|
249 |
|
250 | otherRepo.update (err, output) ->
|
251 | throw err if err
|
252 |
|
253 | should.exist output
|
254 |
|
255 | otherRepo.summary (err, output) ->
|
256 | throw err if err
|
257 |
|
258 | should.exist output
|
259 |
|
260 | done()
|
261 |
|
262 | it "can merge changes between two repos", (done) ->
|
263 | HGRepo.MakeTempRepo (err, repo) ->
|
264 |
|
265 | otherPath = path.resolve(path.join(repo.path, "..", uuid.v1()))
|
266 |
|
267 | repo.clone repo.path, otherPath, (err, output) ->
|
268 | throw err if err
|
269 |
|
270 | should.exist output
|
271 |
|
272 | otherRepo = new HGRepo(otherPath)
|
273 | fileOne = path.join(repo.path, "one.txt")
|
274 |
|
275 | fs.writeFile fileOne, "Text Content 1", (err) ->
|
276 | throw err if err
|
277 |
|
278 | fs.writeFile path.join(repo.path, "two.txt"), "Text Content 2", (err) ->
|
279 | throw err if err
|
280 |
|
281 | repo.add ['.'], (err, output) ->
|
282 | throw err if err
|
283 |
|
284 | output.length.should.equal 3
|
285 |
|
286 | commitOpts =
|
287 | "-m": "A Test Commit"
|
288 |
|
289 | repo.commit commitOpts, (err, output) ->
|
290 | throw err if err
|
291 |
|
292 | should.exist output
|
293 |
|
294 | otherRepo.pull repo.path, (err, output) ->
|
295 | throw err if err
|
296 |
|
297 | should.exist output
|
298 |
|
299 | otherRepo.update (err, output) ->
|
300 | throw err if err
|
301 |
|
302 | should.exist output
|
303 |
|
304 | otherFileOne = path.join(otherRepo.path, "one.txt")
|
305 |
|
306 | fs.appendFileSync otherFileOne, "\nSome More Text on Line 2"
|
307 | fs.writeFileSync fileOne, "Some Changes on Line 1\n"
|
308 |
|
309 | commitOpts =
|
310 | "-m": "Repo One Update"
|
311 |
|
312 | repo.commit commitOpts, (err, output) ->
|
313 | throw err if err
|
314 |
|
315 | should.exist output
|
316 |
|
317 | commitOpts =
|
318 | "-m": "Repo Two Update"
|
319 |
|
320 | otherRepo.commit commitOpts, (err, output) ->
|
321 | throw err if err
|
322 |
|
323 | should.exist output
|
324 |
|
325 | otherRepo.pull repo.path, (err, output) ->
|
326 | throw err if err
|
327 |
|
328 | should.exist output
|
329 |
|
330 | otherRepo.merge (err, output) ->
|
331 | throw err if err
|
332 |
|
333 | should.exist output
|
334 |
|
335 | resolveOpts =
|
336 | "--list": ""
|
337 |
|
338 | otherRepo.resolve resolveOpts, (err, output) ->
|
339 | throw err if err
|
340 |
|
341 | should.exist output
|
342 | output.length.should.be.above 1
|
343 |
|
344 | resolveOpts =
|
345 | "-m": "one.txt"
|
346 |
|
347 | otherRepo.resolve resolveOpts, (err, output) ->
|
348 | throw err if err
|
349 |
|
350 | should.exist output
|
351 |
|
352 | otherRepo.commit {"-m": "Merging from one"}, (err, output) ->
|
353 | throw err if err
|
354 |
|
355 | should.exist output
|
356 |
|
357 |
|
358 | done()
|
359 |
|
360 | it "can read and write tags", (done) ->
|
361 | HGRepo.MakeTempRepo (err, repo) ->
|
362 |
|
363 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
364 | throw err if err
|
365 |
|
366 | repo.add ['.'], (err, output) ->
|
367 | throw err if err
|
368 |
|
369 | commitOpts =
|
370 | "-m": "A Test Commit"
|
371 |
|
372 | repo.commit commitOpts, (err, output) ->
|
373 | throw err if err
|
374 |
|
375 | repo.tag 'a-tag', (err, output) ->
|
376 | throw err if err
|
377 |
|
378 | repo.tags (err, output) ->
|
379 | throw err if err
|
380 |
|
381 | should.exist output
|
382 |
|
383 | output[3].body.should.equal('a-tag')
|
384 | done()
|
385 |
|
386 | it "can show repo status", (done) ->
|
387 | HGRepo.MakeTempRepo (err, repo) ->
|
388 |
|
389 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
390 | throw err if err
|
391 |
|
392 | repo.status '-A', (err, output) ->
|
393 | throw err if err
|
394 |
|
395 | should.exist output
|
396 | output.length.should.be.above 2
|
397 |
|
398 | done()
|
399 |
|
400 | it "can show repo heads", (done) ->
|
401 | HGRepo.MakeTempRepo (err, repo) ->
|
402 |
|
403 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
404 | throw err if err
|
405 |
|
406 | repo.add ['.'], (err, output) ->
|
407 | throw err if err
|
408 |
|
409 | repo.commit {"-m": "Testing heads"}, (err, output) ->
|
410 | throw err if err
|
411 |
|
412 | repo.heads (err, output) ->
|
413 | throw err if err
|
414 |
|
415 | should.exist output
|
416 | output.length.should.be.above 4
|
417 |
|
418 | done()
|
419 |
|
420 | it "can show repo branches", (done) ->
|
421 | HGRepo.MakeTempRepo (err, repo) ->
|
422 |
|
423 | fs.writeFile path.join(repo.path, "one.txt"), "Text Content 1", (err) ->
|
424 | throw err if err
|
425 |
|
426 | repo.add ['.'], (err, output) ->
|
427 | throw err if err
|
428 |
|
429 | repo.commit {"-m": "Testing branches"}, (err, output) ->
|
430 | throw err if err
|
431 |
|
432 | repo.branches (err, output) ->
|
433 | throw err if err
|
434 | should.exist output
|
435 | output.length.should.be.above 3
|
436 |
|
437 | done()
|
438 |
|
439 | it "can generate diff", (done) ->
|
440 | HGRepo.MakeTempRepo (err, repo) ->
|
441 |
|
442 | fileOne = path.join(repo.path, "one.txt")
|
443 | fs.writeFile fileOne, "Text Content 1", (err) ->
|
444 | throw err if err
|
445 |
|
446 | repo.add ['.'], (err, output) ->
|
447 | throw err if err
|
448 |
|
449 | repo.commit {"-m": "Testing diff"}, (err, output) ->
|
450 | throw err if err
|
451 |
|
452 | fs.writeFileSync fileOne, "Some Changes on Line 1\n"
|
453 |
|
454 | repo.diff (err, output) ->
|
455 | throw err if err
|
456 | should.exist output
|
457 | diff = Parsers.text output
|
458 | diff.should.match /diff \-r .* one.txt/mg
|
459 | diff.should.match /\-\-\- a\/one\.txt/mg
|
460 | diff.should.match /\+\+\+ b\/one\.txt/mg
|
461 |
|
462 | done()
|