Skip to content

Commit eea7f94

Browse files
committed
Make git config check more robust
Resolves #58
1 parent 8025ce2 commit eea7f94

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

pre_commit_hooks/check_git_config_email.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ def main(argv=None):
2929

3030
retval = 0
3131
if args.domains:
32-
user_email = subprocess.check_output(["git", "config", "--get", "user.email"])
33-
user_email = user_email.decode().strip()
34-
if not any((user_email.endswith(x) for x in args.domains)):
32+
proc = subprocess.run(
33+
["git", "config", "--get", "user.email"],
34+
check=False,
35+
capture_output=True,
36+
text=True,
37+
)
38+
user_email = proc.stdout.strip()
39+
if not user_email:
40+
print("Git config email is not set.")
41+
retval = 1
42+
elif "@" not in user_email:
43+
print("Git config email does not look like an email address.")
44+
print("Git config email: " + user_email)
45+
retval = 1
46+
elif not any((user_email.endswith("@" + x) for x in args.domains)):
3547
print("Git config email is from an unexpected domain.")
3648
print("Git config email: " + user_email)
3749
print("Expected domains: " + str(args.domains))

0 commit comments

Comments
 (0)