From 73e22af6a9c83f9e9e1d79f4018f4562bf5ae1b2 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 14 Mar 2014 12:58:32 +0000 Subject: Add functionality for doing git commands in a directory These commands are: * git fat * git pull They are required for the morph add-binary and push/pull plugins. Also make sure that GitDirectory is working in the root directory of the specified git repository, and add some helper functions for handling paths of files in the working tree. --- morphlib/gitdir.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index 15079231..15c0ee9f 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -317,6 +317,14 @@ class Remote(object): self._parse_push_output(out), err) return self._parse_push_output(out) + def pull(self, branch=None): # pragma: no cover + if branch: + repo = self.get_fetch_url() + ret = self.gd._runcmd(['git', 'pull', repo, branch]) + else: + ret = self.gd._runcmd(['git', 'pull']) + return ret + class GitDirectory(object): @@ -330,7 +338,11 @@ class GitDirectory(object): ''' def __init__(self, dirname): - self.dirname = dirname + self.dirname = morphlib.util.find_root(dirname, '.git') + # if we are in a bare repo, self.dirname will now be None + # so we just use the provided dirname + if not self.dirname: + self.dirname = dirname def _runcmd(self, argv, **kwargs): '''Run a command at the root of the git directory. @@ -616,12 +628,30 @@ class GitDirectory(object): ['git', 'describe', '--always', '--dirty=-unreproducible']) return version.strip() + def fat_init(self): # pragma: no cover + return self._runcmd(['git', 'fat', 'init']) + + def fat_push(self): # pragma: no cover + return self._runcmd(['git', 'fat', 'push']) + + def fat_pull(self): # pragma: no cover + return self._runcmd(['git', 'fat', 'pull']) + + def has_fat(self): # pragma: no cover + return '.gitfat' in self.list_files() + + def join_path(self, path): # pragma: no cover + return os.path.join(self.dirname, path) + + def get_relpath(self, path): # pragma: no cover + return os.path.relpath(path, self.dirname) + def init(dirname): '''Initialise a new git repository.''' + cliapp.runcmd(['git', 'init'], cwd=dirname) gd = GitDirectory(dirname) - gd._runcmd(['git', 'init']) return gd -- cgit v1.2.1