changeset 508:29f6d1f5cc53

add a tag detector for git
author Bjoern Ricks <bricks@intevation.de>
date Mon, 08 Nov 2010 17:07:41 +0000
parents c8268d40d35d
children c4288095887f
files treepkg/git.py
diffstat 1 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/git.py	Mon Nov 08 16:40:19 2010 +0000
+++ b/treepkg/git.py	Mon Nov 08 17:07:41 2010 +0000
@@ -123,3 +123,46 @@
     def last_changed_revision(self):
         """Returns the last changed rev of the working copy"""
         return self.repository.last_changed_revision(self.localdir)
+
+    def list_tags(self, pattern):
+        output = run.capture_output(cmdexpand("git tag -l $pattern",
+            pattern=pattern), cwd=self.localdir)
+        return output.splitlines()
+
+    def get_revision(self, refname="HEAD"):
+        """Return the SHA1 sum of the latest commit"""
+        output = run.capture_output(cmdexpand("git rev-parse $id",
+            refname=refname), cwd=git_working_copy)
+        if output is None:
+            raise GitError("Cannot determine revision for %r"
+                           % git_working_copy)
+        return output.strip()
+
+class TagDetector:
+
+    """Class to detect tags from a git repository
+
+    The tags are found using the parameters:
+      url -- The url of the git repository to use
+      pattern -- A regular expression matching the tags
+    """
+
+    def __init__(self, url, pattern, localdir):
+        self.url = url
+        self.pattern = pattern
+        repo = GitRepository(url)
+        self.workingcopy = GitWorkingCopy(repo, localdir)
+
+    def newest_tag_revision(self):
+        self.workingcopy.update_or_checkout()
+        candidates = self.workingcopy.list_tags(self.pattern)
+        candidates = sorted(candidates)
+        urlrev = (None, None)
+        if candidates:
+            newest = candidates[-1]
+            try:
+                rev = self.workingcopy.get_revision(newest)
+                urlrev = (newest, rev)
+            except GitError:
+                pass
+        return urlrev
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)