Skip to content

Commit d043c41

Browse files
committed
Validate email of git configuration
This regex matches a basic email pattern. Change-Id: I7196a97db325c73f3b88462b69edc2ddc7d0fbce
1 parent eec9e7f commit d043c41

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

scripts/check-repo.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ if ! command -v git &>/dev/null; then
2020
throw "git not installed."
2121
fi
2222

23+
# Retrieve git email.
24+
GIT_EMAIL=$(git config user.email)
25+
26+
# Check if email is set.
27+
if [ -z "$GIT_EMAIL" ]; then
28+
throw "Git email is not set."
29+
fi
30+
31+
# Validate email using a regex.
32+
# This regex matches a basic email pattern.
33+
if ! [[ "$GIT_EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
34+
throw "Git email '$GIT_EMAIL' is not valid."
35+
fi
36+
2337
# 1. Sleep for a random number of milliseconds
2438
# The time interval is important to reduce unintended network traffic.
2539
((CURRENT_STEP++))

0 commit comments

Comments
 (0)