Show More
@@ -1886,3 +1886,17 b' def repo_groups(request):' | |||
|
1886 | 1886 | fixture.destroy_repo_group(parent_group) |
|
1887 | 1887 | |
|
1888 | 1888 | return zombie_group, parent_group, child_group |
|
1889 | ||
|
1890 | ||
|
1891 | @pytest.fixture(scope="session") | |
|
1892 | def tmp_path_factory(request): | |
|
1893 | """Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session. | |
|
1894 | """ | |
|
1895 | ||
|
1896 | class TempPathFactory: | |
|
1897 | ||
|
1898 | def mktemp(self, basename): | |
|
1899 | import tempfile | |
|
1900 | return tempfile.mktemp(basename) | |
|
1901 | ||
|
1902 | return TempPathFactory() |
@@ -41,60 +41,41 b' from rhodecode.tests.vcs.conftest import' | |||
|
41 | 41 | pytestmark = pytest.mark.backends("git") |
|
42 | 42 | |
|
43 | 43 | |
|
44 | def repo_path_generator(): | |
|
45 | """ | |
|
46 | Return a different path to be used for cloning repos. | |
|
47 | """ | |
|
48 | i = 0 | |
|
49 | while True: | |
|
50 | i += 1 | |
|
51 | yield '%s-%d' % (TEST_GIT_REPO_CLONE, i) | |
|
52 | ||
|
53 | ||
|
54 | REPO_PATH_GENERATOR = repo_path_generator() | |
|
55 | ||
|
56 | ||
|
57 | class TestGitRepository: | |
|
58 | ||
|
59 | # pylint: disable=protected-access | |
|
60 | ||
|
61 | def __check_for_existing_repo(self): | |
|
62 | if os.path.exists(TEST_GIT_REPO_CLONE): | |
|
63 | self.fail('Cannot test git clone repo as location %s already ' | |
|
64 | 'exists. You should manually remove it first.' | |
|
65 | % TEST_GIT_REPO_CLONE) | |
|
44 | class TestGitRepository(object): | |
|
66 | 45 | |
|
67 | 46 | @pytest.fixture(autouse=True) |
|
68 | 47 | def prepare(self, request, baseapp): |
|
69 | 48 | self.repo = GitRepository(TEST_GIT_REPO, bare=True) |
|
70 | 49 | |
|
71 | def get_clone_repo(self): | |
|
50 | def get_clone_repo(self, tmp_path_factory): | |
|
72 | 51 | """ |
|
73 | 52 | Return a non bare clone of the base repo. |
|
74 | 53 | """ |
|
75 | clone_path = next(REPO_PATH_GENERATOR) | |
|
54 | clone_path = tmp_path_factory.mktemp('clone-url') | |
|
76 | 55 | repo_clone = GitRepository( |
|
77 | 56 | clone_path, create=True, src_url=self.repo.path, bare=False) |
|
78 | 57 | |
|
79 | 58 | return repo_clone |
|
80 | 59 | |
|
81 | def get_empty_repo(self, bare=False): | |
|
60 | def get_empty_repo(self, tmp_path_factory, bare=False): | |
|
82 | 61 | """ |
|
83 | 62 | Return a non bare empty repo. |
|
84 | 63 | """ |
|
85 | return GitRepository(next(REPO_PATH_GENERATOR), create=True, bare=bare) | |
|
64 | clone_path = tmp_path_factory.mktemp('empty-repo') | |
|
65 | return GitRepository(clone_path, create=True, bare=bare) | |
|
86 | 66 | |
|
87 | 67 | def test_wrong_repo_path(self): |
|
88 | 68 | wrong_repo_path = '/tmp/errorrepo_git' |
|
89 | 69 | with pytest.raises(RepositoryError): |
|
90 | 70 | GitRepository(wrong_repo_path) |
|
91 | 71 | |
|
92 | def test_repo_clone(self): | |
|
93 | self.__check_for_existing_repo() | |
|
72 | def test_repo_clone(self, tmp_path_factory): | |
|
94 | 73 | repo = GitRepository(TEST_GIT_REPO) |
|
74 | clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE | |
|
95 | 75 | repo_clone = GitRepository( |
|
96 | TEST_GIT_REPO_CLONE, | |
|
76 | clone_path, | |
|
97 | 77 | src_url=TEST_GIT_REPO, create=True, do_workspace_checkout=True) |
|
78 | ||
|
98 | 79 | assert len(repo.commit_ids) == len(repo_clone.commit_ids) |
|
99 | 80 | # Checking hashes of commits should be enough |
|
100 | 81 | for commit in repo.get_commits(): |
@@ -106,9 +87,10 b' class TestGitRepository:' | |||
|
106 | 87 | GitRepository( |
|
107 | 88 | TEST_GIT_REPO_CLONE + '_wo_create', src_url=TEST_GIT_REPO) |
|
108 | 89 | |
|
109 | def test_repo_clone_with_update(self): | |
|
90 | def test_repo_clone_with_update(self, tmp_path_factory): | |
|
110 | 91 | repo = GitRepository(TEST_GIT_REPO) |
|
111 |
clone_path = TEST_GIT_REPO_CLONE + ' |
|
|
92 | clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_update' | |
|
93 | ||
|
112 | 94 | repo_clone = GitRepository( |
|
113 | 95 | clone_path, |
|
114 | 96 | create=True, src_url=TEST_GIT_REPO, do_workspace_checkout=True) |
@@ -118,9 +100,9 b' class TestGitRepository:' | |||
|
118 | 100 | fpath = os.path.join(clone_path, 'MANIFEST.in') |
|
119 | 101 | assert os.path.isfile(fpath) |
|
120 | 102 | |
|
121 | def test_repo_clone_without_update(self): | |
|
103 | def test_repo_clone_without_update(self, tmp_path_factory): | |
|
122 | 104 | repo = GitRepository(TEST_GIT_REPO) |
|
123 | clone_path = TEST_GIT_REPO_CLONE + '_without_update' | |
|
105 | clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_without_update' | |
|
124 | 106 | repo_clone = GitRepository( |
|
125 | 107 | clone_path, |
|
126 | 108 | create=True, src_url=TEST_GIT_REPO, do_workspace_checkout=False) |
@@ -131,9 +113,9 b' class TestGitRepository:' | |||
|
131 | 113 | assert not repo_clone.bare |
|
132 | 114 | assert not os.path.isfile(fpath) |
|
133 | 115 | |
|
134 | def test_repo_clone_into_bare_repo(self): | |
|
116 | def test_repo_clone_into_bare_repo(self, tmp_path_factory): | |
|
135 | 117 | repo = GitRepository(TEST_GIT_REPO) |
|
136 | clone_path = TEST_GIT_REPO_CLONE + '_bare.git' | |
|
118 | clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_bare.git' | |
|
137 | 119 | repo_clone = GitRepository( |
|
138 | 120 | clone_path, create=True, src_url=repo.path, bare=True) |
|
139 | 121 | assert repo_clone.bare |
@@ -275,8 +257,8 b' TODO: To be written...' | |||
|
275 | 257 | def test_head(self): |
|
276 | 258 | assert self.repo.head == self.repo.get_commit().raw_id |
|
277 | 259 | |
|
278 | def test_checkout_with_create(self): | |
|
279 | repo_clone = self.get_clone_repo() | |
|
260 | def test_checkout_with_create(self, tmp_path_factory): | |
|
261 | repo_clone = self.get_clone_repo(tmp_path_factory) | |
|
280 | 262 | |
|
281 | 263 | new_branch = 'new_branch' |
|
282 | 264 | assert repo_clone._current_branch() == 'master' |
@@ -288,22 +270,22 b' TODO: To be written...' | |||
|
288 | 270 | assert set(repo_clone.branches) == {'master', new_branch} |
|
289 | 271 | assert repo_clone._current_branch() == new_branch |
|
290 | 272 | |
|
291 | def test_checkout(self): | |
|
292 | repo_clone = self.get_clone_repo() | |
|
273 | def test_checkout(self, tmp_path_factory): | |
|
274 | repo_clone = self.get_clone_repo(tmp_path_factory) | |
|
293 | 275 | |
|
294 | 276 | repo_clone._checkout('new_branch', create=True) |
|
295 | 277 | repo_clone._checkout('master') |
|
296 | 278 | |
|
297 | 279 | assert repo_clone._current_branch() == 'master' |
|
298 | 280 | |
|
299 | def test_checkout_same_branch(self): | |
|
300 | repo_clone = self.get_clone_repo() | |
|
281 | def test_checkout_same_branch(self, tmp_path_factory): | |
|
282 | repo_clone = self.get_clone_repo(tmp_path_factory) | |
|
301 | 283 | |
|
302 | 284 | repo_clone._checkout('master') |
|
303 | 285 | assert repo_clone._current_branch() == 'master' |
|
304 | 286 | |
|
305 | def test_checkout_branch_already_exists(self): | |
|
306 | repo_clone = self.get_clone_repo() | |
|
287 | def test_checkout_branch_already_exists(self, tmp_path_factory): | |
|
288 | repo_clone = self.get_clone_repo(tmp_path_factory) | |
|
307 | 289 | |
|
308 | 290 | with pytest.raises(RepositoryError): |
|
309 | 291 | repo_clone._checkout('master', create=True) |
@@ -316,32 +298,32 b' TODO: To be written...' | |||
|
316 | 298 | with pytest.raises(RepositoryError): |
|
317 | 299 | self.repo._current_branch() |
|
318 | 300 | |
|
319 | def test_current_branch_empty_repo(self): | |
|
320 | repo = self.get_empty_repo() | |
|
301 | def test_current_branch_empty_repo(self, tmp_path_factory): | |
|
302 | repo = self.get_empty_repo(tmp_path_factory) | |
|
321 | 303 | assert repo._current_branch() is None |
|
322 | 304 | |
|
323 | def test_local_clone(self): | |
|
324 | clone_path = next(REPO_PATH_GENERATOR) | |
|
305 | def test_local_clone(self, tmp_path_factory): | |
|
306 | clone_path = tmp_path_factory.mktemp('test-local-clone') | |
|
325 | 307 | self.repo._local_clone(clone_path, 'master') |
|
326 | 308 | repo_clone = GitRepository(clone_path) |
|
327 | 309 | |
|
328 | 310 | assert self.repo.commit_ids == repo_clone.commit_ids |
|
329 | 311 | |
|
330 | def test_local_clone_with_specific_branch(self): | |
|
331 | source_repo = self.get_clone_repo() | |
|
312 | def test_local_clone_with_specific_branch(self, tmp_path_factory): | |
|
313 | source_repo = self.get_clone_repo(tmp_path_factory) | |
|
332 | 314 | |
|
333 | 315 | # Create a new branch in source repo |
|
334 | 316 | new_branch_commit = source_repo.commit_ids[-3] |
|
335 | 317 | source_repo._checkout(new_branch_commit) |
|
336 | 318 | source_repo._checkout('new_branch', create=True) |
|
337 | 319 | |
|
338 | clone_path = next(REPO_PATH_GENERATOR) | |
|
320 | clone_path = tmp_path_factory.mktemp('git-clone-path-1') | |
|
339 | 321 | source_repo._local_clone(clone_path, 'new_branch') |
|
340 | 322 | repo_clone = GitRepository(clone_path) |
|
341 | 323 | |
|
342 | 324 | assert source_repo.commit_ids[:-3 + 1] == repo_clone.commit_ids |
|
343 | 325 | |
|
344 | clone_path = next(REPO_PATH_GENERATOR) | |
|
326 | clone_path = tmp_path_factory.mktemp('git-clone-path-2') | |
|
345 | 327 | source_repo._local_clone(clone_path, 'master') |
|
346 | 328 | repo_clone = GitRepository(clone_path) |
|
347 | 329 | |
@@ -351,9 +333,9 b' TODO: To be written...' | |||
|
351 | 333 | with pytest.raises(RepositoryError): |
|
352 | 334 | self.repo._local_clone(self.repo.path, 'master') |
|
353 | 335 | |
|
354 | def test_local_fetch(self): | |
|
355 | target_repo = self.get_empty_repo() | |
|
356 | source_repo = self.get_clone_repo() | |
|
336 | def test_local_fetch(self, tmp_path_factory): | |
|
337 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
338 | source_repo = self.get_clone_repo(tmp_path_factory) | |
|
357 | 339 | |
|
358 | 340 | # Create a new branch in source repo |
|
359 | 341 | master_commit = source_repo.commit_ids[-1] |
@@ -367,8 +349,8 b' TODO: To be written...' | |||
|
367 | 349 | target_repo._local_fetch(source_repo.path, 'master') |
|
368 | 350 | assert target_repo._last_fetch_heads() == [master_commit] |
|
369 | 351 | |
|
370 | def test_local_fetch_from_bare_repo(self): | |
|
371 | target_repo = self.get_empty_repo() | |
|
352 | def test_local_fetch_from_bare_repo(self, tmp_path_factory): | |
|
353 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
372 | 354 | target_repo._local_fetch(self.repo.path, 'master') |
|
373 | 355 | |
|
374 | 356 | master_commit = self.repo.commit_ids[-1] |
@@ -378,15 +360,15 b' TODO: To be written...' | |||
|
378 | 360 | with pytest.raises(ValueError): |
|
379 | 361 | self.repo._local_fetch(self.repo.path, 'master') |
|
380 | 362 | |
|
381 | def test_local_fetch_branch_does_not_exist(self): | |
|
382 | target_repo = self.get_empty_repo() | |
|
363 | def test_local_fetch_branch_does_not_exist(self, tmp_path_factory): | |
|
364 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
383 | 365 | |
|
384 | 366 | with pytest.raises(RepositoryError): |
|
385 | 367 | target_repo._local_fetch(self.repo.path, 'new_branch') |
|
386 | 368 | |
|
387 | def test_local_pull(self): | |
|
388 | target_repo = self.get_empty_repo() | |
|
389 | source_repo = self.get_clone_repo() | |
|
369 | def test_local_pull(self, tmp_path_factory): | |
|
370 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
371 | source_repo = self.get_clone_repo(tmp_path_factory) | |
|
390 | 372 | |
|
391 | 373 | # Create a new branch in source repo |
|
392 | 374 | master_commit = source_repo.commit_ids[-1] |
@@ -406,9 +388,9 b' TODO: To be written...' | |||
|
406 | 388 | with pytest.raises(RepositoryError): |
|
407 | 389 | self.repo._local_pull(self.repo.path, 'master') |
|
408 | 390 | |
|
409 | def test_local_merge(self): | |
|
410 | target_repo = self.get_empty_repo() | |
|
411 | source_repo = self.get_clone_repo() | |
|
391 | def test_local_merge(self, tmp_path_factory): | |
|
392 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
393 | source_repo = self.get_clone_repo(tmp_path_factory) | |
|
412 | 394 | |
|
413 | 395 | # Create a new branch in source repo |
|
414 | 396 | master_commit = source_repo.commit_ids[-1] |
@@ -449,8 +431,8 b' TODO: To be written...' | |||
|
449 | 431 | assert not os.path.exists( |
|
450 | 432 | os.path.join(target_repo.path, '.git', 'MERGE_HEAD')) |
|
451 | 433 | |
|
452 | def test_local_merge_into_empty_repo(self): | |
|
453 | target_repo = self.get_empty_repo() | |
|
434 | def test_local_merge_into_empty_repo(self, tmp_path_factory): | |
|
435 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
454 | 436 | |
|
455 | 437 | # This is required as one cannot do a -ff-only merge in an empty repo. |
|
456 | 438 | target_repo._local_fetch(self.repo.path, 'master') |
@@ -464,8 +446,8 b' TODO: To be written...' | |||
|
464 | 446 | self.repo._local_merge( |
|
465 | 447 | 'merge_message', 'user name', 'user@name.com', None) |
|
466 | 448 | |
|
467 | def test_local_push_non_bare(self): | |
|
468 | target_repo = self.get_empty_repo() | |
|
449 | def test_local_push_non_bare(self, tmp_path_factory): | |
|
450 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
469 | 451 | |
|
470 | 452 | pushed_branch = 'pushed_branch' |
|
471 | 453 | self.repo._local_push('master', target_repo.path, pushed_branch) |
@@ -479,8 +461,8 b' TODO: To be written...' | |||
|
479 | 461 | assert (target_repo.branches[pushed_branch] == |
|
480 | 462 | self.repo.branches['master']) |
|
481 | 463 | |
|
482 | def test_local_push_bare(self): | |
|
483 | target_repo = self.get_empty_repo(bare=True) | |
|
464 | def test_local_push_bare(self, tmp_path_factory): | |
|
465 | target_repo = self.get_empty_repo(tmp_path_factory, bare=True) | |
|
484 | 466 | |
|
485 | 467 | pushed_branch = 'pushed_branch' |
|
486 | 468 | self.repo._local_push('master', target_repo.path, pushed_branch) |
@@ -494,8 +476,8 b' TODO: To be written...' | |||
|
494 | 476 | assert (target_repo.branches[pushed_branch] == |
|
495 | 477 | self.repo.branches['master']) |
|
496 | 478 | |
|
497 | def test_local_push_non_bare_target_branch_is_checked_out(self): | |
|
498 | target_repo = self.get_clone_repo() | |
|
479 | def test_local_push_non_bare_target_branch_is_checked_out(self, tmp_path_factory): | |
|
480 | target_repo = self.get_clone_repo(tmp_path_factory) | |
|
499 | 481 | |
|
500 | 482 | pushed_branch = 'pushed_branch' |
|
501 | 483 | # Create a new branch in source repo |
@@ -515,8 +497,8 b' TODO: To be written...' | |||
|
515 | 497 | with pytest.raises(RepositoryError): |
|
516 | 498 | self.repo._local_push('master', target_repo.path, 'master') |
|
517 | 499 | |
|
518 | def test_hooks_can_be_enabled_via_env_variable_for_local_push(self): | |
|
519 | target_repo = self.get_empty_repo(bare=True) | |
|
500 | def test_hooks_can_be_enabled_via_env_variable_for_local_push(self, tmp_path_factory): | |
|
501 | target_repo = self.get_empty_repo(tmp_path_factory, bare=True) | |
|
520 | 502 | |
|
521 | 503 | with mock.patch.object(self.repo, 'run_git_command') as run_mock: |
|
522 | 504 | self.repo._local_push( |
@@ -540,8 +522,8 b' TODO: To be written...' | |||
|
540 | 522 | f.write('\n'.join(script_lines)) |
|
541 | 523 | os.chmod(hook_path, 0o755) |
|
542 | 524 | |
|
543 | def test_local_push_does_not_execute_hook(self): | |
|
544 | target_repo = self.get_empty_repo() | |
|
525 | def test_local_push_does_not_execute_hook(self, tmp_path_factory): | |
|
526 | target_repo = self.get_empty_repo(tmp_path_factory) | |
|
545 | 527 | |
|
546 | 528 | pushed_branch = 'pushed_branch' |
|
547 | 529 | self._add_failing_hook(target_repo.path, 'pre-receive') |
@@ -556,8 +538,8 b' TODO: To be written...' | |||
|
556 | 538 | assert (target_repo.branches[pushed_branch] == |
|
557 | 539 | self.repo.branches['master']) |
|
558 | 540 | |
|
559 | def test_local_push_executes_hook(self): | |
|
560 | target_repo = self.get_empty_repo(bare=True) | |
|
541 | def test_local_push_executes_hook(self, tmp_path_factory): | |
|
542 | target_repo = self.get_empty_repo(tmp_path_factory, bare=True) | |
|
561 | 543 | self._add_failing_hook(target_repo.path, 'pre-receive', bare=True) |
|
562 | 544 | with pytest.raises(RepositoryError): |
|
563 | 545 | self.repo._local_push( |
@@ -46,6 +46,7 b' class TestVCSOperationsSpecial(object):' | |||
|
46 | 46 | cmd.execute('git clone', clone_url) |
|
47 | 47 | |
|
48 | 48 | repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) |
|
49 | repo._checkout('test', create=True) | |
|
49 | 50 | repo.in_memory_commit.add(FileNode('file', content='')) |
|
50 | 51 | repo.in_memory_commit.commit( |
|
51 | 52 | message='Commit on branch test', |
General Comments 0
You need to be logged in to leave comments.
Login now