[Treepkg-commits] r472 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 9 15:54:56 CET 2010
Author: bricks
Date: 2010-11-09 15:54:55 +0100 (Tue, 09 Nov 2010)
New Revision: 472
Added:
trunk/test/test_git.py
Modified:
trunk/treepkg/git.py
Log:
update git tag detector and add test
Added: trunk/test/test_git.py
===================================================================
--- trunk/test/test_git.py 2010-11-08 17:07:41 UTC (rev 471)
+++ trunk/test/test_git.py 2010-11-09 14:54:55 UTC (rev 472)
@@ -0,0 +1,57 @@
+# Copyright (C) 2010 by Intevation GmbH
+# Authors:
+# Bjoern Ricks <bjoern.ricks at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for the treepkg.git module"""
+
+
+import unittest
+import os
+
+import treepkg.run as run
+from treepkg.cmdexpand import cmdexpand
+from filesupport import FileTestMixin
+
+import treepkg.git as git
+
+class TestTagDetector(unittest.TestCase, FileTestMixin):
+
+ def test_tag(self):
+ dirname = self.create_test_specific_temp_dir()
+ repodir = self.create_temp_dir("repo")
+ clonedir = os.path.join(dirname, "clone")
+ run.call(cmdexpand("git init -q"), cwd=repodir)
+
+ file = open(os.path.join(repodir, "tmp"), "w")
+ file.write("test")
+ file.close()
+
+ run.call(cmdexpand("git add tmp"), cwd=repodir)
+ run.call(cmdexpand("git commit -m \"Add tmp file\""), cwd=repodir)
+ run.call(cmdexpand("git tag tag1"), cwd=repodir)
+ run.call(cmdexpand("git tag tag2"), cwd=repodir)
+ run.call(cmdexpand("git tag anothertag"), cwd=repodir)
+
+ tagdetector1 = git.TagDetector(repodir, "tag*", clonedir)
+ tags = tagdetector1.list_tags()
+ urlrev = tagdetector1.newest_tag_revision()
+
+ self.assertEquals(len(tags), 2)
+ self.assertEquals(urlrev[0], "tag2")
+
+ tagdetector2 = git.TagDetector(dirname, "*tag*", clonedir)
+ tags = tagdetector2.list_tags()
+ urlrev = tagdetector2.newest_tag_revision()
+
+ self.assertEquals(len(tags), 3)
+ self.assertEquals(urlrev[0], "tag2")
+
+ tagdetector3 = git.TagDetector(dirname, "another*", clonedir)
+ tags = tagdetector3.list_tags()
+ urlrev = tagdetector3.newest_tag_revision()
+
+ self.assertEquals(len(tags), 1)
+ self.assertEquals(urlrev[0], "anothertag")
Modified: trunk/treepkg/git.py
===================================================================
--- trunk/treepkg/git.py 2010-11-08 17:07:41 UTC (rev 471)
+++ trunk/treepkg/git.py 2010-11-09 14:54:55 UTC (rev 472)
@@ -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 list_tags(self):
+ self.workingcopy.update_or_checkout()
+ tags = self.workingcopy.list_tags(self.pattern)
+ return sorted(tags)
+
def newest_tag_revision(self):
- self.workingcopy.update_or_checkout()
- candidates = self.workingcopy.list_tags(self.pattern)
- candidates = sorted(candidates)
+ candidates = self.list_tags()
urlrev = (None, None)
if candidates:
newest = candidates[-1]
More information about the Treepkg-commits
mailing list