Skip to content

Commit 3e2943f

Browse files
Merge pull request #85858 from charles-zablit/charles-zablit/update-checkout/fix-clone-warning
2 parents e8b0184 + 13a32fb commit 3e2943f

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

utils/update_checkout/tests/test_clone.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ===----------------------------------------------------------------------===#
1212

1313
import os
14+
import shutil
1415

1516
from . import scheme_mock
1617

@@ -56,6 +57,39 @@ def test_clone_with_additional_scheme(self):
5657
# Test that we're actually checking out the 'extra' scheme based on the output
5758
self.assertIn("git checkout refs/heads/main", output)
5859

60+
def test_clone_missing_repos(self):
61+
output = self.call(
62+
[
63+
self.update_checkout_path,
64+
"--config",
65+
self.config_path,
66+
"--source-root",
67+
self.source_root,
68+
"--clone",
69+
]
70+
)
71+
self.assertNotIn(
72+
"You don't have all swift sources. Call this script with --clone to get them.",
73+
output,
74+
)
75+
76+
repo = self.get_all_repos()[0]
77+
repo_path = os.path.join(self.source_root, repo)
78+
shutil.rmtree(repo_path)
79+
output = self.call(
80+
[
81+
self.update_checkout_path,
82+
"--config",
83+
self.config_path,
84+
"--source-root",
85+
self.source_root,
86+
]
87+
)
88+
self.assertIn(
89+
"You don't have all swift sources. Call this script with --clone to get them.",
90+
output,
91+
)
92+
5993

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

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,46 @@ def _is_any_repository_locked(pool_args: List[UpdateArguments]) -> Set[str]:
376376
return locked_repositories
377377

378378

379+
def _check_missing_clones(
380+
args: CliArguments, config: Dict[str, Any], scheme_map: Dict[str, Any]
381+
):
382+
"""
383+
Verify that all repositories defined in the scheme map are present in the
384+
source root directory. If a repository is missing—and not explicitly skipped—
385+
the user is prompted to re-run the script with the `--clone` option.
386+
387+
This function also respects per-repository platform restrictions: if the
388+
current platform is not listed for a repo, that repo is ignored.
389+
390+
Args:
391+
args (CliArguments): Parsed CLI arguments.
392+
config (Dict[str, Any]): deserialized `update-checkout-config.json`.
393+
scheme_map (Dict[str, str] | None): map of repo names to branches to check out.
394+
395+
Returns:
396+
Prints a warning if any required repository is missing.
397+
"""
398+
399+
directory_contents = {path.name for path in args.source_root.iterdir()}
400+
current_platform = platform.system()
401+
402+
for repo in scheme_map:
403+
repo_config = config["repos"].get(repo, {})
404+
405+
if (
406+
"platforms" in repo_config
407+
and current_platform not in repo_config["platforms"]
408+
):
409+
continue
410+
411+
if repo not in directory_contents and repo not in args.skip_repository_list:
412+
print(
413+
"You don't have all swift sources. "
414+
"Call this script with --clone to get them."
415+
)
416+
return
417+
418+
379419
def _move_llvm_project_to_first_index(
380420
pool_args: Union[List[UpdateArguments], List[AdditionalSwiftSourcesArguments]],
381421
):
@@ -855,17 +895,7 @@ def main() -> int:
855895
dump_repo_hashes(args, config, args.dump_hashes_config)
856896
return 0
857897

858-
# Quick check whether somebody is calling update in an empty directory
859-
directory_contents = args.source_root.iterdir()
860-
if not (
861-
"cmark" in directory_contents
862-
or "llvm" in directory_contents
863-
or "clang" in directory_contents
864-
):
865-
print(
866-
"You don't have all swift sources. "
867-
"Call this script with --clone to get them."
868-
)
898+
_check_missing_clones(args=args, config=config, scheme_map=scheme_map)
869899

870900
skipped_repositories, update_results = update_all_repositories(
871901
args, config, scheme_name, scheme_map, cross_repos_pr

0 commit comments

Comments
 (0)