summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmorph23
-rwxr-xr-xtests.branching/branch-creates-new-system-branch.script31
-rw-r--r--tests.branching/branch-creates-new-system-branch.stdout15
3 files changed, 67 insertions, 2 deletions
diff --git a/morph b/morph
index d3d09311..1013f065 100755
--- a/morph
+++ b/morph
@@ -397,8 +397,27 @@ class Morph(cliapp.Application):
raise cliapp.AppException('morph branch needs name of branch '
'as parameter')
- branch = args[0]
- os.makedirs(branch)
+ new_branch = args[0]
+ repo = 'morphs'
+ commit = 'master'
+
+ # Create the system branch directory.
+ os.makedirs(new_branch)
+
+ # Get the 'morphs' repository into the cache.
+ tempdir = morphlib.tempdir.Tempdir(self.settings['tempdir'])
+ morph_loader = MorphologyLoader(self.settings)
+ source_manager = morphlib.sourcemanager.SourceManager(self,
+ update=not self.settings['no-git-update'])
+ treeish = source_manager.get_treeish('morphs', commit)
+
+ # Clone it from cache to system branch directory.
+ new_repo = os.path.join(new_branch, os.path.basename(repo))
+ morphlib.git.clone(new_repo, treeish.repo, self.msg)
+
+ # Create a new branch in the local morphs repository.
+ self.runcmd(['git', 'checkout', '-b', new_branch, commit],
+ cwd=new_repo)
def msg(self, msg):
'''Show a message to the user about what is going on.'''
diff --git a/tests.branching/branch-creates-new-system-branch.script b/tests.branching/branch-creates-new-system-branch.script
new file mode 100755
index 00000000..07e12f5f
--- /dev/null
+++ b/tests.branching/branch-creates-new-system-branch.script
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Copyright (C) 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Make sure "morph branch" creates a new system branch.
+
+set -eu
+
+cd "$DATADIR/mine"
+"$SRCDIR/scripts/test-morph" init
+
+"$SRCDIR/scripts/test-morph" branch newbranch
+
+echo "File tree:"
+"$SRCDIR/scripts/list-tree" . | grep -v '/\.git/' |
+ sed 's,/cache/gits/file_[^/]*_,/cache/gits/file_,'
+
+echo "Current branches:"
+"$SRCDIR/scripts/run-git-in" newbranch/morphs branch
diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout
new file mode 100644
index 00000000..1381fcfe
--- /dev/null
+++ b/tests.branching/branch-creates-new-system-branch.stdout
@@ -0,0 +1,15 @@
+File tree:
+d .
+d ./.morph
+d ./.morph/cache
+d ./.morph/cache/gits
+d ./.morph/cache/gits/file_morphs
+d ./.morph/cache/gits/file_morphs/.git
+d ./newbranch
+d ./newbranch/morphs
+d ./newbranch/morphs/.git
+f ./newbranch/morphs/hello-stratum.chunk
+f ./newbranch/morphs/hello-system.chunk
+Current branches:
+ master
+* newbranch