Skip to content

update-checkout: Do not update repository if not listed in the given branch-scheme #61275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion utils/python_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
_SWIFT_PATH / "test/Driver/Inputs/fake-toolchain/ld",
_SWIFT_PATH / "utils/80+-check",
_SWIFT_PATH / "utils/backtrace-check",
_SWIFT_PATH / "utils/build-parser-lib",
_SWIFT_PATH / "utils/build-script",
_SWIFT_PATH / "utils/check-incremental",
_SWIFT_PATH / "utils/coverage/coverage-build-db",
Expand Down
16 changes: 12 additions & 4 deletions utils/update_checkout/tests/scheme_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
('A.txt', 'a'),
],
'repo2': [
# This is a series of changes to repo1. (File, NewContents)
# This is a series of changes to repo2. (File, NewContents)
('X.txt', 'X'),
('Y.txt', 'Y'),
('X.txt', 'z'),
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_config_path(base_dir):
return os.path.join(base_dir, 'test-config.json')


def setup_mock_remote(base_dir):
def setup_mock_remote(base_dir, base_config):
create_dir(base_dir)

# We use local as a workspace for creating commits.
Expand Down Expand Up @@ -130,7 +130,6 @@ def setup_mock_remote(base_dir):
call_quietly(['git', 'push', 'origin', 'main'],
cwd=local_repo_path)

base_config = MOCK_CONFIG
https_clone_pattern = os.path.join('file://%s' % REMOTE_PATH, '%s')
base_config['https-clone-pattern'] = https_clone_pattern

Expand All @@ -153,6 +152,7 @@ class SchemeMockTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(SchemeMockTestCase, self).__init__(*args, **kwargs)

self.config = MOCK_CONFIG.copy()
self.workspace = os.getenv(BASEDIR_ENV_VAR)
if self.workspace is None:
raise RuntimeError('Misconfigured test suite! Environment '
Expand All @@ -167,11 +167,19 @@ def __init__(self, *args, **kwargs):

def setUp(self):
create_dir(self.source_root)
(self.local_path, self.remote_path) = setup_mock_remote(self.workspace)
(self.local_path, self.remote_path) = setup_mock_remote(
self.workspace, self.config
)

def tearDown(self):
teardown_mock_remote(self.workspace)

def call(self, *args, **kwargs):
kwargs['cwd'] = self.source_root
call_quietly(*args, **kwargs)

def get_all_repos(self):
return list(self.config["repos"].keys())

def add_branch_scheme(self, name, scheme):
self.config["branch-schemes"][name] = scheme
50 changes: 50 additions & 0 deletions utils/update_checkout/tests/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#
# ===----------------------------------------------------------------------===#

import os

from . import scheme_mock


Expand All @@ -23,3 +25,51 @@ def test_simple_clone(self):
'--config', self.config_path,
'--source-root', self.source_root,
'--clone'])

for repo in self.get_all_repos():
repo_path = os.path.join(self.source_root, repo)
self.assertTrue(os.path.isdir(repo_path))


class SchemeWithMissingRepoTestCase(scheme_mock.SchemeMockTestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.base_args = [
self.update_checkout_path,
"--config",
self.config_path,
"--source-root",
self.source_root,
]

repos = self.get_all_repos()
repos.pop()

self.scheme_name = "missing-repo"
scheme = {
"aliases": [self.scheme_name],
"repos": dict((repo, "main") for repo in repos),
}
self.add_branch_scheme(self.scheme_name, scheme)

# Test that we do not clone a repository that is not listed in the
# given branch-scheme.
def test_clone(self):
self.call(self.base_args + ["--scheme", self.scheme_name, "--clone"])

missing_repo_path = os.path.join(
self.source_root, self.get_all_repos().pop()
)
self.assertFalse(os.path.isdir(missing_repo_path))

# Test that we do not update a repository that is not listed in the given
# branch-scheme---doing so will cause an irrelevant failure in an attempt
# to query the branch-scheme about the target branch for that repository.
def test_update(self):
# First, clone using the default branch-scheme, which has mappings for
# all repositories.
self.call(self.base_args + ["--clone"])

# Then, update using our custom scheme---a subset of the default one.
self.call(self.base_args + ["--scheme", self.scheme_name])
14 changes: 14 additions & 0 deletions utils/update_checkout/update_checkout/update_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
if repo_name in args.skip_repository_list:
print("Skipping update of '" + repo_name + "', requested by user")
continue

# If the repository is not listed in the branch-scheme, skip it.
if scheme_map and repo_name not in scheme_map:
# If the repository exists locally, notify we are skipping it.
if os.path.isdir(os.path.join(args.source_root, repo_name)):
print(
"Skipping update of '"
+ repo_name
+ "', repository not listed in the '"
+ scheme_name
+ "' branch-scheme"
)
continue

my_args = [args.source_root, config,
repo_name,
scheme_name,
Expand Down