Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to show commit hash with -c -C #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ Options
-q, --quiet Display info only when repository needs action
-e, --email Send an email with result as html, using mail.properties parameters
--init-email Initialize mail.properties file (has to be modified by user using JSON Format)
-c --commit Show short commit hash (git rev-parse --short HEAD)
-C --Commit Show long commit hash (git rev-parse HEAD)


French version
~~~~~~~~~~~~~~
Expand Down
38 changes: 34 additions & 4 deletions gitcheck/gitcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class html:
prjname = ""
path = ""
timestamp = ""
commit = ""


def showDebug(mess, level='info'):
Expand Down Expand Up @@ -109,9 +110,11 @@ def checkRepository(rep, branch):

topush = ""
topull = ""
commit = ""
html.topush = ""
html.topull = ""
if branch != "":

remotes = getRemoteRepositories(rep)
hasremotes = bool(remotes)
for r in remotes:
Expand Down Expand Up @@ -167,6 +170,16 @@ def checkRepository(rep, branch):
else:
repname = rep

# @Xuning: print commit hash if asked
if argopts.get('commit', False):
gitCommit = getLatestShortCommit(rep)
html.commit = '(%s)' % (gitCommit)
commit = "(%s)" % (gitCommit)
elif argopts.get('Commit', False):
gitCommit = getLatestCommit(rep)
html.commit = '(%s)' % (gitCommit)
commit = "(%s)" % (gitCommit)

if ischange:
prjname = "%s%s%s" % (colortheme['prjchanged'], repname, colortheme['default'])
html.prjname = '<b style="color:red">%s</b>' % (repname)
Expand Down Expand Up @@ -201,7 +214,9 @@ def checkRepository(rep, branch):

else:
cbranch = "%s%s" % (colortheme['branchname'], branch)
print("%(prjname)s/%(cbranch)s %(strlocal)s%(topush)s%(topull)s" % locals())
print("%(prjname)s/%(cbranch)s %(commit)s %(strlocal)s%(topush)s%(topull)s" % locals())



if argopts.get('verbose', False):
if ischange > 0:
Expand Down Expand Up @@ -327,6 +342,16 @@ def getAllBranches(rep):

return [b[2:] for b in branch]

# @Xuning: Get latest commit for repository on the branch
def getLatestShortCommit(rep):
gitCommit = gitExec(rep, "rev-parse --short HEAD"
% locals())
return gitCommit.strip()

def getLatestCommit(rep):
gitCommit = gitExec(rep, "rev-parse HEAD"
% locals())
return gitCommit.strip()

def getRemoteRepositories(rep):
result = gitExec(rep, "remote"
Expand All @@ -347,7 +372,6 @@ def gitExec(path, cmd):
raise Exception(errors)
return output.decode('utf-8')


# Check all git repositories
def gitcheck():
showDebug("Global Vars: %s" % argopts)
Expand Down Expand Up @@ -463,15 +487,17 @@ def usage():
print(" -a, --all-branch Show the status of all branches")
print(" -l <re>, --localignore=<re> ignore changes in local files which match the regex <re>")
print(" --init-email Initialize mail.properties file (has to be modified by user using JSON Format)")
print(" -c --commit Show short commit hash (git rev-parse --short HEAD) ")
print(" -C --Commit Show long commit hash (git rev-parse HEAD) ")


def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
"vhrubw:i:d:m:q:e:al:",
"vhrubcCw:i:d:m:q:e:al:",
[
"verbose", "debug", "help", "remote", "untracked", "bell", "watch=", "ignore-branch=",
"verbose", "debug", "help", "remote", "untracked", "bell", "commit", "Commit", "watch=", "ignore-branch=",
"dir=", "maxdepth=", "quiet", "email", "init-email", "all-branch", "localignore="
]
)
Expand Down Expand Up @@ -521,6 +547,10 @@ def main():
argopts['email'] = True
elif opt in ["-a", "--all-branch"]:
argopts['checkall'] = True
elif opt in ["-c", "--commit"]:
argopts['commit'] = True
elif opt in ["-C", "--Commit"]:
argopts['Commit'] = True
elif opt in ["--init-email"]:
initEmailConfig()
sys.exit(0)
Expand Down