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