changeset 550:f841b369aa80

add a copy method for git drop git functions and use only methods
author Bjoern Ricks <bricks@intevation.de>
date Tue, 08 Mar 2011 12:06:49 +0000
parents e38976f77e26
children d2b294e4ede7
files treepkg/git.py
diffstat 1 files changed, 27 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/git.py	Tue Mar 08 11:48:26 2011 +0000
+++ b/treepkg/git.py	Tue Mar 08 12:06:49 2011 +0000
@@ -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"""
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)