diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-08-29 14:46:35 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-08-29 18:49:31 +0100 |
commit | b657fbcab062073ff4dd1c69a72b252e4992e152 (patch) | |
tree | 6739bceee440567f10aaead17974b5eeaa7e8fb6 | |
parent | ce83a0afe0a51c9b8ab75e89d23f45c3ebf2be93 (diff) | |
download | morph-b657fbcab062073ff4dd1c69a72b252e4992e152.tar.gz |
Add mandatory repository parameter to "morph branch"
This is complementary to adding a repository parameter to the "morph
checkout" command. It allows to branch off arbitrary repositories
rather than always branching off baserock:morphs.
All affected tests are updated to provide and work with this new
parameter.
15 files changed, 51 insertions, 54 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 74069200..78005668 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -26,9 +26,6 @@ import morphlib class BranchAndMergePlugin(cliapp.Plugin): - system_repo_base = 'morphs' - system_repo_name = 'baserock:%s' % system_repo_base - def enable(self): self.app.add_subcommand('petrify', self.petrify, arg_synopsis='STRATUM...') @@ -259,12 +256,13 @@ class BranchAndMergePlugin(cliapp.Plugin): def branch(self, args): '''Branch the whole system.''' - if len(args) not in [1, 2]: + if len(args) not in [2, 3]: raise cliapp.AppException('morph branch needs name of branch ' 'as parameter') - new_branch = args[0] - commit = 'master' if len(args) == 1 else args[1] + repo = args[0] + new_branch = args[1] + commit = 'master' if len(args) == 2 else args[2] # Create the system branch directory. os.makedirs(new_branch) @@ -274,16 +272,15 @@ class BranchAndMergePlugin(cliapp.Plugin): os.mkdir(os.path.join(new_branch, '.morph-system-branch')) # Remember the repository we branched off from. - self.write_branch_root(new_branch, self.system_repo_base) + self.write_branch_root(new_branch, repo) # Clone into system branch directory. - new_repo = os.path.join(new_branch, self.system_repo_base) - self.clone_to_directory(self.app, new_repo, self.system_repo_name, - commit) + repo_dir = os.path.join(new_branch, self._convert_uri_to_path(repo)) + self.clone_to_directory(self.app, repo_dir, repo, commit) # Create a new branch in the local morphs repository. self.app.runcmd(['git', 'checkout', '-b', new_branch, commit], - cwd=new_repo) + cwd=repo_dir) def _convert_uri_to_path(self, uri): parts = urlparse.urlparse(uri) diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.script b/tests.branching/branch-creates-new-system-branch-not-from-master.script index 9356a70f..e2883c83 100755 --- a/tests.branching/branch-creates-new-system-branch-not-from-master.script +++ b/tests.branching/branch-creates-new-system-branch-not-from-master.script @@ -21,15 +21,15 @@ set -eu cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch origin/alfred +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch origin/alfred 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" newbranch/morphs branch +"$SRCDIR/scripts/run-git-in" newbranch/baserock:morphs branch echo "Current origin:" -"$SRCDIR/scripts/run-git-in" newbranch/morphs remote show origin | +"$SRCDIR/scripts/run-git-in" newbranch/baserock:morphs remote show origin | sed 's,\(TMP/workspace/\.morph/cache/gits/file_\).*_,\1,g' diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout index 7dc55cc0..d68a6342 100644 --- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout +++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout @@ -7,12 +7,12 @@ d ./.morph/cache/gits/file_morphs d ./.morph/cache/gits/file_morphs/.git d ./newbranch d ./newbranch/.morph-system-branch -d ./newbranch/morphs -d ./newbranch/morphs/.git +d ./newbranch/baserock:morphs +d ./newbranch/baserock:morphs/.git f ./newbranch/.morph-system-branch/branch-root -f ./newbranch/morphs/hello-stratum.morph -f ./newbranch/morphs/hello-system.morph -f ./newbranch/morphs/this.is.alfred +f ./newbranch/baserock:morphs/hello-stratum.morph +f ./newbranch/baserock:morphs/hello-system.morph +f ./newbranch/baserock:morphs/this.is.alfred Current branches: master * newbranch diff --git a/tests.branching/branch-creates-new-system-branch.script b/tests.branching/branch-creates-new-system-branch.script index fa58796e..de1a81ee 100755 --- a/tests.branching/branch-creates-new-system-branch.script +++ b/tests.branching/branch-creates-new-system-branch.script @@ -21,15 +21,15 @@ set -eu cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch 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" newbranch/morphs branch +"$SRCDIR/scripts/run-git-in" newbranch/baserock:morphs branch echo "Current origin:" -"$SRCDIR/scripts/run-git-in" newbranch/morphs remote show origin | +"$SRCDIR/scripts/run-git-in" newbranch/baserock:morphs remote show origin | sed 's,\(TMP/workspace/\.morph/cache/gits/file_\).*_,\1,g' diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout index c37fb0e4..3f2dba1d 100644 --- a/tests.branching/branch-creates-new-system-branch.stdout +++ b/tests.branching/branch-creates-new-system-branch.stdout @@ -7,11 +7,11 @@ d ./.morph/cache/gits/file_morphs d ./.morph/cache/gits/file_morphs/.git d ./newbranch d ./newbranch/.morph-system-branch -d ./newbranch/morphs -d ./newbranch/morphs/.git +d ./newbranch/baserock:morphs +d ./newbranch/baserock:morphs/.git f ./newbranch/.morph-system-branch/branch-root -f ./newbranch/morphs/hello-stratum.morph -f ./newbranch/morphs/hello-system.morph +f ./newbranch/baserock:morphs/hello-stratum.morph +f ./newbranch/baserock:morphs/hello-system.morph Current branches: master * newbranch diff --git a/tests.branching/branch-when-branchdir-exists-locally.script b/tests.branching/branch-when-branchdir-exists-locally.script index 7278e7e9..a98f6401 100755 --- a/tests.branching/branch-when-branchdir-exists-locally.script +++ b/tests.branching/branch-when-branchdir-exists-locally.script @@ -23,5 +23,5 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init mkdir newbranch -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch diff --git a/tests.branching/edit-clones-chunk.script b/tests.branching/edit-clones-chunk.script index d5e117cb..7a3038a3 100755 --- a/tests.branching/edit-clones-chunk.script +++ b/tests.branching/edit-clones-chunk.script @@ -23,17 +23,19 @@ set -eu # Create system branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch # Edit chunk. -cd newbranch/morphs +cd newbranch/baserock:morphs "$SRCDIR/scripts/test-morph" edit baserock:hello master echo "Current branches, morphs:" -"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/newbranch/morphs" branch +"$SRCDIR/scripts/run-git-in" \ + "$DATADIR/workspace/newbranch/baserock:morphs" branch echo "Current origin, morphs:" -"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/newbranch/morphs" \ +"$SRCDIR/scripts/run-git-in" \ + "$DATADIR/workspace/newbranch/baserock:morphs" \ remote show origin | \ sed 's,\(TMP/workspace/\.morph/cache/gits/file_\).*_,\1,g' diff --git a/tests.branching/edit-updates-stratum.script b/tests.branching/edit-updates-stratum.script index 7b81f59a..db819088 100755 --- a/tests.branching/edit-updates-stratum.script +++ b/tests.branching/edit-updates-stratum.script @@ -23,10 +23,11 @@ set -eu # Create system branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch # Edit chunk. -cd newbranch/morphs "$SRCDIR/scripts/test-morph" edit baserock:hello master +# See what effect the editing had. +cd newbranch/baserock:morphs git diff diff --git a/tests.branching/edit-uses-ref-from-stratum.script b/tests.branching/edit-uses-ref-from-stratum.script index f2276f3b..0e4eb915 100755 --- a/tests.branching/edit-uses-ref-from-stratum.script +++ b/tests.branching/edit-uses-ref-from-stratum.script @@ -23,11 +23,10 @@ set -eu # Create system branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch # Edit chunk. -cd newbranch/morphs "$SRCDIR/scripts/test-morph" edit baserock:hello -cd ../baserock:hello +cd newbranch/baserock:hello git branch diff --git a/tests.branching/merge-explicitly-named-repos.script b/tests.branching/merge-explicitly-named-repos.script index 5a0953a7..ad3ef0e6 100755 --- a/tests.branching/merge-explicitly-named-repos.script +++ b/tests.branching/merge-explicitly-named-repos.script @@ -24,25 +24,24 @@ set -eu # Create system branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch newbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs newbranch # Make a change to a chunk. -cd newbranch/morphs "$SRCDIR/scripts/test-morph" edit baserock:hello master -cd ../baserock:hello +cd newbranch/baserock:hello touch newfile.txt git add newfile.txt git commit -m foo --quiet # Merge changes to a new system branch. cd "$DATADIR/workspace" -"$SRCDIR/scripts/test-morph" branch otherbranch -cd otherbranch/morphs +"$SRCDIR/scripts/test-morph" branch baserock:morphs otherbranch +cd otherbranch "$SRCDIR/scripts/test-morph" edit baserock:hello master "$SRCDIR/scripts/test-morph" merge newbranch baserock:hello # Check results. -cd ../baserock:hello +cd baserock:hello git status --short # make sure all changes are committed ls newfile.txt # make sure the new file is there diff --git a/tests.branching/show-system-branch-fails-outside-workspace.script b/tests.branching/show-system-branch-fails-outside-workspace.script index fc3f3db3..5cd3bb98 100755 --- a/tests.branching/show-system-branch-fails-outside-workspace.script +++ b/tests.branching/show-system-branch-fails-outside-workspace.script @@ -15,8 +15,8 @@ # 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. +# Check that 'morph show-system-branch' fails when being run +# outside a workspace. set -eu @@ -24,7 +24,7 @@ set -eu # Create a workspace and branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch testbranch +"$SRCDIR/scripts/test-morph" branch baserock:morphs testbranch # Leave the workspace. cd .. diff --git a/tests.branching/show-system-branch-fails-when-branch-is-ambiguous.script b/tests.branching/show-system-branch-fails-when-branch-is-ambiguous.script index f6fc4646..2383deb9 100755 --- a/tests.branching/show-system-branch-fails-when-branch-is-ambiguous.script +++ b/tests.branching/show-system-branch-fails-when-branch-is-ambiguous.script @@ -24,8 +24,8 @@ set -eu # Create a workspace and two system branches cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch first/branch -"$SRCDIR/scripts/test-morph" branch second/branch +"$SRCDIR/scripts/test-morph" branch baserock:morphs first/branch +"$SRCDIR/scripts/test-morph" branch baserock:morphs second/branch # Try to find out the branch from the workspace directory. cd "$DATADIR/workspace" diff --git a/tests.branching/show-system-branch-works-anywhere-with-a-single-branch.script b/tests.branching/show-system-branch-works-anywhere-with-a-single-branch.script index 66b2a01f..eb565b91 100755 --- a/tests.branching/show-system-branch-works-anywhere-with-a-single-branch.script +++ b/tests.branching/show-system-branch-works-anywhere-with-a-single-branch.script @@ -24,7 +24,7 @@ set -eu # Create a workspace and a system branch. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch first/branch +"$SRCDIR/scripts/test-morph" branch baserock:morphs first/branch # Show the branch even when outside the branch. cd "$DATADIR/workspace" diff --git a/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script b/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script index 1391f0ec..f4abc8ea 100755 --- a/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script +++ b/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script @@ -24,8 +24,8 @@ set -eu # Create a workspace and two system branches. cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch first/branch -"$SRCDIR/scripts/test-morph" branch second/branch +"$SRCDIR/scripts/test-morph" branch baserock:morphs first/branch +"$SRCDIR/scripts/test-morph" branch baserock:morphs second/branch # Create a few subdirectories in the first branch. mkdir -p "$DATADIR/workspace/first/branch/foo" diff --git a/tests.branching/workflow.script b/tests.branching/workflow.script index 59c7b152..c8ee2187 100755 --- a/tests.branching/workflow.script +++ b/tests.branching/workflow.script @@ -23,17 +23,16 @@ set -eu cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" branch me/readme-fix -cd me/readme-fix/morphs +"$SRCDIR/scripts/test-morph" branch baserock:morphs me/readme-fix "$SRCDIR/scripts/test-morph" edit baserock:hello master -cd ../baserock:hello +cd me/readme-fix/baserock:hello echo > README yoyoyo git add README git commit -m "Fix README, yo!" --quiet cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" checkout baserock:morphs master -cd master/baserock:morphs +cd master "$SRCDIR/scripts/test-morph" edit baserock:hello master "$SRCDIR/scripts/test-morph" merge me/readme-fix baserock:hello |