Skip to content

Instantly share code, notes, and snippets.

@sleepygarden
Created September 13, 2013 18:05
Show Gist options
  • Save sleepygarden/6554050 to your computer and use it in GitHub Desktop.
Save sleepygarden/6554050 to your computer and use it in GitHub Desktop.
simple python git interface with tagging and tag searching.
# gitlog.py
# -*- coding: utf-8 -*-
import subprocess
import sys
#tag ideas? you can implement your own!
INFO_TAG="[INFO]" # just a heads up, default tag
FUCK_TAG="[FUCK]" # something broke! :c
CLEAN_TAG="[CLEAN]" # ripped out stuff, removed comments, etc
TODO_TAG="[TODO]" # didn't finish what i was doing
RESOLVE_TAG="[RESOLVE]" # the last todo got fixed. if TODOS > RESOLVES, you're not done yet __TODO__ implement reporting on this
STASH_TAG="[STASH]" # end of day commits, half baked ideas, code sketches, nothing noteworthy to mention but still pushing changes, stash in server
BEER_TAG="[BEER]" # genius, beautiful, elegant code that will look like shit in the morning. AKA, review / QA this code
CRIT_TAG="[CRIT]" # mega super important turning point
NOTE_TAG="[NOTE]" # added /edited documentation
#utter horseshit
BANG_TAG="[!]" #snake, get down!!
UTTER_HORSESHIT_TAG="[UTTER HORSESHIT]"
FAIC_TAG="[ >:( ]" # anger faic!
KAWAII_TAG="[~ugu~]" # uguuuuuuu~~~~
#faces n tables
UGH_TAG=u"[ ಠ_ಠ ]"
TABLEFLIP_TAG=u"[ ╯°□°)╯┻━┻ ]"
TABLEFLIP_SOB_TAG=u"[ (ノಥ益ಥ)ノ ┻━┻ ]"
TABLEFIX_TAG=u"[ ┬──┬ ¯\_(ツ) ]"
DOUBLETABLE_TAG=u"[ ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻ ]"
WHOEVENGIVES_TAG=u"[ ┻━┻ ︵ ¯\(ツ)/¯ ︵ ┻━┻ ]"
FADTABLE_SAD_TAG=u"[ ┬─┬ノ( º _ ºノ) ]"
MEGAFLIP_TAG=u"[ (ノಠ益ಠ)ノ彡┻━┻ ]"
# def initTags():
# with "tags.txt" as f:
# if f:
# #load user custom tags
# print "loaded tags i guess"
def getCommitsByTag(tag):
ret = list()
for commit in getCommitLog():
if tag in commit:ret.append(commit)
return ret
def getCommitLog():
return subprocess.check_output(["git", "log", "--pretty=format:\"%an: %s\""]).split("\n")
def getFuckCommits():
return getTaggedCommits(FUCK_TAG)
def commitWithTag(msg,tag=INFO_TAG):
print subprocess.check_output(["git", "commit", "-am","{} {}".format(tag,msg)])
def runCmd(cmds):
print subprocess.check_output(cmds)
def quietRun(cmds):
try:
print subprocess.check_output(cmds)
except subprocess.CalledProcessError as e:
print e
if __name__ == "__main__": # make calling gitfuck.py transparent with calling git
# initTags()
try:
if len(sys.argv) > 3:
runCmds(sys.argv) # if not git fuck relevant git, then just call runCmd with sys.args
elif len(sys.argv) == 3:
commitWithTag(sys.argv[1],tag=sys.argv[0])
elif len(sys.argv) == 2:
# check for special commands, like TODO gets
commitWithTag(sys.argv[0])
else:
print "GITFUQ HELP"
except subprocess.CalledProcessError as e:
print e
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment