aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/presubmit.py
diff options
context:
space:
mode:
authorGravatar Abhishek Arya <inferno@chromium.org>2021-01-27 14:28:27 -0800
committerGravatar GitHub <noreply@github.com>2021-01-27 14:28:27 -0800
commit23e24a4bac8c5014450038d583f535947f93f052 (patch)
treed0cbfc81c1e359441c978cc7a96f1bcde75d4754 /infra/presubmit.py
parent21c3e09de9e7eb71906529a75d563ff4028889a9 (diff)
Get list of changed files from branch head, instead of master. (#5048)
* Get list of changed files from branch head, instead of master. Fixes https://github.com/google/oss-fuzz/issues/5022 * Add debug with subprocess.call. * Try again debugginig. * Try again * Fix works!
Diffstat (limited to 'infra/presubmit.py')
-rwxr-xr-xinfra/presubmit.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/infra/presubmit.py b/infra/presubmit.py
index 268a1149..cd6cbb6a 100755
--- a/infra/presubmit.py
+++ b/infra/presubmit.py
@@ -323,14 +323,29 @@ def yapf(paths, validate=True):
def get_changed_files():
"""Return a list of absolute paths of files changed in this git branch."""
- # FIXME: This doesn't work if branch is behind master.
- diff_command = ['git', 'diff', '--name-only', 'FETCH_HEAD']
- return [
- os.path.abspath(path)
- for path in subprocess.check_output(diff_command).decode().splitlines()
- if os.path.isfile(path)
+ main_branch = subprocess.check_output(
+ ['git', 'rev-parse', '--abbrev-ref', 'origin/HEAD']).strip().decode()
+ branch_commit_hash = subprocess.check_output(
+ ['git', 'merge-base', 'FETCH_HEAD', main_branch]).strip().decode()
+
+ diff_commands = [
+ # Return list of modified files in the commits on this branch.
+ ['git', 'diff', '--name-only', branch_commit_hash + '..'],
+ # Return list of modified files from uncommitted changes.
+ ['git', 'diff', '--name-only']
]
+ changed_files = set()
+ for command in diff_commands:
+ file_paths = subprocess.check_output(command).decode().splitlines()
+ for file_path in file_paths:
+ if not os.path.isfile(file_path):
+ continue
+ changed_files.add(file_path)
+ print('Changed files: {changed_files}'.format(
+ changed_files=' '.join(changed_files)))
+ return [os.path.abspath(f) for f in changed_files]
+
def is_test_dir_blocklisted(directory):
"""Returns True if |directory| is blocklisted."""