summaryrefslogtreecommitdiff
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
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.
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py36
-rwxr-xr-xtests.branching/checkout-existing-branch.script6
-rw-r--r--tests.branching/checkout-existing-branch.stdout8
-rwxr-xr-xtests.branching/checkout-non-aliased-repos.script61
-rw-r--r--tests.branching/checkout-non-aliased-repos.stdout36
-rwxr-xr-xtests.branching/edit-checkouts-existing-chunk.script6
-rwxr-xr-xtests.branching/petrify.script4
-rwxr-xr-xtests.branching/setup3
-rwxr-xr-xtests.branching/workflow.script4
9 files changed, 143 insertions, 21 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.'''
diff --git a/tests.branching/checkout-existing-branch.script b/tests.branching/checkout-existing-branch.script
index 643a3a5e..e7e3a379 100755
--- a/tests.branching/checkout-existing-branch.script
+++ b/tests.branching/checkout-existing-branch.script
@@ -15,7 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-# Verify that "morph checkout master" works.
+# Verify that "morph checkout baserock:morphs master" works.
set -eu
@@ -23,11 +23,11 @@ set -eu
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
-"$SRCDIR/scripts/test-morph" checkout master
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
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" master/morphs branch
+"$SRCDIR/scripts/run-git-in" master/baserock:morphs branch
diff --git a/tests.branching/checkout-existing-branch.stdout b/tests.branching/checkout-existing-branch.stdout
index 47043bbe..7ac4a149 100644
--- a/tests.branching/checkout-existing-branch.stdout
+++ b/tests.branching/checkout-existing-branch.stdout
@@ -7,9 +7,9 @@ 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
-f ./master/morphs/hello-system.morph
+d ./master/baserock:morphs
+d ./master/baserock:morphs/.git
+f ./master/baserock:morphs/hello-stratum.morph
+f ./master/baserock:morphs/hello-system.morph
Current branches:
* master
diff --git a/tests.branching/checkout-non-aliased-repos.script b/tests.branching/checkout-non-aliased-repos.script
new file mode 100755
index 00000000..6c9ac638
--- /dev/null
+++ b/tests.branching/checkout-non-aliased-repos.script
@@ -0,0 +1,61 @@
+#!/bin/bash
+# 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 checkout" works with repos that are not aliased.
+# This test in particular verifies that URI schemes are stripped off
+# and that the .git suffix is only removed at the end if it is actually
+# present.
+
+
+set -eu
+
+
+REPO_WITH_SUFFIX="file://$DATADIR/morphs.git"
+REPO_WITHOUT_SUFFIX="file://$DATADIR/morphs"
+
+TEMP_DIR=$(dirname "$DATADIR")
+
+cd "$DATADIR/workspace"
+
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout "$REPO_WITH_SUFFIX" master
+
+echo "File tree of repo with suffix:"
+"$SRCDIR/scripts/list-tree" . | grep -v '/\.git/' |
+ sed 's,/cache/gits/file_[^/]*_,/cache/gits/file_,' |
+ sed "s,${DATADIR:1},DATADIR,g" |
+ sed "s,${TEMP_DIR:1},TEMP_DIR,g"
+
+echo "Current branches of repo with suffix:"
+"$SRCDIR/scripts/run-git-in" master/"${DATADIR:1}"/morphs branch
+
+cd "$DATADIR"
+rm -rf "$DATADIR/workspace"
+mkdir "$DATADIR/workspace"
+cd "$DATADIR/workspace"
+
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout "$REPO_WITHOUT_SUFFIX" master
+
+echo "File tree of repo without suffix:"
+"$SRCDIR/scripts/list-tree" . | grep -v '/\.git/' |
+ sed 's,/cache/gits/file_[^/]*_,/cache/gits/file_,' |
+ sed "s,${DATADIR:1},DATADIR,g" |
+ sed "s,${TEMP_DIR:1},TEMP_DIR,g"
+
+echo "Current branches of repo without suffix:"
+"$SRCDIR/scripts/run-git-in" master/"${DATADIR:1}"/morphs branch
diff --git a/tests.branching/checkout-non-aliased-repos.stdout b/tests.branching/checkout-non-aliased-repos.stdout
new file mode 100644
index 00000000..75dcd63d
--- /dev/null
+++ b/tests.branching/checkout-non-aliased-repos.stdout
@@ -0,0 +1,36 @@
+File tree of repo with suffix:
+d .
+d ./.morph
+d ./.morph/cache
+d ./.morph/cache/gits
+d ./.morph/cache/gits/file_git
+d ./.morph/cache/gits/file_git/.git
+d ./master
+d ./master/.morph-system-branch
+d ./master/tmp
+d ./master/TEMP_DIR
+d ./master/DATADIR
+d ./master/DATADIR/morphs
+d ./master/DATADIR/morphs/.git
+f ./master/DATADIR/morphs/hello-stratum.morph
+f ./master/DATADIR/morphs/hello-system.morph
+Current branches of repo with suffix:
+* master
+File tree of repo without suffix:
+d .
+d ./.morph
+d ./.morph/cache
+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/tmp
+d ./master/TEMP_DIR
+d ./master/DATADIR
+d ./master/DATADIR/morphs
+d ./master/DATADIR/morphs/.git
+f ./master/DATADIR/morphs/hello-stratum.morph
+f ./master/DATADIR/morphs/hello-system.morph
+Current branches of repo without suffix:
+* master
diff --git a/tests.branching/edit-checkouts-existing-chunk.script b/tests.branching/edit-checkouts-existing-chunk.script
index 99276853..b8480a5b 100755
--- a/tests.branching/edit-checkouts-existing-chunk.script
+++ b/tests.branching/edit-checkouts-existing-chunk.script
@@ -23,14 +23,14 @@ set -eu
# Checkout the master system branch.
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
-"$SRCDIR/scripts/test-morph" checkout alfred
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs alfred
# Edit the hello chunk in alfred.
-cd alfred/morphs
+cd alfred/baserock:morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello alfred
echo "Current branches, morphs:"
-"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/morphs" branch
+"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/baserock:morphs" branch
echo "Current branches, hello:"
"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/hello" branch
diff --git a/tests.branching/petrify.script b/tests.branching/petrify.script
index 921eb048..502c8220 100755
--- a/tests.branching/petrify.script
+++ b/tests.branching/petrify.script
@@ -25,8 +25,8 @@ cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
"$SRCDIR/scripts/test-morph" update-gits baserock:morphs master \
hello-stratum.morph
-"$SRCDIR/scripts/test-morph" checkout master
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
-cd master/morphs
+cd master/baserock:morphs
"$SRCDIR/scripts/test-morph" petrify hello-stratum.morph
cat hello-stratum.morph
diff --git a/tests.branching/setup b/tests.branching/setup
index 1705c9b4..51092cea 100755
--- a/tests.branching/setup
+++ b/tests.branching/setup
@@ -56,6 +56,9 @@ mkdir "$DATADIR/workspace"
# Create a fake morphs repository
mkdir "$DATADIR/morphs"
+## Create a link to this repo that has a .git suffix
+ln -s "$DATADIR/morphs" "$DATADIR/morphs.git"
+
cat <<EOF > "$DATADIR/morphs/hello-system.morph"
{
"name": "hello-system",
diff --git a/tests.branching/workflow.script b/tests.branching/workflow.script
index ca626cd8..64326e4a 100755
--- a/tests.branching/workflow.script
+++ b/tests.branching/workflow.script
@@ -32,8 +32,8 @@ git add README
git commit -m "Fix README, yo!" --quiet
cd "$DATADIR/workspace"
-"$SRCDIR/scripts/test-morph" checkout master
-cd master/morphs
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+cd master/baserock:morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello master
"$SRCDIR/scripts/test-morph" merge me/readme-fix hello