Skip to content

Commit

Permalink
New flag that only shows the out of sync repos
Browse files Browse the repository at this point in the history
  • Loading branch information
umrysh committed Jan 17, 2014
1 parent 1c6917d commit 3be6a95
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gitcheck.py
Expand Up @@ -38,7 +38,7 @@ def searchRepositories(dir=None):


# Check state of a git repository
def checkRepository(rep, verbose=False, ignoreBranch=r'^$'):
def checkRepository(rep, verbose=False, ignoreBranch=r'^$',unsynced=False):
aitem = []
mitem = []
ditem = []
Expand Down Expand Up @@ -104,7 +104,11 @@ def checkRepository(rep, verbose=False, ignoreBranch=r'^$'):
else:
strlocal = ""

print("%(prjname)s/%(branch)s %(strlocal)s%(topush)s%(topull)s" % locals())
if unsynced:
if topush != "" or topull != "" or strlocal != "":
print("%(prjname)s/%(branch)s %(strlocal)s%(topush)s%(topull)s" % locals())
else:
print("%(prjname)s/%(branch)s %(strlocal)s%(topush)s%(topull)s" % locals())
if verbose:
if ischange > 0:
filename = " |--Local"
Expand Down Expand Up @@ -224,7 +228,7 @@ def gitExec(rep, command):


# Check all git repositories
def gitcheck(verbose, checkremote, ignoreBranch, bellOnActionNeeded, shouldClear, searchDir):
def gitcheck(verbose, checkremote, ignoreBranch, bellOnActionNeeded, shouldClear, searchDir,unsynced):
repo = searchRepositories(searchDir)
actionNeeded = False

Expand All @@ -237,7 +241,7 @@ def gitcheck(verbose, checkremote, ignoreBranch, bellOnActionNeeded, shouldClear
print(tcolor.RESET)

for r in repo:
if checkRepository(r, verbose, ignoreBranch):
if checkRepository(r, verbose, ignoreBranch,unsynced):
actionNeeded = True

if actionNeeded and bellOnActionNeeded:
Expand All @@ -251,6 +255,7 @@ def usage():
print(" -v, --verbose Show files & commits")
print(" -r, --remote force remote update(slow)")
print(" -b, --bell bell on action needed")
print(" -u, --unsynced Only show unsynced repos")
print(" -w <sec>, --watch <sec> after displaying, wait <sec> and run again")
print(" -i <re>, --ignore-branch <re> ignore branches matching the regex <re>")
print(" -d <dir>, Search <dir> for repositories")
Expand All @@ -260,8 +265,8 @@ def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
"vhrbw:i:d:",
["verbose", "help", "remote", "bell", "watch:", "ignore-branch:",
"vhrbuw:i:d:",
["verbose", "help", "remote", "bell", "unsynced", "watch:", "ignore-branch:",
"dir:"])
except getopt.GetoptError, e:
if e.opt == 'w' and 'requires argument' in e.msg:
Expand All @@ -272,6 +277,7 @@ def main():
checkremote = False
watchInterval = 0
bellOnActionNeeded = False
unsynced = False
searchDir = None
ignoreBranch = r'^$' # empty string
for opt, arg in opts:
Expand All @@ -283,6 +289,8 @@ def main():
checkremote = True
if opt in ("-b", "--bell"):
bellOnActionNeeded = True
if opt in ("-u", "--unsynced"):
unsynced = True
if opt in ("-w", "--watch"):
watchInterval = arg
if opt in ("-i", "--ignore-branch"):
Expand All @@ -301,7 +309,8 @@ def main():
ignoreBranch,
bellOnActionNeeded,
watchInterval > 0,
searchDir
searchDir,
unsynced
)
if watchInterval:
time.sleep(float(watchInterval))
Expand Down

0 comments on commit 3be6a95

Please sign in to comment.