diff options
author | Richard Maw <richard.maw@gmail.com> | 2014-08-10 20:29:42 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-08-12 18:07:41 +0100 |
commit | 2e5d8664920453ede30b450c7b39ac3a0bc141bb (patch) | |
tree | e0954f648bba232b654d86bfc96e8d644c88c237 | |
parent | 4d794d475e01363928916f7667a63eed6071f5e2 (diff) | |
download | morph-2e5d8664920453ede30b450c7b39ac3a0bc141bb.tar.gz |
Make morph show-branch-root print the path
The help for the show-branch-root command said it returns a path, but
the command and the yarns just showed the aliased url it was cloned
from.
Given I found myself needing the path in some scripts, not the repo url,
I think it's more useful to reconcile the difference this way.
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 7 | ||||
-rw-r--r-- | morphlib/sysbranchdir.py | 38 | ||||
-rwxr-xr-x | tests.branching/show-branch-root-in-branched-branch.script | 30 | ||||
-rw-r--r-- | tests.branching/show-branch-root-in-branched-branch.stdout | 1 | ||||
-rwxr-xr-x | tests.branching/show-branch-root-in-checked-out-branch.script | 30 | ||||
-rw-r--r-- | tests.branching/show-branch-root-in-checked-out-branch.stdout | 1 | ||||
-rwxr-xr-x | tests.branching/show-branch-root-with-repo-url.script | 30 | ||||
-rw-r--r-- | tests.branching/show-branch-root-with-repo-url.stdout | 1 | ||||
-rw-r--r-- | yarns/branches-workspaces.yarn | 10 | ||||
-rw-r--r-- | yarns/implementations.yarn | 2 |
10 files changed, 36 insertions, 114 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 9450c67b..434ff6af 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -373,16 +373,17 @@ class BranchAndMergePlugin(cliapp.Plugin): This would, for example, write out something like: - /src/ws/master/baserock:baserock/morphs + /src/ws/master/baserock/baserock/morphs - when the master branch of the `baserock:baserock/morphs` + when the master branch of the `baserock/baserock/morphs` repository is checked out. ''' ws = morphlib.workspace.open('.') sb = morphlib.sysbranchdir.open_from_within('.') - self.app.output.write('%s\n' % sb.get_config('branch.root')) + repo_url = sb.get_config('branch.root') + self.app.output.write('%s\n' % sb.get_git_directory_name(repo_url)) def _remove_branch_dir_safe(self, workspace_root, system_branch_root): # This function avoids throwing any exceptions, so it is safe to call diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index b8953c2f..19fba695 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -68,19 +68,13 @@ class SystemBranchDirectory(object): value = cliapp.runcmd(['git', 'config', '-f', self._config_path, key]) return value.strip() - def get_git_directory_name(self, repo_url): - '''Return directory pathname for a given git repository. - - If the URL is a real one (not aliased), the schema and leading // - are removed from it, as is a .git suffix. - - Any colons in the URL path or network location are replaced - with slashes, so that directory paths do not contain colons. - This avoids problems with PYTHONPATH, PATH, and other things - that use colon as a separator. - - ''' + def _find_git_directory(self, repo_url): + for gd in self.list_git_directories(): + if gd.get_config('morph.repository') == repo_url: + return gd.dirname + return None + def _fabricate_git_directory_name(self, repo_url): # Parse the URL. If the path component is absolute, we assume # it's a real URL; otherwise, an aliased URL. parts = urlparse.urlparse(repo_url) @@ -107,6 +101,26 @@ class SystemBranchDirectory(object): return os.path.join(self.root_directory, relative) + def get_git_directory_name(self, repo_url): + '''Return directory pathname for a given git repository. + + If the repository has already been cloned, then it returns the + path to that, if not it will fabricate a path based on the url. + + If the URL is a real one (not aliased), the schema and leading // + are removed from it, as is a .git suffix. + + Any colons in the URL path or network location are replaced + with slashes, so that directory paths do not contain colons. + This avoids problems with PYTHONPATH, PATH, and other things + that use colon as a separator. + + ''' + found_repo = self._find_git_directory(repo_url) + if not found_repo: + return self._fabricate_git_directory_name(repo_url) + return found_repo + def get_filename(self, repo_url, relative): '''Return full pathname to a file in a checked out repository. diff --git a/tests.branching/show-branch-root-in-branched-branch.script b/tests.branching/show-branch-root-in-branched-branch.script deleted file mode 100755 index 4598d6a9..00000000 --- a/tests.branching/show-branch-root-in-branched-branch.script +++ /dev/null @@ -1,30 +0,0 @@ -#!/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-branch-root' works when being run in a -## local system branch created using 'morph branch ...'. - -set -eu - -# Create a workspace and branch. -cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch test:morphs testbranch - -# Try to print the branch root repository. -"$SRCDIR/scripts/test-morph" show-branch-root diff --git a/tests.branching/show-branch-root-in-branched-branch.stdout b/tests.branching/show-branch-root-in-branched-branch.stdout deleted file mode 100644 index b2804d56..00000000 --- a/tests.branching/show-branch-root-in-branched-branch.stdout +++ /dev/null @@ -1 +0,0 @@ -test:morphs diff --git a/tests.branching/show-branch-root-in-checked-out-branch.script b/tests.branching/show-branch-root-in-checked-out-branch.script deleted file mode 100755 index 97f892b9..00000000 --- a/tests.branching/show-branch-root-in-checked-out-branch.script +++ /dev/null @@ -1,30 +0,0 @@ -#!/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-branch-root' works when being run in a -## local system branch created using 'morph checkout ...'. - -set -eu - -# Create a workspace and branch. -cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" checkout test:morphs master - -# Try to print the branch root repository. -"$SRCDIR/scripts/test-morph" show-branch-root diff --git a/tests.branching/show-branch-root-in-checked-out-branch.stdout b/tests.branching/show-branch-root-in-checked-out-branch.stdout deleted file mode 100644 index b2804d56..00000000 --- a/tests.branching/show-branch-root-in-checked-out-branch.stdout +++ /dev/null @@ -1 +0,0 @@ -test:morphs diff --git a/tests.branching/show-branch-root-with-repo-url.script b/tests.branching/show-branch-root-with-repo-url.script deleted file mode 100755 index 5480c3ef..00000000 --- a/tests.branching/show-branch-root-with-repo-url.script +++ /dev/null @@ -1,30 +0,0 @@ -#!/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-branch-root' works when being run in a -## local system branch created from a full repository URL. - -set -eu - -# Create a workspace and branch. -cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch "file://${DATADIR}/morphs.git" testbranch - -# Try to print the branch root repository. -"$SRCDIR/scripts/test-morph" show-branch-root diff --git a/tests.branching/show-branch-root-with-repo-url.stdout b/tests.branching/show-branch-root-with-repo-url.stdout deleted file mode 100644 index 2d47eb40..00000000 --- a/tests.branching/show-branch-root-with-repo-url.stdout +++ /dev/null @@ -1 +0,0 @@ -file://TMP/morphs.git diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn index 2f617ce4..25ea7365 100644 --- a/yarns/branches-workspaces.yarn +++ b/yarns/branches-workspaces.yarn @@ -142,19 +142,19 @@ current directory, things should fail. AND the user attempts to report the system branch from the directory . THEN morph failed -`morph show-branch-root` reports the URL (possibly aliases) of the -system branch root repository. It can be run inside a checkout, or -somewhere outside a checkout, where exactly one checkout exists below. +`morph show-branch-root` reports the path of the system branch root +repository. It can be run inside a checkout, or somewhere outside a +checkout, where exactly one checkout exists below. SCENARIO morph reports system branch root repository GIVEN a workspace AND a git server WHEN the user checks out the system branch called master AND the user reports the system branch root repository from the directory master - THEN the system branch root repository is reported as test:morphs + THEN the system branch root repository is reported as workspace/master/test/morphs WHEN the user reports the system branch root repository from the directory . - THEN the system branch root repository is reported as test:morphs + THEN the system branch root repository is reported as workspace/master/test/morphs However, it fails if run outside a checkout and there's no system branches checked out. diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index 66dd9d57..d2e72ccf 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -419,7 +419,7 @@ Report system branch root repository. else attempt_morph show-branch-root > "$@"; fi IMPLEMENTS THEN the system branch root repository is reported as (.*) - echo "$MATCH_1" > "$DATADIR/branch-root.actual" + echo "$DATADIR/$MATCH_1" > "$DATADIR/branch-root.actual" diff -u "$DATADIR/branch-root.actual" "$DATADIR/branch-root.reported" Editing morphologies with `morph edit`. |