-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-working-copy-check.py
executable file
·45 lines (34 loc) · 1.45 KB
/
git-working-copy-check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
#
import argparse
import os
import sys
import re
import subprocess
class Tool(object):
def __init__(self, root, add_missing_email=None):
self.root = os.path.expanduser(root)
self.add_missing_email = add_missing_email
def run(self):
for root, dirs, files in os.walk(self.root):
if '.git' not in dirs:
continue
del dirs[:]
email = subprocess.check_output(['git', 'config', 'user.email'], cwd=root).strip()
if '@' not in email:
print '*** No e-mail configured in {}'.format(root)
if self.add_missing_email:
print '--> Configuring {}'.format(self.add_missing_email)
cmd = ['git', 'config', 'user.email', self.add_missing_email]
subprocess.check_output(cmd, cwd=root)
else:
print '{} {}'.format(email, root)
@classmethod
def main(cls):
parser = argparse.ArgumentParser(description='Run some checks on git working copies')
parser.add_argument('root', help='Root in which to search for git working copies')
parser.add_argument('--add-missing-email', help='If user.email setting is missing, configure this one')
args = parser.parse_args()
cls(root=args.root, add_missing_email=args.add_missing_email).run()
if __name__ == '__main__':
Tool.main()