summaryrefslogtreecommitdiff
path: root/morphlib/gitdir.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-08-08 23:05:13 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2014-08-12 11:00:29 +0100
commit6c9a5d65d615abf75e640f5ceda332ef42854d57 (patch)
tree382deb1ed959ed5f9e682bacd13b198ba5a95388 /morphlib/gitdir.py
parent54e03f2e5005775c8e8c434094256feccd91c488 (diff)
downloadmorph-6c9a5d65d615abf75e640f5ceda332ef42854d57.tar.gz
Avoid creating and pushing temporary build branches when they aren't necessary.
Sorry about the big lump, I can split it into a nicer set of changes, but they didn't naturally emerge in a nice series. This creates a pushed_build_branch context manager, to eliminate code duplication between build and deploy. Rather than the build branch being constructed knowing whether it needs to push the branch, it infers that from the state of the repositories, and whether a local build would be possible. If there are no uncommitted changes and all local branches are pushed, then it doesn't create temporary branches or push them, and instead uses what it already has. It will currently create and use temporary build branches even for chunks that have no local changes, but it's pretty cheap, and doesn't require re-working the build-ref injection code to check whether there are local changes.
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r--morphlib/gitdir.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py
index 5b0693cb..3966a0f0 100644
--- a/morphlib/gitdir.py
+++ b/morphlib/gitdir.py
@@ -282,6 +282,16 @@ class Remote(object):
return self._get_remote_url(self.name, 'push')
@staticmethod
+ def _parse_ls_remote_output(output): # pragma: no cover
+ for line in output.splitlines():
+ sha1, refname = line.split(None, 1)
+ yield sha1, refname
+
+ def ls(self): # pragma: no cover
+ out = self.gd._runcmd(['git', 'ls-remote', self.get_fetch_url()])
+ return self._parse_ls_remote_output(out)
+
+ @staticmethod
def _parse_push_output(output):
for line in output.splitlines():
m = PUSH_FORMAT.match(line)
@@ -484,6 +494,10 @@ class GitDirectory(object):
except cliapp.AppException as e:
raise InvalidRefError(self, ref)
+ def disambiguate_ref(self, ref): # pragma: no cover
+ out = self._runcmd(['git', 'rev-parse', '--symbolic-full-name', ref])
+ return out.strip()
+
def resolve_ref_to_commit(self, ref):
return self._rev_parse('%s^{commit}' % ref)