summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2014-08-10 20:29:43 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2014-08-12 18:07:41 +0100
commit0f9c9e2ff3c9afe00735fa986200ac5fdcc8f79e (patch)
tree95f93aea389a1988b3267d8d4af40d1ac78ec5b7 /morphlib
parent2e5d8664920453ede30b450c7b39ac3a0bc141bb (diff)
downloadmorph-0f9c9e2ff3c9afe00735fa986200ac5fdcc8f79e.tar.gz
Fix `morph edit` when repo has the same ref as system branch
There was a check in it to see whether it needed to do the git branch and git checkout based on whether the name of the branch matched that in the morphology. This had a couple of problems: 1. Now that we aren't always building from HEAD, we need to be able to roll its commit back, so using the existing branch isn't always the best idea. 2. It only checks the "ref" field, not "unpetrify-ref", so even though we clone the right ref in there, it's checking the commit id against the system branch name, so would always try to re-create the branch, and fail when it already exists. So now, we remove the original ref and re-create it with our preferred HEAD. A better solution might be to change the clone logic to not automatically checkout HEAD, and instead require an explicit branch then checkout, but the initial clone logic is shared with build, and I didn't feel like tracking down all the different places that it was used.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/gitdir.py13
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py14
2 files changed, 22 insertions, 5 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py
index 3966a0f0..fea26c2e 100644
--- a/morphlib/gitdir.py
+++ b/morphlib/gitdir.py
@@ -495,8 +495,17 @@ class GitDirectory(object):
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()
+ try:
+ out = self._runcmd(['git', 'rev-parse', '--symbolic-full-name',
+ ref])
+ return out.strip()
+ except cliapp.AppException: # ref not found
+ if ref.startswith('refs/heads/'):
+ return ref
+ elif ref.startswith('heads/'):
+ return 'refs/' + ref
+ else:
+ return 'refs/heads/' + ref
def resolve_ref_to_commit(self, ref):
return self._rev_parse('%s^{commit}' % ref)
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 434ff6af..36f720aa 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -309,9 +309,17 @@ class BranchAndMergePlugin(cliapp.Plugin):
cached_repo = lrc.get_updated_repo(chunk_url)
gd = sb.clone_cached_repo(cached_repo, chunk_ref)
- if chunk_ref != sb.system_branch_name:
- gd.branch(sb.system_branch_name, chunk_ref)
- gd.checkout(sb.system_branch_name)
+ system_branch_ref = gd.disambiguate_ref(sb.system_branch_name)
+ sha1 = gd.resolve_ref_to_commit(chunk_ref)
+
+ try:
+ old_sha1 = gd.resolve_ref_to_commit(system_branch_ref)
+ except morphlib.gitdir.InvalidRefError as e:
+ pass
+ else:
+ gd.delete_ref(system_branch_ref, old_sha1)
+ gd.branch(sb.system_branch_name, sha1)
+ gd.checkout(sb.system_branch_name)
gd.update_submodules(self.app)
gd.update_remotes()
if gd.has_fat():