summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py44
-rw-r--r--tests.branching/branch-creates-new-system-branch-not-from-master.stdout1
-rw-r--r--tests.branching/branch-creates-new-system-branch.stdout1
-rw-r--r--tests.branching/checkout-existing-branch.stdout1
4 files changed, 22 insertions, 25 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 2304fc0f..3145b774 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -56,22 +56,20 @@ class BranchAndMergePlugin(cliapp.Plugin):
if os.path.isdir(dot_morph):
return dirname
dirname = os.path.dirname(dirname)
- return None
+ raise cliapp.AppException("Can't find the workspace directory")
@classmethod
def deduce_system_branch(cls):
workspace = cls.deduce_workspace()
- if workspace is None:
- return None
-
- if not workspace.endswith('/'):
- workspace += '/'
- cwd = os.getcwd()
- if not cwd.startswith(workspace):
- return None
+ dirname = os.getcwd()
+ while dirname != workspace and dirname != '/':
+ system_branch_dir = os.path.join(dirname, '.morph-system-branch')
+ if os.path.isdir(system_branch_dir):
+ return os.path.dirname(system_branch_dir[len(workspace)+1:])
+ dirname = os.path.dirname(dirname)
- return os.path.dirname(cwd[len(workspace):])
+ raise cliapp.AppException("Can't find the system branch directory")
@staticmethod
def clone_to_directory(app, dirname, reponame, ref):
@@ -211,10 +209,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
def workspace(self, args):
'''Find morph workspace directory from current working directory.'''
- dirname = self.deduce_workspace()
- if dirname is None:
- raise cliapp.AppException("Can't find the workspace directory")
- self.app.output.write('%s\n' % dirname)
+ self.app.output.write('%s\n' % self.deduce_workspace())
def branch(self, args):
'''Branch the whole system.'''
@@ -229,6 +224,10 @@ class BranchAndMergePlugin(cliapp.Plugin):
# Create the system branch directory.
os.makedirs(new_branch)
+ # Create a .morph-system-branch directory to clearly identify
+ # this directory as a morph system branch.
+ os.mkdir(os.path.join(new_branch, '.morph-system-branch'))
+
# Clone into system branch directory.
new_repo = os.path.join(new_branch, self.system_repo_base)
self.clone_to_directory(self.app, new_repo, self.system_repo_name,
@@ -250,22 +249,19 @@ class BranchAndMergePlugin(cliapp.Plugin):
# Create the system branch directory.
os.makedirs(system_branch)
+ # Create a .morph-system-branch directory to clearly identify
+ # this directory as a morph system branch.
+ os.mkdir(os.path.join(system_branch, '.morph-system-branch'))
+
# Clone into system branch directory.
new_repo = os.path.join(system_branch, self.system_repo_base)
self.clone_to_directory(self.app, new_repo, self.system_repo_name,
system_branch)
def show_system_branch(self, args):
- '''Print name of current system branch.
-
- This must be run in the system branch's ``morphs`` repository.
+ '''Print name of current system branch.'''
- '''
-
- system_branch = self.deduce_system_branch()
- if system_branch is None:
- raise cliapp.AppException("Can't determine system branch")
- self.app.output.write('%s\n' % system_branch)
+ self.app.output.write('%s\n' % self.deduce_system_branch())
def merge(self, args):
'''Merge specified repositories from another system branch.'''
@@ -296,8 +292,6 @@ class BranchAndMergePlugin(cliapp.Plugin):
app = self.app
workspace = self.deduce_workspace()
system_branch = self.deduce_system_branch()
- if system_branch is None:
- raise morphlib.Error('Cannot deduce system branch')
morphs_dirname = os.path.join(workspace, system_branch, 'morphs')
if morphs_dirname is None:
diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
index 7dfffab1..af1ad6cd 100644
--- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
+++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
@@ -6,6 +6,7 @@ d ./.morph/cache/gits
d ./.morph/cache/gits/file_morphs
d ./.morph/cache/gits/file_morphs/.git
d ./newbranch
+d ./newbranch/.morph-system-branch
d ./newbranch/morphs
d ./newbranch/morphs/.git
f ./newbranch/morphs/hello-stratum.morph
diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout
index d2884b8c..e22ef30b 100644
--- a/tests.branching/branch-creates-new-system-branch.stdout
+++ b/tests.branching/branch-creates-new-system-branch.stdout
@@ -6,6 +6,7 @@ d ./.morph/cache/gits
d ./.morph/cache/gits/file_morphs
d ./.morph/cache/gits/file_morphs/.git
d ./newbranch
+d ./newbranch/.morph-system-branch
d ./newbranch/morphs
d ./newbranch/morphs/.git
f ./newbranch/morphs/hello-stratum.morph
diff --git a/tests.branching/checkout-existing-branch.stdout b/tests.branching/checkout-existing-branch.stdout
index 7f405fdb..47043bbe 100644
--- a/tests.branching/checkout-existing-branch.stdout
+++ b/tests.branching/checkout-existing-branch.stdout
@@ -6,6 +6,7 @@ d ./.morph/cache/gits
d ./.morph/cache/gits/file_morphs
d ./.morph/cache/gits/file_morphs/.git
d ./master
+d ./master/.morph-system-branch
d ./master/morphs
d ./master/morphs/.git
f ./master/morphs/hello-stratum.morph