diff options
Diffstat (limited to 'devbot/git.py')
-rw-r--r-- | devbot/git.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/devbot/git.py b/devbot/git.py index b9008af..1e361f0 100644 --- a/devbot/git.py +++ b/devbot/git.py @@ -1,7 +1,20 @@ import os +import subprocess from devbot import command +def _chdir(func): + def wrapped(*args, **kwargs): + orig_cwd = os.getcwd() + + os.chdir(args[0].local) + result = func(*args, **kwargs) + os.chdir(orig_cwd) + + return result + + return wrapped + class Module: def __init__(self, path=None, name=None, remote=None, branch="master", tag=None, retry=10): @@ -45,6 +58,40 @@ class Module: command.run(["git", "merge", "--ff-only", "origin/%s" % self._branch]) + @_chdir + def checkout(self, revision=None): + if revision is None: + revision = self.tag + if revision is None: + revision = self._branch + + command.run(["git", "checkout", revision]) + + @_chdir + def describe(self): + return subprocess.check_output(["git", "describe"]).strip() + + @_chdir + def get_annotation(self, tag): + # FIXME this is fragile, there must be a better way + + show = subprocess.check_output(["git", "show", tag]) + + annotation = [] + for line in show.split("\n"): + ignore = False + for start in ["tag ", "Tagger: ", "Date: "]: + if line.startswith(start): + ignore = True + + if line.startswith("commit "): + break + + if not ignore: + annotation.append(line) + + return "\n".join(annotation) + def clean(self): try: os.chdir(self.local) |