summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-29 13:06:27 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-29 18:49:26 +0100
commit34c03048cc99e8a8abeb3e3c99574a92a2acb00a (patch)
treeaa6068e4d03fbca208f81d2f73056b3608fab401 /morphlib
parent4018afbdb583517277a0f1f7d990fa4c2a04923a (diff)
downloadmorph-34c03048cc99e8a8abeb3e3c99574a92a2acb00a.tar.gz
Make "morph checkout" require a repository parameter
Instead of hard-coding "baserock:morphs" as the repository we check out from, we want to allow people to check out from arbitrary repositories with system and stratum morphologies. This commit adds a mandatory repository parameter to "morph checkout". This parameter can either be an aliased repo, e.g. baserock:morphs, or a full repo URL such as ssh://gitano@git.baserock.org/baserock/morphs. When cloning the actual repository into a local directory, the following happens: For alias repos baserock:morphs and baserock:foo/bar, the repositories would be cloned into the directories $workspace/$branch/baserock:morphs and $workspace/$branch/baserock:foo/bar. For repos specified using full URLs, the scheme and .git suffix (if present) are stripped off. The above ssh example would be cloned into the following directory: $workspace/$branch/gitano@git.baserock.org/baserock/morphs This commit also adjusts all affected tests and adds a new test to verify that checking out from full repo URLs works as expected.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index cb975482..098546cf 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -19,6 +19,7 @@ import os
import json
import glob
import tempfile
+import urlparse
import morphlib
@@ -114,6 +115,11 @@ class BranchAndMergePlugin(cliapp.Plugin):
if not app.settings['no-git-update']:
repo.update()
+ # Make sure the parent directories needed for the repo dir exist.
+ parent_dir = os.path.dirname(dirname)
+ if not os.path.exists(parent_dir):
+ os.makedirs(parent_dir)
+
# Clone it from cache to target directory.
repo.checkout(ref, os.path.abspath(dirname))
@@ -262,14 +268,31 @@ class BranchAndMergePlugin(cliapp.Plugin):
self.app.runcmd(['git', 'checkout', '-b', new_branch, commit],
cwd=new_repo)
+ def _convert_uri_to_path(self, uri):
+ parts = urlparse.urlparse(uri)
+
+ # If the URI path is relative, assume it is an aliased repo (e.g.
+ # baserock:morphs). Otherwise assume it is a full URI where we need
+ # to strip off the scheme and .git suffix.
+ if not os.path.isabs(parts.path):
+ return uri
+ else:
+ path = parts.netloc
+ if parts.path.endswith('.git'):
+ path = os.path.join(path, parts.path[1:-len('.git')])
+ else:
+ path = os.path.join(path, parts.path[1:])
+ return path
+
def checkout(self, args):
'''Check out an existing system branch.'''
- if len(args) != 1:
- raise cliapp.AppException('morph checkout needs name of '
- 'branch as parameter')
+ if len(args) != 2:
+ raise cliapp.AppException('morph checkout needs a repo and the '
+ 'name of a branch as parameters')
- system_branch = args[0]
+ repo = args[0]
+ system_branch = args[1]
# Create the system branch directory.
os.makedirs(system_branch)
@@ -279,9 +302,8 @@ class BranchAndMergePlugin(cliapp.Plugin):
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)
+ repo_dir = os.path.join(system_branch, self._convert_uri_to_path(repo))
+ self.clone_to_directory(self.app, repo_dir, repo, system_branch)
def show_system_branch(self, args):
'''Print name of current system branch.'''