diff options
-rwxr-xr-x | morph | 85 | ||||
-rwxr-xr-x | tests.branching/edit-clones-chunk.script | 36 | ||||
-rw-r--r-- | tests.branching/edit-clones-chunk.stdout | 6 | ||||
-rwxr-xr-x | tests.branching/show-system-branch-shows-name-correctly.script | 31 | ||||
-rw-r--r-- | tests.branching/show-system-branch-shows-name-correctly.stdout | 1 |
5 files changed, 142 insertions, 17 deletions
@@ -377,19 +377,40 @@ class Morph(cliapp.Application): os.mkdir(os.path.join(dirname, '.morph')) os.mkdir(os.path.join(dirname, '.morph', 'cache')) - def cmd_minedir(self, args): - '''Find morph mine directory from current working directory.''' - + def _deduce_mine_directory(self): dirname = os.getcwd() while dirname != '/': dot_morph = os.path.join(dirname, '.morph') if os.path.isdir(dot_morph): - self.output.write('%s\n' % dirname) - return + return dirname dirname = os.path.dirname(dirname) - - raise cliapp.AppException("Can't find the mine directory") + return None + + def cmd_minedir(self, args): + '''Find morph mine directory from current working directory.''' + + dirname = self._deduce_mine_directory() + if dirname is None: + raise cliapp.AppException("Can't find the mine directory") + self.output.write('%s\n' % dirname) + + def _clone_to_directory(self, dirname, repo, ref): + '''Clone a repository below a directory. + + As a side effect, clone it into the morph repository. + + ''' + + # Get the 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(repo, ref) + # Clone it from cache to target directory. + morphlib.git.clone(dirname, treeish.repo, self.msg) + def cmd_branch(self, args): '''Branch the whole system.''' @@ -404,20 +425,50 @@ class Morph(cliapp.Application): # 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. + # Clone into system branch directory. new_repo = os.path.join(new_branch, os.path.basename(repo)) - morphlib.git.clone(new_repo, treeish.repo, self.msg) + self._clone_to_directory(new_repo, repo, commit) # Create a new branch in the local morphs repository. self.runcmd(['git', 'checkout', '-b', new_branch, commit], cwd=new_repo) + + def _deduce_system_branch(self): + out = self.runcmd(['git', 'branch']) + for line in out.splitlines(): + if line.startswith('* '): + return line.strip()[2:] + return None + + def cmd_show_system_branch(self, args): + '''Print name of current system branch. + + This must be run in the system branch's ``morphs`` repository. + + ''' + + system_branch = self._deduce_system_branch() + if system_branch is None: + raise cliapp.AppException("Can't determine system branch") + self.output.write('%s\n' % system_branch) + + def cmd_edit(self, args): + '''Edit a component in a system branch.''' + + if len(args) != 2: + raise cliapp.AppException('morph edit must get a repository name ' + 'and commit ref as argument') + + repo = args[0] + ref = args[1] + + mine_directory = self._deduce_mine_directory() + system_branch = self._deduce_system_branch() + new_repo = os.path.join(mine_directory, system_branch, + os.path.basename(repo)) + self._clone_to_directory(new_repo, repo, ref) + self.runcmd(['git', 'checkout', '-b', system_branch, ref], + cwd=new_repo) def msg(self, msg): '''Show a message to the user about what is going on.''' @@ -445,7 +496,7 @@ class Morph(cliapp.Application): msg('# %s' % ' | '.join(commands)) # run the command line - cliapp.Application.runcmd(self, argv, *args, **kwargs) + return cliapp.Application.runcmd(self, argv, *args, **kwargs) # This is in morph so that policy is easily visible, and not embedded # deep down in the call stack. diff --git a/tests.branching/edit-clones-chunk.script b/tests.branching/edit-clones-chunk.script new file mode 100755 index 00000000..c4d84cda --- /dev/null +++ b/tests.branching/edit-clones-chunk.script @@ -0,0 +1,36 @@ +#!/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. + + +# Verify that "morph edit" clones a chunk repository into a system branch. + + +set -eu + +# Create system branch. +cd "$DATADIR/mine" +"$SRCDIR/scripts/test-morph" init +"$SRCDIR/scripts/test-morph" branch newbranch + +# Edit chunk. +cd newbranch/morphs +"$SRCDIR/scripts/test-morph" edit hello master + +echo "Current branches, morphs:" +"$SRCDIR/scripts/run-git-in" "$DATADIR/mine/newbranch/morphs" branch +echo "Current branches, hello:" +"$SRCDIR/scripts/run-git-in" "$DATADIR/mine/newbranch/hello" branch + diff --git a/tests.branching/edit-clones-chunk.stdout b/tests.branching/edit-clones-chunk.stdout new file mode 100644 index 00000000..b5dd24d6 --- /dev/null +++ b/tests.branching/edit-clones-chunk.stdout @@ -0,0 +1,6 @@ +Current branches, morphs: + master +* newbranch +Current branches, hello: + master +* newbranch diff --git a/tests.branching/show-system-branch-shows-name-correctly.script b/tests.branching/show-system-branch-shows-name-correctly.script new file mode 100755 index 00000000..38b2aa14 --- /dev/null +++ b/tests.branching/show-system-branch-shows-name-correctly.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. + + +# Check that 'morph show-system-branch' shows the name of the current system +# branch correctly. + + +set -eu + +# Create system branch. +cd "$DATADIR/mine" +"$SRCDIR/scripts/test-morph" init +"$SRCDIR/scripts/test-morph" branch newbranch + +cd newbranch/morphs +"$SRCDIR/scripts/test-morph" show-system-branch + diff --git a/tests.branching/show-system-branch-shows-name-correctly.stdout b/tests.branching/show-system-branch-shows-name-correctly.stdout new file mode 100644 index 00000000..467e4889 --- /dev/null +++ b/tests.branching/show-system-branch-shows-name-correctly.stdout @@ -0,0 +1 @@ +newbranch |