summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-10-23 12:08:34 +0100
committerSam Thursfield <sam@afuera.me.uk>2014-10-24 16:59:00 +0000
commitc255fc68775fe4c5975155c2932b3ed6ee3625c1 (patch)
tree4a0774f36f9034d8d3a1d7f4d010fad7a80f2cd8
parent35178357f0ba7eafdeebfc621d70ba69f2cd270a (diff)
downloadmorph-c255fc68775fe4c5975155c2932b3ed6ee3625c1.tar.gz
build: Resolve the ref being built in the user's local definitions.git
Most usefully, this patch means that Morph no longer updates its cached copy of definitions.git every time you run `morph build`. Also, it prevents confusion in the following situation. Imagine I have run: morph checkout baserock:baserock/definitions master I then wait a while, during which time someone pushes to 'master' in the definitions.git repo that I cloned from. Now I run: cd master morph build systems/whatever.morph Which commit does it build, the local head of 'master' or the remote head of 'master'? The answer, both before and after this patch, is that it builds the local version of master. But previously, this only happened because of the magic that we have to detect local changes. With this patch, the local change detection could be disabled and `morph build` would still build what the user had checked out as 'master' locally, not whatever 'master' pointed to in the remote repo.
-rw-r--r--morphlib/buildbranch.py16
-rw-r--r--morphlib/plugins/build_plugin.py5
-rw-r--r--morphlib/plugins/deploy_plugin.py4
3 files changed, 18 insertions, 7 deletions
diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py
index 638350e3..cfc4a67f 100644
--- a/morphlib/buildbranch.py
+++ b/morphlib/buildbranch.py
@@ -254,6 +254,10 @@ class BuildBranch(object):
return self._sb.get_config('branch.name')
@property
+ def root_commit(self):
+ return self._root.resolve_ref_to_commit(self.root_ref)
+
+ @property
def root_local_repo_url(self):
return urlparse.urljoin('file://', self._root.dirname)
@@ -291,7 +295,13 @@ def pushed_build_branch(bb, loader, changes_need_pushing, name, email,
unpushed = any(bb.get_unpushed_branches())
if not changes_made and not unpushed:
- yield bb.root_repo_url, bb.root_ref
+ # We resolve the system branch ref to the commit SHA1 here, so that
+ # the build uses whatever commit the user's copy of the root repo
+ # considers the head of that branch to be. If we returned a named
+ # ref, we risk building what the remote considers the head of that
+ # branch to be instead, and we also trigger a needless update in
+ # the cached copy of the root repo.
+ yield bb.root_repo_url, bb.root_commit, bb.root_ref
return
def report_inject(gd):
@@ -318,6 +328,6 @@ def pushed_build_branch(bb, loader, changes_need_pushing, name, email,
remote=remote.get_push_url(), chatty=True)
bb.push_build_branches(push_cb=report_push)
- yield bb.root_repo_url, bb.root_build_ref
+ yield bb.root_repo_url, bb.root_build_ref, bb.root_build_ref
else:
- yield bb.root_local_repo_url, bb.root_build_ref
+ yield bb.root_local_repo_url, bb.root_build_ref, bb.root_build_ref
diff --git a/morphlib/plugins/build_plugin.py b/morphlib/plugins/build_plugin.py
index d4f53e2b..218bd819 100644
--- a/morphlib/plugins/build_plugin.py
+++ b/morphlib/plugins/build_plugin.py
@@ -191,5 +191,6 @@ class BuildPlugin(cliapp.Plugin):
bb, loader=loader, changes_need_pushing=push,
name=name, email=email, build_uuid=build_uuid,
status=self.app.status)
- with pbb as (repo, ref):
- build_command.build(repo, ref, system_filename)
+ with pbb as (repo, commit, original_ref):
+ build_command.build(repo, commit, system_filename,
+ original_ref=original_ref)
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 2bc53a0d..e795e637 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -328,14 +328,14 @@ class DeployPlugin(cliapp.Plugin):
bb, loader=loader, changes_need_pushing=False,
name=name, email=email, build_uuid=build_uuid,
status=self.app.status)
- with pbb as (repo, ref):
+ with pbb as (repo, commit, original_ref):
# Create a tempdir for this deployment to work in
deploy_tempdir = tempfile.mkdtemp(
dir=os.path.join(self.app.settings['tempdir'], 'deployments'))
try:
for system in cluster_morphology['systems']:
self.deploy_system(build_command, deploy_tempdir,
- root_repo_dir, repo, ref, system,
+ root_repo_dir, repo, commit, system,
env_vars, deployments,
parent_location='')
finally: