[Treepkg-commits] r513 - trunk/treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 8 13:06:49 CET 2011


Author: bricks
Date: 2011-03-08 13:06:49 +0100 (Tue, 08 Mar 2011)
New Revision: 513

Modified:
   trunk/treepkg/git.py
Log:
add a copy method for git
drop git functions and use only methods


Modified: trunk/treepkg/git.py
===================================================================
--- trunk/treepkg/git.py	2011-03-08 11:48:26 UTC (rev 512)
+++ trunk/treepkg/git.py	2011-03-08 12:06:49 UTC (rev 513)
@@ -21,35 +21,6 @@
 
     """Base class for Git specific errors raised by TreePKG"""
 
-def checkout(url, localdir, branch=None):
-    """Clones the repository at url into the localdir"""
-    run.call(cmdexpand("git clone -q $url $localdir", **locals()))
-    if branch:
-        run.call(cmdexpand("git checkout -q --track -b local $branch",
-                            **locals()), cwd=localdir)
-
-def update(localdir, branch=None):
-    """Runs git pull on the localdir."""
-    run.call(cmdexpand("git pull -q"), cwd=localdir)
-    if branch:
-        run.call(cmdexpand("git checkout -q $branch", branch=branch),
-                cwd=localdir)
-
-def export(src, dest):
-    """Exports the local branch from src to dest"""
-    dest = dest + os.sep
-    run.call(cmdexpand("git checkout-index -a -f --prefix=$dest", **locals()),
-             cwd=src)
-
-def last_changed_revision(git_working_copy):
-    """Return the SHA1 sum of the latest commit"""
-    output = run.capture_output(cmdexpand("git rev-parse HEAD"),
-                                cwd=git_working_copy)
-    if output is None:
-        raise GitError("Cannot determine last changed revision for %r"
-                       % git_working_copy)
-    return output.strip()
-
 class GitRepository(object):
 
     """Describes a git repository"""
@@ -66,16 +37,38 @@
         self.branch = branch
 
     def checkout(self, localdir):
-        """Checks out the repository into localdir."""
-        checkout(self.url , localdir, self.branch)
+        """Clones the repository at url into the localdir"""
+        run.call(cmdexpand("git clone -q $url $localdir", **locals()))
+        if branch:
+            run.call(cmdexpand("git checkout -q --track -b local $branch",
+                            branch=self.branch), cwd=localdir)
 
     def export(self, localdir, destdir):
         """Exports the working copy in localdir to destdir"""
-        export(localdir, destdir)
+        dest = destdir + os.sep
+        run.call(cmdexpand("git checkout-index -a -f --prefix=$dest", dest=dest),
+             cwd=localdir)
 
+    def copy(self, localdir, destdir):
+        """Copies the working copy to destdir (including .git dir)"""
+        shutils.copytree(localdir, destdir)
+
+    def update(self, localdir, branch=None):
+        """Runs git pull on the localdir."""
+        run.call(cmdexpand("git pull -q"), cwd=localdir)
+        if branch:
+            run.call(cmdexpand("git checkout -q $branch", branch=branch),
+                    cwd=localdir)
+
+
     def last_changed_revision(self, localdir):
-        """Returns the last changed revision of the working copy in localdir"""
-        return last_changed_revision(localdir)
+        """Returns the SHA1 sum of the latest commit in the working copy in localdir"""
+        output = run.capture_output(cmdexpand("git rev-parse HEAD"),
+                                    cwd=localdir)
+        if output is None:
+            raise GitError("Cannot determine last changed revision for %r"
+                           % git_working_copy)
+        return output.strip()
 
     def check_working_copy(self, localdir):
         """FIXME STUB: Not implemented for git"""



More information about the Treepkg-commits mailing list