1
|
|
|
# pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned,no-member |
2
|
|
|
|
3
|
|
|
import inspect |
4
|
|
|
import os |
5
|
|
|
import shutil |
6
|
|
|
from contextlib import suppress |
7
|
|
|
|
8
|
|
|
import log |
9
|
|
|
import pytest |
10
|
|
|
from expecter import expect |
11
|
|
|
from freezegun import freeze_time |
12
|
|
|
|
13
|
|
|
import gitman |
14
|
|
|
from gitman import shell |
15
|
|
|
from gitman.exceptions import InvalidConfig, InvalidRepository, UncommittedChanges |
16
|
|
|
from gitman.models import Config |
17
|
|
|
|
18
|
|
|
from .utilities import strip |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__))) |
22
|
|
|
TMP = os.path.join(ROOT, 'tmp') |
23
|
|
|
|
24
|
|
|
CONFIG = """ |
25
|
|
|
location: deps |
26
|
|
|
sources: |
27
|
|
|
- name: gitman_1 |
28
|
|
|
type: git |
29
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
30
|
|
|
sparse_paths: |
31
|
|
|
- |
32
|
|
|
rev: example-branch |
33
|
|
|
link: |
34
|
|
|
scripts: |
35
|
|
|
- |
36
|
|
|
- name: gitman_2 |
37
|
|
|
type: git |
38
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
39
|
|
|
sparse_paths: |
40
|
|
|
- |
41
|
|
|
rev: example-tag |
42
|
|
|
link: |
43
|
|
|
scripts: |
44
|
|
|
- |
45
|
|
|
- name: gitman_3 |
46
|
|
|
type: git |
47
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
48
|
|
|
sparse_paths: |
49
|
|
|
- |
50
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
51
|
|
|
link: |
52
|
|
|
scripts: |
53
|
|
|
- |
54
|
|
|
""".lstrip() |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
@pytest.yield_fixture |
58
|
|
|
def config(): |
59
|
|
|
log.info("Temporary directory: %s", TMP) |
60
|
|
|
|
61
|
|
|
with suppress(FileNotFoundError, PermissionError): |
62
|
|
|
shutil.rmtree(TMP) |
63
|
|
|
with suppress(FileExistsError): |
64
|
|
|
os.makedirs(TMP) |
65
|
|
|
os.chdir(TMP) |
66
|
|
|
|
67
|
|
|
os.system("touch .git") |
68
|
|
|
config = Config(root=TMP) |
69
|
|
|
config.datafile.text = CONFIG |
70
|
|
|
config.datafile.load() |
71
|
|
|
|
72
|
|
|
log.debug("File listing: %s", os.listdir(TMP)) |
73
|
|
|
|
74
|
|
|
yield config |
75
|
|
|
|
76
|
|
|
os.chdir(ROOT) |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
def describe_init(): |
80
|
|
|
@pytest.mark.xfail |
81
|
|
|
def it_creates_a_new_config_file(tmpdir): |
82
|
|
|
tmpdir.chdir() |
83
|
|
|
|
84
|
|
|
expect(gitman.init()) == True |
85
|
|
|
|
86
|
|
|
expect(Config().datafile.text) == strip( |
87
|
|
|
""" |
88
|
|
|
location: gitman_sources |
89
|
|
|
sources: |
90
|
|
|
- name: sample_dependency |
91
|
|
|
type: git |
92
|
|
|
repo: https://github.com/githubtraining/hellogitworld |
93
|
|
|
sparse_paths: |
94
|
|
|
- |
95
|
|
|
rev: master |
96
|
|
|
link: |
97
|
|
|
scripts: |
98
|
|
|
- |
99
|
|
|
sources_locked: |
100
|
|
|
- name: sample_dependency |
101
|
|
|
type: git |
102
|
|
|
repo: https://github.com/githubtraining/hellogitworld |
103
|
|
|
sparse_paths: |
104
|
|
|
- |
105
|
|
|
rev: ebbbf773431ba07510251bb03f9525c7bab2b13a |
106
|
|
|
link: |
107
|
|
|
scripts: |
108
|
|
|
- |
109
|
|
|
groups: |
110
|
|
|
- |
111
|
|
|
""" |
112
|
|
|
) |
113
|
|
|
|
114
|
|
|
def it_does_not_modify_existing_config_file(config): |
115
|
|
|
expect(gitman.init()) == False |
116
|
|
|
|
117
|
|
|
expect(config.datafile.text) == CONFIG |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
def describe_install(): |
121
|
|
|
def it_creates_missing_directories(config): |
122
|
|
|
shell.rm(config.location) |
123
|
|
|
|
124
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
125
|
|
|
|
126
|
|
|
expect(os.listdir(config.location)) == ['gitman_1'] |
127
|
|
|
|
128
|
|
|
def it_should_not_modify_config(config): |
129
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
130
|
|
|
|
131
|
|
|
expect(config.datafile.text) == CONFIG |
132
|
|
|
|
133
|
|
|
def it_merges_sources(config): |
134
|
|
|
config.datafile.text = strip( |
135
|
|
|
""" |
136
|
|
|
location: deps |
137
|
|
|
sources: |
138
|
|
|
- name: gitman_1 |
139
|
|
|
type: git |
140
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
141
|
|
|
rev: example-branch |
142
|
|
|
link: |
143
|
|
|
scripts: |
144
|
|
|
- |
145
|
|
|
sources_locked: |
146
|
|
|
- name: gitman_2 |
147
|
|
|
type: git |
148
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
149
|
|
|
rev: example-branch |
150
|
|
|
link: |
151
|
|
|
scripts: |
152
|
|
|
- |
153
|
|
|
- name: gitman_3 |
154
|
|
|
type: git |
155
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
156
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
157
|
|
|
link: |
158
|
|
|
scripts: |
159
|
|
|
- |
160
|
|
|
""" |
161
|
|
|
) |
162
|
|
|
config.datafile.load() |
163
|
|
|
|
164
|
|
|
expect(gitman.install(depth=1)) == True |
165
|
|
|
|
166
|
|
|
expect(len(os.listdir(config.location))) == 3 |
167
|
|
|
|
168
|
|
|
def it_can_handle_missing_locked_sources(config): |
169
|
|
|
config.datafile.text = strip( |
170
|
|
|
""" |
171
|
|
|
location: deps |
172
|
|
|
sources: |
173
|
|
|
- name: gitman_1 |
174
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
175
|
|
|
rev: example-branch |
176
|
|
|
link: |
177
|
|
|
scripts: |
178
|
|
|
- |
179
|
|
|
sources_locked: |
180
|
|
|
- name: gitman_2 |
181
|
|
|
type: git |
182
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
183
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
184
|
|
|
link: |
185
|
|
|
scripts: |
186
|
|
|
- |
187
|
|
|
""" |
188
|
|
|
) |
189
|
|
|
config.datafile.load() |
190
|
|
|
|
191
|
|
|
expect(gitman.install('gitman_1', depth=1)) == True |
192
|
|
|
|
193
|
|
|
expect(os.listdir(config.location)) == ['gitman_1'] |
194
|
|
|
|
195
|
|
|
def it_detects_invalid_repositories(config): |
196
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".git")) |
197
|
|
|
shell.mkdir(os.path.join("deps", "gitman_1", ".git")) |
198
|
|
|
|
199
|
|
|
try: |
200
|
|
|
with pytest.raises(InvalidRepository): |
201
|
|
|
expect(gitman.install('gitman_1', depth=1)) == False |
202
|
|
|
|
203
|
|
|
finally: |
204
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
205
|
|
|
|
206
|
|
|
def describe_links(): |
207
|
|
|
@pytest.fixture |
208
|
|
|
def config_with_link(config): |
209
|
|
|
config.datafile.text = strip( |
210
|
|
|
""" |
211
|
|
|
location: deps |
212
|
|
|
sources: |
213
|
|
|
- name: gitman_1 |
214
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
215
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
216
|
|
|
link: my_link |
217
|
|
|
scripts: |
218
|
|
|
- |
219
|
|
|
""" |
220
|
|
|
) |
221
|
|
|
config.datafile.load() |
222
|
|
|
|
223
|
|
|
return config |
224
|
|
|
|
225
|
|
|
def it_should_create_links(config_with_link): |
226
|
|
|
expect(gitman.install(depth=1)) == True |
227
|
|
|
|
228
|
|
|
expect(os.listdir()).contains('my_link') |
229
|
|
|
|
230
|
|
|
def it_should_not_overwrite_files(config_with_link): |
231
|
|
|
os.system("touch my_link") |
232
|
|
|
|
233
|
|
|
with pytest.raises(RuntimeError): |
234
|
|
|
gitman.install(depth=1) |
235
|
|
|
|
236
|
|
|
def it_overwrites_files_with_force(config_with_link): |
237
|
|
|
os.system("touch my_link") |
238
|
|
|
|
239
|
|
|
expect(gitman.install(depth=1, force=True)) == True |
240
|
|
|
|
241
|
|
|
def describe_scripts(): |
242
|
|
|
@pytest.fixture |
243
|
|
|
def config_with_scripts(config): |
244
|
|
|
config.datafile.text = strip( |
245
|
|
|
""" |
246
|
|
|
location: deps |
247
|
|
|
sources: |
248
|
|
|
- name: gitman_1 |
249
|
|
|
type: git |
250
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
251
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
252
|
|
|
link: |
253
|
|
|
scripts: |
254
|
|
|
- make foobar |
255
|
|
|
""" |
256
|
|
|
) |
257
|
|
|
config.datafile.load() |
258
|
|
|
|
259
|
|
|
return config |
260
|
|
|
|
261
|
|
|
def it_detects_failures_in_scripts(config_with_scripts): |
262
|
|
|
with pytest.raises(RuntimeError): |
263
|
|
|
expect(gitman.install()) |
264
|
|
|
|
265
|
|
|
def script_failures_can_be_ignored(config_with_scripts): |
266
|
|
|
expect(gitman.install(force=True)) == True |
267
|
|
|
|
268
|
|
|
def describe_sparse_paths(): |
269
|
|
|
@pytest.fixture |
270
|
|
|
def config_with_scripts(config): |
271
|
|
|
config.datafile.text = strip( |
272
|
|
|
""" |
273
|
|
|
location: deps |
274
|
|
|
sources: |
275
|
|
|
- name: gitman_1 |
276
|
|
|
type: git |
277
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
278
|
|
|
sparse_paths: |
279
|
|
|
- src/* |
280
|
|
|
rev: ddbe17ef173538d1fda29bd99a14bab3c5d86e78 |
281
|
|
|
link: |
282
|
|
|
scripts: |
283
|
|
|
- |
284
|
|
|
""" |
285
|
|
|
) |
286
|
|
|
config.datafile.load() |
287
|
|
|
|
288
|
|
|
return config |
289
|
|
|
|
290
|
|
|
def it_successfully_materializes_the_repo(config): |
291
|
|
|
expect(gitman.install(depth=1, force=True)) == True |
292
|
|
|
dir_listing = os.listdir(os.path.join(config.location, "gitman_1")) |
293
|
|
|
expect(dir_listing).contains('src') |
294
|
|
|
|
295
|
|
|
def it_contains_only_the_sparse_paths(config): |
296
|
|
|
expect(gitman.install(depth=1, force=True)) == True |
297
|
|
|
dir_listing = os.listdir(os.path.join(config.location, "gitman_1")) |
298
|
|
|
expect(dir_listing).contains('src') |
299
|
|
|
expect(len(dir_listing) == 1) |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
def describe_uninstall(): |
303
|
|
|
def it_deletes_dependencies_when_they_exist(config): |
304
|
|
|
gitman.install('gitman_1', depth=1) |
305
|
|
|
expect(os.path.isdir(config.location)) == True |
306
|
|
|
|
307
|
|
|
expect(gitman.uninstall()) == True |
308
|
|
|
|
309
|
|
|
expect(os.path.exists(config.location)) == False |
310
|
|
|
|
311
|
|
|
def it_should_not_fail_when_no_dependencies_exist(config): |
312
|
|
|
expect(os.path.isdir(config.location)) == False |
313
|
|
|
|
314
|
|
|
expect(gitman.uninstall()) == True |
315
|
|
|
|
316
|
|
|
def it_deletes_the_log_file(config): |
317
|
|
|
gitman.install('gitman_1', depth=1) |
318
|
|
|
gitman.list() |
319
|
|
|
expect(os.path.exists(config.log_path)) == True |
320
|
|
|
|
321
|
|
|
gitman.uninstall() |
322
|
|
|
expect(os.path.exists(config.log_path)) == False |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
def describe_keep_location(): |
326
|
|
|
def it_deletes_dependencies_when_they_exist(config): |
327
|
|
|
gitman.install('gitman_1', depth=1) |
328
|
|
|
expect(os.path.isdir(config.location)) == True |
329
|
|
|
|
330
|
|
|
expect(gitman.uninstall(keep_location=True)) == True |
331
|
|
|
|
332
|
|
|
path = os.path.join(config.location, 'gitman_1') |
333
|
|
|
expect(os.path.exists(path)) == False |
334
|
|
|
|
335
|
|
|
expect(os.path.exists(config.location)) == True |
336
|
|
|
|
337
|
|
|
gitman.uninstall() |
338
|
|
|
|
339
|
|
|
def it_should_not_fail_when_no_dependencies_exist(config): |
340
|
|
|
expect(os.path.isdir(config.location)) == False |
341
|
|
|
|
342
|
|
|
expect(gitman.uninstall(keep_location=True)) == True |
343
|
|
|
|
344
|
|
|
gitman.uninstall() |
345
|
|
|
|
346
|
|
|
def it_deletes_the_log_file(config): |
347
|
|
|
gitman.install('gitman_1', depth=1) |
348
|
|
|
gitman.list() |
349
|
|
|
expect(os.path.exists(config.log_path)) == True |
350
|
|
|
|
351
|
|
|
gitman.uninstall(keep_location=True) |
352
|
|
|
expect(os.path.exists(config.log_path)) == False |
353
|
|
|
|
354
|
|
|
gitman.uninstall() |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
def describe_update(): |
358
|
|
|
def it_should_not_modify_config(config): |
359
|
|
|
gitman.update('gitman_1', depth=1) |
360
|
|
|
|
361
|
|
|
expect(config.datafile.text) == CONFIG |
362
|
|
|
|
363
|
|
|
@pytest.mark.xfail |
364
|
|
|
def it_locks_previously_locked_dependencies(config): |
365
|
|
|
config.datafile.text = strip( |
366
|
|
|
""" |
367
|
|
|
location: deps |
368
|
|
|
sources: |
369
|
|
|
- name: gitman_1 |
370
|
|
|
type: git |
371
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
372
|
|
|
sparse_paths: |
373
|
|
|
- |
374
|
|
|
rev: example-branch |
375
|
|
|
link: |
376
|
|
|
scripts: |
377
|
|
|
- |
378
|
|
|
- name: gitman_2 |
379
|
|
|
type: git |
380
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
381
|
|
|
sparse_paths: |
382
|
|
|
- |
383
|
|
|
rev: example-tag |
384
|
|
|
link: |
385
|
|
|
scripts: |
386
|
|
|
- |
387
|
|
|
sources_locked: |
388
|
|
|
- name: gitman_2 |
389
|
|
|
type: git |
390
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
391
|
|
|
sparse_paths: |
392
|
|
|
- |
393
|
|
|
rev: (old revision) |
394
|
|
|
link: |
395
|
|
|
scripts: |
396
|
|
|
- |
397
|
|
|
groups: [] |
398
|
|
|
""" |
399
|
|
|
) |
400
|
|
|
config.datafile.load() |
401
|
|
|
|
402
|
|
|
gitman.update(depth=1) |
403
|
|
|
|
404
|
|
|
expect(config.datafile.text) == strip( |
405
|
|
|
""" |
406
|
|
|
location: deps |
407
|
|
|
sources: |
408
|
|
|
- name: gitman_1 |
409
|
|
|
type: git |
410
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
411
|
|
|
sparse_paths: |
412
|
|
|
- |
413
|
|
|
rev: example-branch |
414
|
|
|
link: |
415
|
|
|
scripts: |
416
|
|
|
- |
417
|
|
|
- name: gitman_2 |
418
|
|
|
type: git |
419
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
420
|
|
|
sparse_paths: |
421
|
|
|
- |
422
|
|
|
rev: example-tag |
423
|
|
|
link: |
424
|
|
|
scripts: |
425
|
|
|
- |
426
|
|
|
sources_locked: |
427
|
|
|
- name: gitman_2 |
428
|
|
|
type: git |
429
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
430
|
|
|
sparse_paths: |
431
|
|
|
- |
432
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
433
|
|
|
link: |
434
|
|
|
scripts: |
435
|
|
|
- |
436
|
|
|
groups: [] |
437
|
|
|
""" |
438
|
|
|
) |
439
|
|
|
|
440
|
|
|
@pytest.mark.xfail |
441
|
|
|
def it_should_not_lock_dependencies_when_disabled(config): |
442
|
|
|
config.datafile.text = strip( |
443
|
|
|
""" |
444
|
|
|
location: deps |
445
|
|
|
sources: |
446
|
|
|
- name: gitman_1 |
447
|
|
|
type: git |
448
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
449
|
|
|
sparse_paths: |
450
|
|
|
- |
451
|
|
|
rev: example-branch |
452
|
|
|
link: |
453
|
|
|
scripts: |
454
|
|
|
- |
455
|
|
|
- name: gitman_2 |
456
|
|
|
type: git |
457
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
458
|
|
|
sparse_paths: |
459
|
|
|
- |
460
|
|
|
rev: example-tag |
461
|
|
|
link: |
462
|
|
|
scripts: |
463
|
|
|
- |
464
|
|
|
sources_locked: |
465
|
|
|
- name: gitman_2 |
466
|
|
|
type: git |
467
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
468
|
|
|
sparse_paths: |
469
|
|
|
- |
470
|
|
|
rev: (old revision) |
471
|
|
|
link: |
472
|
|
|
scripts: |
473
|
|
|
- |
474
|
|
|
groups: [] |
475
|
|
|
""" |
476
|
|
|
) |
477
|
|
|
config.datafile.load() |
478
|
|
|
|
479
|
|
|
gitman.update(depth=1, lock=False) |
480
|
|
|
|
481
|
|
|
expect(config.datafile.text) == strip( |
482
|
|
|
""" |
483
|
|
|
location: deps |
484
|
|
|
sources: |
485
|
|
|
- name: gitman_1 |
486
|
|
|
type: git |
487
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
488
|
|
|
sparse_paths: |
489
|
|
|
- |
490
|
|
|
rev: example-branch |
491
|
|
|
link: |
492
|
|
|
scripts: |
493
|
|
|
- |
494
|
|
|
- name: gitman_2 |
495
|
|
|
type: git |
496
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
497
|
|
|
sparse_paths: |
498
|
|
|
- |
499
|
|
|
rev: example-tag |
500
|
|
|
link: |
501
|
|
|
scripts: |
502
|
|
|
- |
503
|
|
|
sources_locked: |
504
|
|
|
- name: gitman_2 |
505
|
|
|
type: git |
506
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
507
|
|
|
sparse_paths: |
508
|
|
|
- |
509
|
|
|
rev: (old revision) |
510
|
|
|
link: |
511
|
|
|
scripts: |
512
|
|
|
- |
513
|
|
|
groups: [] |
514
|
|
|
""" |
515
|
|
|
) |
516
|
|
|
|
517
|
|
|
def it_should_not_allow_source_and_group_name_conflicts(config): |
518
|
|
|
config.datafile.text = strip( |
519
|
|
|
""" |
520
|
|
|
location: deps |
521
|
|
|
sources: |
522
|
|
|
- name: gitman_1 |
523
|
|
|
type: git |
524
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
525
|
|
|
rev: example-branch |
526
|
|
|
- name: gitman_2 |
527
|
|
|
type: git |
528
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
529
|
|
|
rev: example-branch |
530
|
|
|
groups: |
531
|
|
|
- name: gitman_1 |
532
|
|
|
members: |
533
|
|
|
- gitman_1 |
534
|
|
|
- gitman_2 |
535
|
|
|
""" |
536
|
|
|
) |
537
|
|
|
config.datafile.load() |
538
|
|
|
|
539
|
|
|
with pytest.raises(InvalidConfig): |
540
|
|
|
gitman.update(depth=1, lock=True) |
541
|
|
|
|
542
|
|
|
@pytest.mark.xfail |
543
|
|
|
def it_locks_previously_locked_dependencies_by_group_name(config): |
544
|
|
|
config.datafile.text = strip( |
545
|
|
|
""" |
546
|
|
|
location: deps |
547
|
|
|
sources: |
548
|
|
|
- name: gitman_1 |
549
|
|
|
type: git |
550
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
551
|
|
|
sparse_paths: |
552
|
|
|
- |
553
|
|
|
rev: example-branch |
554
|
|
|
link: |
555
|
|
|
scripts: |
556
|
|
|
- |
557
|
|
|
- name: gitman_2 |
558
|
|
|
type: git |
559
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
560
|
|
|
sparse_paths: |
561
|
|
|
- |
562
|
|
|
rev: example-tag |
563
|
|
|
link: |
564
|
|
|
scripts: |
565
|
|
|
- |
566
|
|
|
- name: gitman_3 |
567
|
|
|
type: git |
568
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
569
|
|
|
sparse_paths: |
570
|
|
|
- |
571
|
|
|
rev: example-tag |
572
|
|
|
link: |
573
|
|
|
scripts: |
574
|
|
|
- |
575
|
|
|
sources_locked: |
576
|
|
|
- name: gitman_1 |
577
|
|
|
type: git |
578
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
579
|
|
|
sparse_paths: |
580
|
|
|
- |
581
|
|
|
rev: (old revision) |
582
|
|
|
link: |
583
|
|
|
scripts: |
584
|
|
|
- |
585
|
|
|
- name: gitman_2 |
586
|
|
|
type: git |
587
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
588
|
|
|
sparse_paths: |
589
|
|
|
- |
590
|
|
|
rev: (old revision) |
591
|
|
|
link: |
592
|
|
|
scripts: |
593
|
|
|
- |
594
|
|
|
groups: |
595
|
|
|
- name: group_a |
596
|
|
|
members: |
597
|
|
|
- gitman_1 |
598
|
|
|
- gitman_2 |
599
|
|
|
""" |
600
|
|
|
) |
601
|
|
|
config.datafile.load() |
602
|
|
|
|
603
|
|
|
gitman.update('group_a', depth=1) |
604
|
|
|
|
605
|
|
|
expect(config.datafile.text) == strip( |
606
|
|
|
""" |
607
|
|
|
location: deps |
608
|
|
|
sources: |
609
|
|
|
- name: gitman_1 |
610
|
|
|
type: git |
611
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
612
|
|
|
sparse_paths: |
613
|
|
|
- |
614
|
|
|
rev: example-branch |
615
|
|
|
link: |
616
|
|
|
scripts: |
617
|
|
|
- |
618
|
|
|
- name: gitman_2 |
619
|
|
|
type: git |
620
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
621
|
|
|
sparse_paths: |
622
|
|
|
- |
623
|
|
|
rev: example-tag |
624
|
|
|
link: |
625
|
|
|
scripts: |
626
|
|
|
- |
627
|
|
|
- name: gitman_3 |
628
|
|
|
type: git |
629
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
630
|
|
|
sparse_paths: |
631
|
|
|
- |
632
|
|
|
rev: example-tag |
633
|
|
|
link: |
634
|
|
|
scripts: |
635
|
|
|
- |
636
|
|
|
sources_locked: |
637
|
|
|
- name: gitman_1 |
638
|
|
|
type: git |
639
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
640
|
|
|
sparse_paths: |
641
|
|
|
- |
642
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
643
|
|
|
link: |
644
|
|
|
scripts: |
645
|
|
|
- |
646
|
|
|
- name: gitman_2 |
647
|
|
|
type: git |
648
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
649
|
|
|
sparse_paths: |
650
|
|
|
- |
651
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
652
|
|
|
link: |
653
|
|
|
scripts: |
654
|
|
|
- |
655
|
|
|
groups: |
656
|
|
|
- name: group_a |
657
|
|
|
members: |
658
|
|
|
- gitman_1 |
659
|
|
|
- gitman_2 |
660
|
|
|
""" |
661
|
|
|
) |
662
|
|
|
|
663
|
|
|
@pytest.mark.xfail |
664
|
|
|
def it_should_not_lock_dependencies_changes_force_interactive_no( |
665
|
|
|
config, monkeypatch |
666
|
|
|
): |
667
|
|
|
def git_changes( |
668
|
|
|
type, include_untracked=False, display_status=True, _show=False |
669
|
|
|
): |
670
|
|
|
# always return True because changes won't be overwriten |
671
|
|
|
return True |
672
|
|
|
|
673
|
|
|
# patch the git.changes function to stimulate the |
674
|
|
|
# force-interactive question (without changes no question) |
675
|
|
|
monkeypatch.setattr('gitman.git.changes', git_changes) |
676
|
|
|
# patch standard input function to return "n" for each call |
677
|
|
|
# this is necessary to answer the force-interactive question |
678
|
|
|
# with no to skip the force process |
679
|
|
|
monkeypatch.setattr('builtins.input', lambda x: "n") |
680
|
|
|
|
681
|
|
|
config.datafile.text = strip( |
682
|
|
|
""" |
683
|
|
|
location: deps |
684
|
|
|
sources: |
685
|
|
|
- name: gitman_2 |
686
|
|
|
type: git |
687
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
688
|
|
|
sparse_paths: |
689
|
|
|
- |
690
|
|
|
rev: example-tag |
691
|
|
|
link: |
692
|
|
|
scripts: |
693
|
|
|
- |
694
|
|
|
sources_locked: |
695
|
|
|
- name: gitman_2 |
696
|
|
|
type: git |
697
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
698
|
|
|
sparse_paths: |
699
|
|
|
- |
700
|
|
|
rev: (old revision) |
701
|
|
|
link: |
702
|
|
|
scripts: |
703
|
|
|
- |
704
|
|
|
groups: [] |
705
|
|
|
""" |
706
|
|
|
) |
707
|
|
|
config.datafile.load() |
708
|
|
|
|
709
|
|
|
gitman.update(depth=1, force_interactive=True) |
710
|
|
|
|
711
|
|
|
expect(config.datafile.text) == strip( |
712
|
|
|
""" |
713
|
|
|
location: deps |
714
|
|
|
sources: |
715
|
|
|
- name: gitman_2 |
716
|
|
|
type: git |
717
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
718
|
|
|
sparse_paths: |
719
|
|
|
- |
720
|
|
|
rev: example-tag |
721
|
|
|
link: |
722
|
|
|
scripts: |
723
|
|
|
- |
724
|
|
|
sources_locked: |
725
|
|
|
- name: gitman_2 |
726
|
|
|
type: git |
727
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
728
|
|
|
sparse_paths: |
729
|
|
|
- |
730
|
|
|
rev: (old revision) |
731
|
|
|
link: |
732
|
|
|
scripts: |
733
|
|
|
- |
734
|
|
|
groups: [] |
735
|
|
|
""" |
736
|
|
|
) |
737
|
|
|
|
738
|
|
|
@pytest.mark.xfail |
739
|
|
|
def it_locks_dependencies_changes_force_interactive_yes(config, monkeypatch): |
740
|
|
|
def git_changes( |
741
|
|
|
type, include_untracked=False, display_status=True, _show=False |
742
|
|
|
): |
743
|
|
|
|
744
|
|
|
# get caller function name |
745
|
|
|
caller = inspect.stack()[1].function |
746
|
|
|
# if caller is update_files then we return True |
747
|
|
|
# to simulate local changes |
748
|
|
|
if caller == "update_files": |
749
|
|
|
return True |
750
|
|
|
|
751
|
|
|
# all other functions get False because after |
752
|
|
|
# the force process there are logically no changes anymore |
753
|
|
|
return False |
754
|
|
|
|
755
|
|
|
# patch the git.changes function to stimulate the |
756
|
|
|
# force-interactive question (without changes no question) |
757
|
|
|
monkeypatch.setattr('gitman.git.changes', git_changes) |
758
|
|
|
# patch standard input function to return "y" for each call |
759
|
|
|
# this is necessary to answer the force-interactive question |
760
|
|
|
# with yes todo the force process |
761
|
|
|
monkeypatch.setattr('builtins.input', lambda x: "y") |
762
|
|
|
|
763
|
|
|
config.datafile.text = strip( |
764
|
|
|
""" |
765
|
|
|
location: deps |
766
|
|
|
sources: |
767
|
|
|
- name: gitman_2 |
768
|
|
|
type: git |
769
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
770
|
|
|
sparse_paths: |
771
|
|
|
- |
772
|
|
|
rev: example-tag |
773
|
|
|
link: |
774
|
|
|
scripts: |
775
|
|
|
- |
776
|
|
|
sources_locked: |
777
|
|
|
- name: gitman_2 |
778
|
|
|
type: git |
779
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
780
|
|
|
sparse_paths: |
781
|
|
|
- |
782
|
|
|
rev: (old revision) |
783
|
|
|
link: |
784
|
|
|
scripts: |
785
|
|
|
- |
786
|
|
|
groups: [] |
787
|
|
|
""" |
788
|
|
|
) |
789
|
|
|
config.datafile.load() |
790
|
|
|
|
791
|
|
|
gitman.update(depth=1, force_interactive=True) |
792
|
|
|
|
793
|
|
|
expect(config.datafile.text) == strip( |
794
|
|
|
""" |
795
|
|
|
location: deps |
796
|
|
|
sources: |
797
|
|
|
- name: gitman_2 |
798
|
|
|
type: git |
799
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
800
|
|
|
sparse_paths: |
801
|
|
|
- |
802
|
|
|
rev: example-tag |
803
|
|
|
link: |
804
|
|
|
scripts: |
805
|
|
|
- |
806
|
|
|
sources_locked: |
807
|
|
|
- name: gitman_2 |
808
|
|
|
type: git |
809
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
810
|
|
|
sparse_paths: |
811
|
|
|
- |
812
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
813
|
|
|
link: |
814
|
|
|
scripts: |
815
|
|
|
- |
816
|
|
|
groups: [] |
817
|
|
|
""" |
818
|
|
|
) |
819
|
|
|
|
820
|
|
|
def it_merges_sources(config): |
821
|
|
|
config.datafile.text = strip( |
822
|
|
|
""" |
823
|
|
|
location: deps |
824
|
|
|
sources: |
825
|
|
|
- name: gitman_1 |
826
|
|
|
type: git |
827
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
828
|
|
|
rev: example-branch |
829
|
|
|
link: |
830
|
|
|
scripts: |
831
|
|
|
- |
832
|
|
|
sources_locked: |
833
|
|
|
- name: gitman_2 |
834
|
|
|
type: git |
835
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
836
|
|
|
rev: example-branch |
837
|
|
|
link: |
838
|
|
|
scripts: |
839
|
|
|
- |
840
|
|
|
- name: gitman_3 |
841
|
|
|
type: git |
842
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
843
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
844
|
|
|
link: |
845
|
|
|
scripts: |
846
|
|
|
- |
847
|
|
|
""" |
848
|
|
|
) |
849
|
|
|
config.datafile.load() |
850
|
|
|
|
851
|
|
|
expect(gitman.install(depth=1)) == True |
852
|
|
|
|
853
|
|
|
expect(len(os.listdir(config.location))) == 3 |
854
|
|
|
|
855
|
|
|
|
856
|
|
|
def describe_list(): |
857
|
|
|
@freeze_time("2012-01-14 12:00:01") |
858
|
|
|
def it_updates_the_log(config): |
859
|
|
|
gitman.install() |
860
|
|
|
gitman.list() |
861
|
|
|
|
862
|
|
|
with open(config.log_path) as stream: |
863
|
|
|
contents = stream.read().replace(TMP, "tmp").replace('\\', '/') |
864
|
|
|
expect(contents) == strip( |
865
|
|
|
""" |
866
|
|
|
2012-01-14 12:00:01 |
867
|
|
|
tmp/deps/gitman_1: https://github.com/jacebrowning/gitman-demo @ 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
868
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ 050290bca3f14e13fd616604202b579853e7bfb0 |
869
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ fb693447579235391a45ca170959b5583c5042d8 |
870
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5 |
871
|
|
|
tmp/deps/gitman_1/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5 |
872
|
|
|
tmp/deps/gitman_2: https://github.com/jacebrowning/gitman-demo @ 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
873
|
|
|
tmp/deps/gitman_3: https://github.com/jacebrowning/gitman-demo @ 9bf18e16b956041f0267c21baad555a23237b52e |
874
|
|
|
""", |
875
|
|
|
end='\n\n', |
876
|
|
|
) |
877
|
|
|
|
878
|
|
|
|
879
|
|
|
def describe_lock(): |
880
|
|
|
@pytest.mark.xfail |
881
|
|
|
def it_records_all_versions_when_no_arguments(config): |
882
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
883
|
|
|
expect(gitman.lock()) == True |
884
|
|
|
|
885
|
|
|
expect(config.datafile.text) == CONFIG + strip( |
886
|
|
|
""" |
887
|
|
|
sources_locked: |
888
|
|
|
- name: gitman_1 |
889
|
|
|
type: git |
890
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
891
|
|
|
sparse_paths: |
892
|
|
|
- |
893
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
894
|
|
|
link: |
895
|
|
|
scripts: |
896
|
|
|
- |
897
|
|
|
- name: gitman_2 |
898
|
|
|
type: git |
899
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
900
|
|
|
sparse_paths: |
901
|
|
|
- |
902
|
|
|
rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
903
|
|
|
link: |
904
|
|
|
scripts: |
905
|
|
|
- |
906
|
|
|
- name: gitman_3 |
907
|
|
|
type: git |
908
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
909
|
|
|
sparse_paths: |
910
|
|
|
- |
911
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
912
|
|
|
link: |
913
|
|
|
scripts: |
914
|
|
|
- |
915
|
|
|
groups: [] |
916
|
|
|
""" |
917
|
|
|
) == config.datafile.text |
918
|
|
|
|
919
|
|
|
@pytest.mark.xfail |
920
|
|
|
def it_records_specified_dependencies(config): |
921
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
922
|
|
|
expect(gitman.lock('gitman_1', 'gitman_3')) == True |
923
|
|
|
|
924
|
|
|
expect(config.datafile.text) == CONFIG + strip( |
925
|
|
|
""" |
926
|
|
|
sources_locked: |
927
|
|
|
- name: gitman_1 |
928
|
|
|
type: git |
929
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
930
|
|
|
sparse_paths: |
931
|
|
|
- |
932
|
|
|
rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
933
|
|
|
link: |
934
|
|
|
scripts: |
935
|
|
|
- |
936
|
|
|
- name: gitman_3 |
937
|
|
|
type: git |
938
|
|
|
repo: https://github.com/jacebrowning/gitman-demo |
939
|
|
|
sparse_paths: |
940
|
|
|
- |
941
|
|
|
rev: 9bf18e16b956041f0267c21baad555a23237b52e |
942
|
|
|
link: |
943
|
|
|
scripts: |
944
|
|
|
- |
945
|
|
|
groups: [] |
946
|
|
|
""" |
947
|
|
|
) == config.datafile.text |
948
|
|
|
|
949
|
|
|
def it_should_fail_on_dirty_repositories(config): |
950
|
|
|
expect(gitman.update(depth=1, lock=False)) == True |
951
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".project")) |
952
|
|
|
|
953
|
|
|
try: |
954
|
|
|
with pytest.raises(UncommittedChanges): |
955
|
|
|
gitman.lock() |
956
|
|
|
|
957
|
|
|
expect(config.datafile.text).does_not_contain("<dirty>") |
958
|
|
|
|
959
|
|
|
finally: |
960
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
961
|
|
|
|
962
|
|
|
def it_should_fail_on_missing_repositories(config): |
963
|
|
|
shell.mkdir("deps") |
964
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
965
|
|
|
|
966
|
|
|
with pytest.raises(InvalidRepository): |
967
|
|
|
gitman.lock() |
968
|
|
|
|
969
|
|
|
expect(config.datafile.text).does_not_contain("<unknown>") |
970
|
|
|
|
971
|
|
|
def it_should_fail_on_invalid_repositories(config): |
972
|
|
|
shell.mkdir("deps") |
973
|
|
|
shell.rm(os.path.join("deps", "gitman_1", ".git")) |
974
|
|
|
shell.mkdir(os.path.join("deps", "gitman_1", ".git")) |
975
|
|
|
|
976
|
|
|
try: |
977
|
|
|
with pytest.raises(InvalidRepository): |
978
|
|
|
gitman.lock() |
979
|
|
|
|
980
|
|
|
expect(config.datafile.text).does_not_contain("<unknown>") |
981
|
|
|
|
982
|
|
|
finally: |
983
|
|
|
shell.rm(os.path.join("deps", "gitman_1")) |
984
|
|
|
|