Skip to content

Commit ad951d4

Browse files
author
Pujitha Paladugu
authored
Sync: refuse auto-discovered base outside the current target checkout (#4642)
1 parent e8c26f2 commit ad951d4

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎pontoon/sync/core/paths.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ def find_paths(
3232
paths.base = checkouts.target.path
3333
name = f"cfg={project.configuration_file}"
3434
else:
35+
# Search only the current checkouts, so that a stale clone
36+
# left in project.checkout_path is never considered.
3537
paths = L10nDiscoverPaths(
36-
project.checkout_path,
38+
checkouts.target.path,
3739
ref_root=src_root,
3840
force_paths=force_paths,
3941
source_locale=["templates", "en-US", "en"],

‎pontoon/sync/tests/test_paths.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ def test_no_config_one_repo():
4747
assert paths.find_reference("fr/.other.ftl") is None
4848

4949

50+
def test_no_config_stale_checkout():
51+
# A checkout left behind after a repository URL change
52+
# must not be considered, even if it has more locales.
53+
tree: FileTree = {
54+
"old": {"en-US": {"a.ftl": ""}, "de": {"a.ftl": ""}, "fr": {"a.ftl": ""}},
55+
"new": {"en-US": {"a.ftl": ""}, "it": {"a.ftl": ""}},
56+
}
57+
with TemporaryDirectory() as root:
58+
build_file_tree(root, tree)
59+
mock_project = Mock(Project, checkout_path=root, configuration_file=None)
60+
mock_checkout = Mock(Checkout, path=join(root, "new"), removed=[])
61+
paths = find_paths(mock_project, Checkouts(mock_checkout, mock_checkout))
62+
assert paths.ref_root == join(root, "new", "en-US")
63+
assert paths.base == join(root, "new")
64+
assert paths.locales == ["it"]
65+
66+
5067
def test_no_config_two_repos():
5168
tree: FileTree = {
5269
"source": {"bar.ftl": "", "foo.pot": "", ".other.ftl": ""},

0 commit comments

Comments
 (0)