Skip to content

Commit 2091792

Browse files
Ignore if no changed files found
1 parent d3d6842 commit 2091792

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/qa

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ def code_quality(src, default_branch, event, workspace, build_path, build_type):
2828

2929
# Find files
3030
if event == "pull_request":
31-
diff_command = f"git diff --name-only origin/{default_branch}...HEAD {src} | grep '\{files_pattern}$'"
31+
diff_command = f"git diff --name-only origin/{default_branch}...HEAD {src} | grep '\{files_pattern}$' || true"
3232
else:
33-
diff_command = f"git ls-files --directory {src} | grep '\{files_pattern}$'"
33+
diff_command = f"git ls-files --directory {src} | grep '\{files_pattern}$' || true"
3434

35-
files = subprocess.run(
35+
result = subprocess.run(
3636
diff_command, shell=True, capture_output=True, text=True
3737
).stdout.strip()
38-
files = [f for f in files.split("\n")]
38+
39+
files = [f for f in result.split("\n")] if result != "" else []
40+
41+
if event == "push":
42+
if len(files) == 0:
43+
raise ValueError(f"No files matching pattern \"{files_pattern}\" found on push event. Impossible!")
3944

4045
# Run tools
41-
if files:
42-
file_count = len(files)
46+
file_count = len(files)
47+
if file_count > 0:
4348
print(f"Format {file_count} file(s)")
4449
subprocess.run(["clang-format", "-i"] + files, check=True)
4550

0 commit comments

Comments
 (0)