# HG changeset patch # User Bjoern Ricks # Date 1299586009 0 # Node ID f841b369aa80b8d6414bd56b378b51f012026b46 # Parent e38976f77e26b95dc07d4964691e7f9cd04a9c53 add a copy method for git drop git functions and use only methods diff -r e38976f77e26 -r f841b369aa80 treepkg/git.py --- 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"""