aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadaf Ebrahimi <sadafebrahimi@google.com>2024-03-28 20:26:49 +0000
committerSadaf Ebrahimi <sadafebrahimi@google.com>2024-04-03 16:58:24 +0000
commitba199da594c37c3c73fedea1e99bc43cb2ee284d (patch)
tree8697eba0422e25cde8fbc997a881301caa35ad76
parent8e22672c573a9279dbd66c0dd6961012e0b268b2 (diff)
downloadexternal_updater-ba199da594c37c3c73fedea1e99bc43cb2ee284d.tar.gz
Finding android specific files dynamically
ANDROID_SPECIFIC_FILES list is not accurate, requires manual maintenance, and doesn't include generated files. Test: TreeHugger Change-Id: I85a8a886c88194a47e8d95a9fb1e401d17aaa75a
-rw-r--r--base_updater.py2
-rw-r--r--git_utils.py15
-rw-r--r--tests/test_git_utils.py15
3 files changed, 19 insertions, 13 deletions
diff --git a/base_updater.py b/base_updater.py
index 0adc8f4..106f125 100644
--- a/base_updater.py
+++ b/base_updater.py
@@ -46,7 +46,7 @@ class Updater:
def validate(self) -> str:
"""Checks whether aosp version is what it claims to be."""
self.setup_remote()
- return git_utils.diff(self._proj_path, self._old_identifier.version)
+ return git_utils.diff(self._proj_path, 'a', self._old_identifier.version)
def check(self) -> None:
"""Checks whether a new version is available."""
diff --git a/git_utils.py b/git_utils.py
index 91be216..cddd78f 100644
--- a/git_utils.py
+++ b/git_utils.py
@@ -21,12 +21,6 @@ from pathlib import Path
import hashtags
import reviewers
-ANDROID_SPECIFIC_FILES = ["*Android.bp", "Android.mk", "CleanSpec.mk", "LICENSE",
- "NOTICE", "METADATA", "TEST_MAPPING", ".git",
- ".gitignore", "patches", "post_update.sh", "OWNERS",
- "README.android", "cargo2android*", "MODULE_LICENSE_*",
- "rules.mk", "cargo2rulesmk*", "cargo_embargo*"]
-
UNWANTED_TAGS = ["*alpha*", "*Alpha*", "*beta*", "*Beta*", "*rc*", "*RC*", "*test*"]
@@ -255,6 +249,7 @@ def is_valid_url(proj_path: Path, url: str) -> bool:
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
start_new_session=True).returncode == 0
+
def list_remote_tags(proj_path: Path, remote_name: str) -> list[str]:
"""Lists tags in a remote repository."""
cmd = ['git', "ls-remote", "--tags", remote_name]
@@ -264,13 +259,9 @@ def list_remote_tags(proj_path: Path, remote_name: str) -> list[str]:
return lines
-def diff(proj_path: Path, sha_or_tag: str) -> str:
- files = []
- for file in ANDROID_SPECIFIC_FILES:
- file = ":!" + file
- files.append(file)
+def diff(proj_path: Path, diff_filter: str, revision: str) -> str:
try:
- cmd = ['git', 'diff', sha_or_tag, '--stat', '--'] + files
+ cmd = ['git', 'diff', revision, '--stat', f'--diff-filter={diff_filter}']
out = subprocess.run(cmd, capture_output=True, cwd=proj_path,
check=True, text=True).stdout
return out
diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py
index 853145c..3c24302 100644
--- a/tests/test_git_utils.py
+++ b/tests/test_git_utils.py
@@ -119,5 +119,20 @@ class GetMostRecentTagTest(GitRepoTestCase):
self.assertIsNone(git_utils.get_most_recent_tag(self.repo.path, "main"))
+class DiffTest(GitRepoTestCase):
+ """Tests for git_utils.diff."""
+ def test_git_diff_added_filter(self) -> None:
+ self.repo.init("main")
+ self.repo.commit(
+ "Add README.md", update_files={"README.md": "Hello, world!"}
+ )
+ first_commit = self.repo.head()
+ self.repo.commit(
+ "Add OWNERS", update_files={"OWNERS": "nobody"}
+ )
+ diff = git_utils.diff(self.repo.path, 'A', first_commit)
+ self.assertIn('OWNERS', diff)
+
+
if __name__ == "__main__":
unittest.main(verbosity=2)