summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-14 12:58:32 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-20 13:54:21 +0000
commit73e22af6a9c83f9e9e1d79f4018f4562bf5ae1b2 (patch)
tree62aee9b61be3be5f72e0fbad34b1fc484c09e432
parent86cb3fb50a8d04911f5191eb80edb2295350e120 (diff)
downloadmorph-73e22af6a9c83f9e9e1d79f4018f4562bf5ae1b2.tar.gz
Add functionality for doing git commands in a directory
These commands are: * git fat <init|push|pull> * 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.
-rw-r--r--morphlib/gitdir.py34
1 files 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