summaryrefslogtreecommitdiff
path: root/morphlib/gitdir.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-11 17:38:16 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-22 13:49:25 +0000
commit0b4e147009bffa7b720ee767633e3acf3bb68c3a (patch)
tree12448f87519c8738444618f53eb6ed49f632de92 /morphlib/gitdir.py
parentd83d6ad7230eb27afae4169330681967bb20dcfa (diff)
downloadmorph-0b4e147009bffa7b720ee767633e3acf3bb68c3a.tar.gz
GitDir: Add GitIndex class
This represents the state of the index of a GitDirectory. Methods that use the index are now used via the GitIndex class, rather than using the default index, as previously used when the methods were in GitDirectory. GitIndex may be constructed with an alternative path, which can be used to manipulate a git checkout without altering a developer's view of the repository i.e. The working tree and default index. This is needed for `morph build` and `morph deploy` to handle the build without commit logic.
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r--morphlib/gitdir.py34
1 files changed, 2 insertions, 32 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py
index 4ba4cd9c..9020506a 100644
--- a/morphlib/gitdir.py
+++ b/morphlib/gitdir.py
@@ -16,9 +16,7 @@
# =*= License: GPL-2 =*=
-import collections
import cliapp
-import glob
import os
import morphlib
@@ -226,36 +224,8 @@ class GitDirectory(object):
output = self._runcmd(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
return output.strip()
- def _get_status(self):
- '''Runs git status and formats its output into something more useful.
-
- This runs git status such that unusual filenames are preserved
- and returns its output in a sequence of (status_code, to_path,
- from_path).
-
- from_path is None unless the status_code says there was a rename,
- in which case it is the path it was renamed from.
-
- Untracked and ignored changes are also included in the output,
- their status codes are '??' and '!!' respectively.
-
- '''
- status = self._runcmd(['git', 'status', '-z', '--ignored'])
- tokens = collections.deque(status.split('\0'))
- while True:
- tok = tokens.popleft()
- # Terminates with an empty token, since status ends with a \0
- if not tok:
- return
-
- code = tok[:2]
- to_path = tok[3:]
- yield code, to_path, tokens.popleft() if code[0] == 'R' else None
-
- def get_uncommitted_changes(self):
- for code, to_path, from_path in self._get_status():
- if code not in ('??', '!!'):
- yield code, to_path, from_path
+ def get_index(self, index_file=None):
+ return morphlib.gitindex.GitIndex(self, index_file)
def store_blob(self, blob_contents):
'''Hash `blob_contents`, store it in git and return the sha1.