-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitcheck.py
executable file
·65 lines (47 loc) · 1.47 KB
/
gitcheck.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import os
import sys
import subprocess
import functools
def load_path():
if len(sys.argv) < 2:
print 'usage: %s PATH' % (sys.argv[0])
sys.exit(1)
return sys.argv[1]
def describe_git_repo(directory):
"""describe the git repository at DIRECTORY"""
home = os.getcwd()
os.chdir(directory)
repo = os.path.basename(directory)
outp = subprocess.check_output(['git', 'remote'])
os.chdir(home)
if (len(outp) <= 0):
return { 'path': directory, 'name': repo }
else:
return None
def scan_directories(root):
"""Starting at ROOT, run through all directories and describe
and describe all git repositories found."""
repositories = []
for directory, dirs, files in os.walk(root):
if '.git' in dirs:
repo = describe_git_repo(directory)
if repo is not None:
repositories.append(repo)
return repositories
def display_report(repositories):
"""Given a list of REPOSITORIES, display to screen."""
print ''
print 'The following git repositories have no remote origin:'
print '====================================================='
print ''
for repo in repositories:
print '%s\t%s' % (repo['name'], repo['path'])
# Main program begins
# ========================
def main():
path = load_path()
repositories = scan_directories(path)
display_report(repositories)
if __name__ == '__main__':
main()