diff treepkg/git.py @ 509:c4288095887f

update git tag detector and add test
author Bjoern Ricks <bricks@intevation.de>
date Tue, 09 Nov 2010 14:54:55 +0000
parents 29f6d1f5cc53
children 0365b2c7ac00
line wrap: on
line diff
--- a/treepkg/git.py	Mon Nov 08 17:07:41 2010 +0000
+++ b/treepkg/git.py	Tue Nov 09 14:54:55 2010 +0000
@@ -21,15 +21,12 @@
 
     """Base class for Git specific errors raised by TreePKG"""
 
-def checkout(url, localdir, branch=None):
+def checkout(url, localdir, branch="master"):
     """Clones the repository at url into the localdir"""
-    run.call(cmdexpand("git clone $url $localdir", **locals()))
+    run.call(cmdexpand("git clone -q $url $localdir", **locals()))
     if branch:
-        run.call(cmdexpand("git checkout --track -b local $branch",
+        run.call(cmdexpand("git checkout -q --track -b local $branch",
                             **locals()), cwd=localdir)
-    else:
-        run.call(cmdexpand("git checkout --track -b local master"),
-                            cwd=localdir)
 
 def update(localdir, revision=None):
     """Runs git pull on the localdir."""
@@ -68,7 +65,6 @@
     def checkout(self, localdir):
         """Checks out the repository into localdir."""
         checkout(self.url , localdir, self.branch)
-        update(localdir)
 
     def export(self, localdir, destdir):
         """Exports the working copy in localdir to destdir"""
@@ -107,7 +103,8 @@
         """Updates the working copy or creates by checking out the repository.
            Revision number included for compatibility
         """
-        if os.path.exists(self.localdir):
+        gitdir = os.path.join(self.localdir, ".git")
+        if os.path.exists(gitdir):
             self.log_info("Updating the working copy in %r", self.localdir)
             update(self.localdir, self.repository.branch)
         else:
@@ -131,11 +128,11 @@
 
     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)
+        output = run.capture_output(cmdexpand("git rev-parse $refname",
+            refname=refname), cwd=self.localdir)
         if output is None:
             raise GitError("Cannot determine revision for %r"
-                           % git_working_copy)
+                           % self.localdir)
         return output.strip()
 
 class TagDetector:
@@ -153,10 +150,13 @@
         repo = GitRepository(url)
         self.workingcopy = GitWorkingCopy(repo, localdir)
 
-    def newest_tag_revision(self):
+    def list_tags(self):
         self.workingcopy.update_or_checkout()
-        candidates = self.workingcopy.list_tags(self.pattern)
-        candidates = sorted(candidates)
+        tags = self.workingcopy.list_tags(self.pattern)
+        return sorted(tags)
+
+    def newest_tag_revision(self):
+        candidates = self.list_tags()
         urlrev = (None, None)
         if candidates:
             newest = candidates[-1]
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)