Skip to content

Commit

Permalink
During sync, fall back to reporting all files as changed if the hg/gi…
Browse files Browse the repository at this point in the history
…t/svn cli command fails (mozilla#3179)
  • Loading branch information
eemeli authored Apr 18, 2024
1 parent b0bfcc2 commit 722c1d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pontoon/sync/tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_changed_files_error(self):
with patch.object(
self.vcsrepository, "execute", side_effect=self.execute_failure
) as mock_execute:
assert self.vcsrepository.get_changed_files("path", "1") == []
assert self.vcsrepository.get_changed_files("path", "1") is None
assert mock_execute.called

def test_removed_files(self):
Expand All @@ -87,7 +87,7 @@ def test_removed_files_error(self):
with patch.object(
self.vcsrepository, "execute", side_effect=self.execute_failure
) as mock_execute:
assert self.vcsrepository.get_removed_files("path", "1") == []
assert self.vcsrepository.get_removed_files("path", "1") is None
assert mock_execute.called


Expand Down
33 changes: 17 additions & 16 deletions pontoon/sync/vcs/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def normalize_revision(rev):
for line in output.split("\n")
if line and line[0] in statuses
]
return []
return None

def get_removed_files(self, path, from_revision):
return self.get_changed_files(path, from_revision, ("D",))
Expand All @@ -398,7 +398,7 @@ def get_changed_files(self, path, from_revision, statuses=None):
for line in output.split("\n")
if line and line[0] in statuses
]
return []
return None

def get_removed_files(self, path, from_revision):
return self.get_changed_files(path, from_revision, ("D",))
Expand Down Expand Up @@ -437,7 +437,7 @@ def get_changed_files(self, path, from_revision, statuses=None):
for line in output.split("\n")
if line and line[0] in statuses
]
return []
return None

def get_removed_files(self, path, from_revision):
return self.get_changed_files(path, self._strip(from_revision), ("R",))
Expand All @@ -459,18 +459,19 @@ def get_changed_files(repo_type, path, revision):
"""Return a list of changed files for the repository."""
repo = VCSRepository.for_type(repo_type, path)
log.info(f"Retrieving changed files for: {path}:{revision}")

if revision is not None:
changed = repo.get_changed_files(path, revision)
removed = repo.get_removed_files(path, revision)
if changed is not None and removed is not None:
return changed, removed

# If there's no latest revision we should return all the files in the latest
# version of repository
if revision is None:
paths = []
for root, _, files in os.walk(path):
for f in files:
if root[0] == "." or "/." in root:
continue
paths.append(os.path.join(root, f).replace(path + "/", ""))
return paths, []

return (
repo.get_changed_files(path, revision),
repo.get_removed_files(path, revision),
)
paths = []
for root, _, files in os.walk(path):
for f in files:
if root[0] == "." or "/." in root:
continue
paths.append(os.path.join(root, f).replace(path + "/", ""))
return paths, []

0 comments on commit 722c1d3

Please sign in to comment.