Skip to content

Commit 890fee3

Browse files
authored
Merge pull request #32 from glennular/multi-dir-support
Multi dir support
2 parents 92644cd + 6181368 commit 890fee3

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

gitcheck/gitcheck.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,25 @@ def showDebug(mess, level='info'):
7272
# Search all local repositories from current directory
7373
def searchRepositories():
7474
showDebug('Beginning scan... building list of git folders')
75-
dir = argopts.get('searchDir', None)
76-
if dir is not None and dir[-1:] == '/':
77-
dir = dir[:-1]
78-
curdir = os.path.abspath(os.getcwd()) if dir is None else dir
79-
showDebug(" Scan git repositories from %s" % curdir)
80-
81-
html.path = curdir
82-
startinglevel = curdir.count(os.sep)
83-
repo = []
84-
85-
for directory, dirnames, filenames in os.walk(curdir):
86-
level = directory.count(os.sep) - startinglevel
87-
if argopts.get('depth', None) is None or level <= argopts.get('depth', None):
88-
if '.git' in dirnames:
89-
showDebug(" Add %s repository" % directory)
90-
repo.append(directory)
91-
92-
repo.sort()
93-
showDebug('Done')
94-
return repo
75+
dirs = argopts.get('searchDir', [os.path.abspath(os.getcwd())])
76+
repo = set()
77+
for curdir in dirs:
78+
if curdir[-1:] == '/':
79+
curdir = curdir[:-1]
80+
showDebug(" Scan git repositories from %s" % curdir)
81+
82+
html.path = curdir
83+
startinglevel = curdir.count(os.sep)
84+
85+
for directory, dirnames, filenames in os.walk(curdir):
86+
level = directory.count(os.sep) - startinglevel
87+
if argopts.get('depth', None) is None or level <= argopts.get('depth', None):
88+
if '.git' in dirnames:
89+
showDebug(" Add %s repository" % directory)
90+
repo.add(directory)
9591

92+
showDebug('Done')
93+
return sorted(repo)
9694

9795
# Check state of a git repository
9896
def checkRepository(rep, branch):
@@ -457,7 +455,7 @@ def usage():
457455
print(" -b, --bell bell on action needed")
458456
print(" -w <sec>, --watch=<sec> after displaying, wait <sec> and run again")
459457
print(" -i <re>, --ignore-branch=<re> ignore branches matching the regex <re>")
460-
print(" -d <dir>, --dir=<dir> Search <dir> for repositories")
458+
print(" -d <dir>, --dir=<dir> Search <dir> for repositories (can be used multiple times)")
461459
print(" -m <maxdepth>, --maxdepth=<maxdepth> Limit the depth of repositories search")
462460
print(" -q, --quiet Display info only when repository needs action")
463461
print(" -e, --email Send an email with result as html, using mail.properties parameters")
@@ -506,7 +504,10 @@ def main():
506504
elif opt in ["-l", "--localignore"]:
507505
argopts['ignoreLocal'] = arg
508506
elif opt in ["-d", "--dir"]:
509-
argopts['searchDir'] = arg
507+
dirs = argopts.get('searchDir', [])
508+
if (dirs == []):
509+
argopts['searchDir'] = dirs
510+
dirs.append(arg)
510511
elif opt in ["-m", '--maxdepth']:
511512
try:
512513
argopts['depth'] = int(arg)

0 commit comments

Comments
 (0)