summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/gitdir.py13
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py14
-rw-r--r--yarns/branches-workspaces.yarn11
3 files changed, 32 insertions, 6 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():
diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn
index 25ea7365..7c85d6e0 100644
--- a/yarns/branches-workspaces.yarn
+++ b/yarns/branches-workspaces.yarn
@@ -39,7 +39,7 @@ existing workspace, initialising it should fail.
WHEN the user attempts to initialise a workspace
THEN morph failed
-Checking out or branching system branches
+Checking out system branches
-----------------------------------------
Once we have a workspace, we can check out a system branch.
@@ -50,6 +50,12 @@ Once we have a workspace, we can check out a system branch.
WHEN the user checks out the system branch called master
THEN the system branch master is checked out
+Edit is probably not the best name for is, but we can use `morph edit`
+to investigate chunks in existing branches.
+
+ WHEN the user edits the chunk test-chunk in branch master
+ THEN the edited chunk test:test-chunk has git branch master
+
Checking out a system branch should fail, if the branch doesn't exist.
SCENARIO checking out a system branch that doesn't exist
@@ -58,6 +64,9 @@ Checking out a system branch should fail, if the branch doesn't exist.
WHEN the user attempts to check out the system branch called foo
THEN morph failed
+Branching system branches
+-----------------------------------------
+
We can, instead, create a new system branch, off master.
SCENARIO branch off master