I have created a simple script which uses GitPython to tag the latest commit on a specific branch which has already been checked out.
from git import Repo
def TagRepo(path, tag):
repo = Repo(path)
repo.create_tag(tag)
repo.remotes.origin.push(tag)
if __name__ == "__main__":
parser = optparse.OptionParser('usage: %prog [options] ')
parser.add_option('-p', '--path', dest='path', help='path to repo')
parser.add_option('-t', '--tag', dest='tag', help='Tag label')
(options, args) = parser.parse_args()
TagRepo(options.path, options.tag)
I want to improve it so that I can pass it a specific commit's SHA and tag that instead of the latest commit on the branch but I can't see how to do that with GitPython.