|
| 1 | +# ===--- test_clone.py ----------------------------------------------------===# |
| 2 | +# |
| 3 | +# This source file is part of the Swift.org open source project |
| 4 | +# |
| 5 | +# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +# |
| 8 | +# See https:#swift.org/LICENSE.txt for license information |
| 9 | +# See https:#swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +# |
| 11 | +# ===----------------------------------------------------------------------===# |
| 12 | + |
| 13 | +import os |
| 14 | + |
| 15 | +from scheme_mock import call_quietly |
| 16 | + |
| 17 | +from . import scheme_mock |
| 18 | + |
| 19 | +WORKTREE_NAME = "feature" |
| 20 | + |
| 21 | + |
| 22 | +def path_for_worktree(workspace_path, worktree_name): |
| 23 | + return os.path.join(workspace_path, worktree_name) |
| 24 | + |
| 25 | + |
| 26 | +def setup_worktree(workspace_path, local_path, worktree_name): |
| 27 | + worktree_path = path_for_worktree(workspace_path, worktree_name) |
| 28 | + os.makedirs(worktree_path) |
| 29 | + for project in os.listdir(local_path): |
| 30 | + local_project_path = os.path.join(local_path, project) |
| 31 | + worktree_project_path = os.path.join(worktree_path, project) |
| 32 | + call_quietly(['git', |
| 33 | + '-C', local_project_path, |
| 34 | + 'worktree', 'add', worktree_project_path]) |
| 35 | + |
| 36 | + |
| 37 | +def teardown_worktree(workspace_path, local_path, worktree_name): |
| 38 | + worktree_path = path_for_worktree(workspace_path, worktree_name) |
| 39 | + for project in os.listdir(local_path): |
| 40 | + local_project_path = os.path.join(local_path, project) |
| 41 | + worktree_project_path = os.path.join(worktree_path, project) |
| 42 | + call_quietly(['git', |
| 43 | + '-C', local_project_path, |
| 44 | + 'worktree', 'remove', worktree_project_path]) |
| 45 | + |
| 46 | + |
| 47 | +class WorktreeTestCase(scheme_mock.SchemeMockTestCase): |
| 48 | + |
| 49 | + def __init__(self, *args, **kwargs): |
| 50 | + super(WorktreeTestCase, self).__init__(*args, **kwargs) |
| 51 | + |
| 52 | + def test_worktree(self): |
| 53 | + self.call([self.update_checkout_path, |
| 54 | + '--config', self.config_path, |
| 55 | + '--source-root', self.worktree_path, |
| 56 | + '--scheme', 'master']) |
| 57 | + |
| 58 | + def setUp(self): |
| 59 | + super(WorktreeTestCase, self).setUp() |
| 60 | + self.worktree_path = os.path.join(self.workspace, WORKTREE_NAME) |
| 61 | + setup_worktree(self.workspace, self.local_path, WORKTREE_NAME) |
| 62 | + |
| 63 | + def tearDown(self): |
| 64 | + teardown_worktree(self.workspace, self.local_path, WORKTREE_NAME) |
| 65 | + super(WorktreeTestCase, self).tearDown() |
0 commit comments