diff options
-rwxr-xr-x | morph | 53 | ||||
-rwxr-xr-x | tests.branching/edit-uses-ref-from-stratum.script | 33 | ||||
-rw-r--r-- | tests.branching/edit-uses-ref-from-stratum.stdout | 2 |
3 files changed, 72 insertions, 16 deletions
@@ -712,22 +712,32 @@ class Morph(cliapp.Application): def cmd_edit(self, args): '''Edit a component in a system branch.''' - if len(args) != 2: + if len(args) not in (1,2): raise cliapp.AppException('morph edit must get a repository name ' 'and commit ref as argument') - repo = self._resolve_reponame(args[0]) - ref = args[1] - mine_directory = self._deduce_mine_directory() system_branch = self._deduce_system_branch() + if system_branch is None: + raise morphlib.Error('Cannot deduce system branch') + + morphs_dirname = os.path.join(mine_directory, system_branch, 'morphs') + if morphs_dirname is None: + raise morphlib.Error('Can not find morphs directory') + + repo = self._resolve_reponame(args[0]) + + if len(args) == 2: + ref = args[1] + else: + ref = self._find_edit_ref(morphs_dirname, repo) + if ref is None: + raise morphlib.Error('Cannot deduce commit to start edit from') + new_repo = os.path.join(mine_directory, system_branch, os.path.basename(repo)) self._clone_to_directory(new_repo, repo, ref) - system_branch = self._deduce_system_branch() - if system_branch is None: - raise morphlib.Error('Cannot deduce system branch') if system_branch == ref: self.runcmd(['git', 'checkout', system_branch], cwd=new_repo) @@ -735,15 +745,9 @@ class Morph(cliapp.Application): self.runcmd(['git', 'checkout', '-b', system_branch, ref], cwd=new_repo) - morphs_dirname = os.path.join(mine_directory, system_branch, 'morphs') - if morphs_dirname is None: - logging.warning('Can not find morphs directory, not updating') - return - for filename, morphology in self._load_morphologies(morphs_dirname): - if morphology['kind'] != 'stratum': - continue + for filename, morph in self._morphs_for_repo(morphs_dirname, repo): changed = False - for spec in morphology['sources']: + for spec in morph['sources']: spec_repo = self._resolve_reponame(spec['repo']) if spec_repo == repo and spec['ref'] != system_branch: if self.settings['verbose']: @@ -752,7 +756,15 @@ class Morph(cliapp.Application): spec['ref'] = system_branch changed = True if changed: - self._write_morphology(filename, morphology) + self._write_morphology(filename, morph) + + def _find_edit_ref(self, morphs_dirname, repo): + for filename, morph in self._morphs_for_repo(morphs_dirname, repo): + for spec in morph['sources']: + spec_repo = self._resolve_reponame(spec['repo']) + if spec_repo == repo: + return spec['ref'] + return None def _load_morphologies(self, dirname): pattern = os.path.join(dirname, '*.morph') @@ -762,6 +774,15 @@ class Morph(cliapp.Application): morphology = morphlib.morph2.Morphology(text) yield filename, morphology + def _morphs_for_repo(self, morphs_dirname, repo): + for filename, morph in self._load_morphologies(morphs_dirname): + if morph['kind'] == 'stratum': + for spec in morph['sources']: + spec_repo = self._resolve_reponame(spec['repo']) + if spec_repo == repo: + yield filename, morph + break + def _write_morphology(self, filename, morphology): as_dict = {} for key in morphology.keys(): diff --git a/tests.branching/edit-uses-ref-from-stratum.script b/tests.branching/edit-uses-ref-from-stratum.script new file mode 100755 index 00000000..74c26d5a --- /dev/null +++ b/tests.branching/edit-uses-ref-from-stratum.script @@ -0,0 +1,33 @@ +#!/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 baserock:hello + +cd ../hello +git branch diff --git a/tests.branching/edit-uses-ref-from-stratum.stdout b/tests.branching/edit-uses-ref-from-stratum.stdout new file mode 100644 index 00000000..d14c4c96 --- /dev/null +++ b/tests.branching/edit-uses-ref-from-stratum.stdout @@ -0,0 +1,2 @@ + master +* newbranch |