Skip to content

Commit 48e6e50

Browse files
xuanyang15copybara-github
authored andcommitted
chore: Update check_new_py_files.sh to run in multiple VCS environments
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 941262556
1 parent ffa1843 commit 48e6e50

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

scripts/check_new_py_files.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@
1616

1717
exit_code=0
1818

19-
# Get list of newly added files using diff-filter=A
20-
# Using process substitution to avoid subshell and handle spaces in filenames
19+
get_added_files() {
20+
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
21+
git diff --cached --name-only --diff-filter=A
22+
elif jj root >/dev/null 2>&1; then
23+
jj diff --summary 2>/dev/null | awk '/^A / {print $2}'
24+
elif hg root >/dev/null 2>&1; then
25+
hg status --added --no-status 2>/dev/null
26+
elif g4 info >/dev/null 2>&1; then
27+
g4 opened 2>/dev/null | awk '/ - add / {print $1}' | sed 's/#.*//'
28+
elif p4 info >/dev/null 2>&1; then
29+
p4 opened 2>/dev/null | awk '/ - add / {print $1}' | sed 's/#.*//'
30+
fi
31+
}
32+
2133
while read -r file; do
2234
# Check if file is not empty (happens if no new files)
2335
if [[ -n "$file" ]]; then
24-
if [[ "$file" == src/google/adk/*.py ]]; then
36+
if [[ "$file" == */google/adk/*.py ]] || [[ "$file" == google/adk/*.py ]]; then
2537
filename=$(basename "$file")
2638
if [[ ! "$filename" == _* ]]; then
2739
echo "Error: New Python file '$file' must have a '_' prefix."
@@ -32,6 +44,6 @@ while read -r file; do
3244
fi
3345
fi
3446
fi
35-
done < <(git diff --cached --name-only --diff-filter=A)
47+
done < <(get_added_files)
3648

3749
exit $exit_code

0 commit comments

Comments
 (0)