diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-08-19 15:37:05 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-08-19 15:37:05 +0000 |
commit | 2dc382a2a9ae977b1158002cd2631ec5593959c1 (patch) | |
tree | 5d6aaed1754a2392e35a8f548171f4757584c77f | |
parent | 89a019af088ff62459699a6efdadf8ac8fe35dd9 (diff) | |
parent | 7f25c6bea678eb82fdfe024013dac5d0c01af152 (diff) | |
download | morph-2dc382a2a9ae977b1158002cd2631ec5593959c1.tar.gz |
Merge branch 'liw/restore-old-cmds'
Reviewed-by: Daniel Silverstone
-rw-r--r-- | morphlib/plugins/branch_and_merge_new_plugin.py | 2 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 166 | ||||
-rwxr-xr-x | tests.as-root/build-handles-stratum-build-depends.script | 2 | ||||
-rwxr-xr-x | tests.as-root/build-with-external-strata.script | 2 | ||||
-rwxr-xr-x | tests.branching/add-then-edit.script | 4 | ||||
-rwxr-xr-x | tests.branching/edit-checkouts-existing-chunk.script | 4 | ||||
-rwxr-xr-x | tests.branching/edit-clones-chunk.script | 4 | ||||
-rwxr-xr-x | tests.branching/edit-handles-submodules.script | 4 | ||||
-rwxr-xr-x | tests.branching/edit-updates-stratum-build-depends.script | 2 | ||||
-rwxr-xr-x | tests.branching/edit-updates-stratum.script | 2 | ||||
-rwxr-xr-x | tests.branching/edit-works-after-branch-root-was-renamed.script | 2 | ||||
-rwxr-xr-x | tests.branching/petrify.script | 2 | ||||
-rwxr-xr-x | tests.merging/move-chunk-repo.script | 4 | ||||
-rwxr-xr-x | tests.merging/rename-stratum.script | 2 | ||||
-rw-r--r-- | yarns/branches-workspaces.yarn | 2 | ||||
-rw-r--r-- | yarns/implementations.yarn | 4 |
16 files changed, 184 insertions, 24 deletions
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index e5fe52e6..9dd9c915 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -42,7 +42,7 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): self.app.add_subcommand( 'branch', self.branch, arg_synopsis='REPO NEW [OLD]') self.app.add_subcommand( - 'edit', self.edit, arg_synopsis='SYSTEM STRATUM [CHUNK]') + 'new-edit', self.edit, arg_synopsis='SYSTEM STRATUM [CHUNK]') self.app.add_subcommand( 'show-system-branch', self.show_system_branch, arg_synopsis='') self.app.add_subcommand( diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 85e74501..53b94859 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -57,10 +57,15 @@ class BranchAndMergePlugin(cliapp.Plugin): def enable(self): # User-facing commands + self.app.add_subcommand('old-init', self.init, arg_synopsis='[DIR]') + self.app.add_subcommand('old-branch', self.branch, + arg_synopsis='REPO NEW [OLD]') + self.app.add_subcommand('old-checkout', self.checkout, + arg_synopsis='REPO BRANCH') self.app.add_subcommand('merge', self.merge, arg_synopsis='BRANCH') -# self.app.add_subcommand('edit', self.edit, -# arg_synopsis='SYSTEM STRATUM [CHUNK]') + self.app.add_subcommand('edit', self.edit, + arg_synopsis='SYSTEM STRATUM [CHUNK]') self.app.add_subcommand('petrify', self.petrify) self.app.add_subcommand('unpetrify', self.unpetrify) self.app.add_subcommand( @@ -82,6 +87,15 @@ class BranchAndMergePlugin(cliapp.Plugin): self.app.add_subcommand('foreach', self.foreach, arg_synopsis='-- COMMAND [ARGS...]') + # Plumbing commands (FIXME: should be hidden from --help by default) + self.app.add_subcommand('old-workspace', self.workspace, + arg_synopsis='') + self.app.add_subcommand( + 'old-show-system-branch', self.show_system_branch, + arg_synopsis='') + self.app.add_subcommand('old-show-branch-root', self.show_branch_root, + arg_synopsis='') + def disable(self): pass @@ -353,7 +367,7 @@ class BranchAndMergePlugin(cliapp.Plugin): 'cluster': [ 'name', 'systems', - ], + ] } also_known = { @@ -541,6 +555,50 @@ class BranchAndMergePlugin(cliapp.Plugin): return system_key, metadata_cache_id_lookup + def init(self, args): + '''Initialize a workspace directory. + + Command line argument: + + * `DIR` is the directory to use as a workspace, and defaults to + the current directory. + + This creates a workspace, either in the current working directory, + or if `DIR` is given, in that directory. If the directory doesn't + exist, it is created. If it does exist, it must be empty. + + You need to run `morph init` to initialise a workspace, or none + of the other system branching tools will work: they all assume + an existing workspace. Note that a workspace only exists on your + machine, not on the git server. + + Example: + + morph init /src/workspace + cd /src/workspace + + ''' + + if not args: + args = ['.'] + elif len(args) > 1: + raise cliapp.AppException('init must get at most one argument') + + dirname = args[0] + + # verify the workspace is empty (and thus, can be used) or + # create it if it doesn't exist yet + if os.path.exists(dirname): + if os.listdir(dirname) != []: + raise cliapp.AppException('can only initialize empty ' + 'directory as a workspace: %s' % + dirname) + else: + os.makedirs(dirname) + + os.mkdir(os.path.join(dirname, '.morph')) + self.app.status(msg='Initialized morph workspace', chatty=True) + def _create_branch(self, workspace, branch_name, repo, original_ref): '''Create a branch called branch_name based off original_ref. @@ -580,6 +638,81 @@ class BranchAndMergePlugin(cliapp.Plugin): self.remove_branch_dir_safe(workspace, branch_name) raise + @warns_git_identity + def branch(self, args): + '''Create a new system branch. + + Command line arguments: + + * `REPO` is a repository URL. + * `NEW` is the name of the new system branch. + * `OLD` is the point from which to branch, and defaults to `master`. + + This creates a new system branch. It needs to be run in an + existing workspace (see `morph workspace`). It creates a new + git branch in the clone of the repository in the workspace. The + system branch will not be visible on the git server until you + push your changes to the repository. + + Example: + + cd /src/workspace + morph branch baserock:baserock:morphs jrandom/new-feature + + ''' + + if len(args) not in [2, 3]: + raise cliapp.AppException('morph branch needs name of branch ' + 'as parameter') + + repo = args[0] + new_branch = args[1] + commit = 'master' if len(args) == 2 else args[2] + + self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app) + if self.get_cached_repo(repo).ref_exists(new_branch): + raise cliapp.AppException('branch %s already exists in ' + 'repository %s' % (new_branch, repo)) + + # Create the system branch directory. + workspace = self.deduce_workspace() + self._create_branch(workspace, new_branch, repo, commit) + + @warns_git_identity + def checkout(self, args): + '''Check out an existing system branch. + + Command line arguments: + + * `REPO` is the URL to the repository to the root repository of + a system branch. + * `BRANCH` is the name of the system branch. + + This will check out an existing system branch to an existing + workspace. You must create the workspace first. This only checks + out the root repository, not the repositories for individual + components. You need to use `morph edit` to check out those. + + Example: + + cd /src/workspace + morph checkout baserock:baserock/morphs master + + ''' + + if len(args) != 2: + raise cliapp.AppException('morph checkout needs a repo and the ' + 'name of a branch as parameters') + + repo = args[0] + system_branch = args[1] + + self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app) + + # Create the system branch directory. + workspace = self.deduce_workspace() + self._create_branch(workspace, system_branch, repo, system_branch) + def checkout_repository(self, branch_dir, repo, ref, parent_ref=None): '''Make a chunk or stratum repository available for a system branch @@ -1919,3 +2052,30 @@ class BranchAndMergePlugin(cliapp.Plugin): raise cliapp.AppException( 'Command failed at repo %s: %s' % (repo, ' '.join(args))) + def workspace(self, args): + '''Show the toplevel directory of the current workspace.''' + + self.app.output.write('%s\n' % self.deduce_workspace()) + + def show_system_branch(self, args): + '''Show the name of the current system branch.''' + + branch, dirname = self.deduce_system_branch() + self.app.output.write('%s\n' % branch) + + def show_branch_root(self, args): + '''Show the name of the repository holding the system morphologies. + + This would, for example, write out something like: + + /src/ws/master/baserock:baserock/morphs + + when the master branch of the `baserock:baserock/morphs` + repository is checked out. + + ''' + + workspace = self.deduce_workspace() + system_branch, branch_dir = self.deduce_system_branch() + branch_root = self.get_branch_config(branch_dir, 'branch.root') + self.app.output.write('%s\n' % branch_root) diff --git a/tests.as-root/build-handles-stratum-build-depends.script b/tests.as-root/build-handles-stratum-build-depends.script index 22d07c72..fd6a0544 100755 --- a/tests.as-root/build-handles-stratum-build-depends.script +++ b/tests.as-root/build-handles-stratum-build-depends.script @@ -39,7 +39,7 @@ cd test/stratum-build-depends/test:morphs # be updated here. Any build-depends of any altered strata also need to # be altered, such as the 'tools-stratum' which depends on linux-stratum # If they are not updated, the build command will fail. -"$SRCDIR/scripts/test-morph" edit linux-system hello-stratum +"$SRCDIR/scripts/test-morph" new-edit linux-system hello-stratum # Likewise, this command must update build-depends or the 'repo' field will # not be changed in the temporary build branch, leading to: diff --git a/tests.as-root/build-with-external-strata.script b/tests.as-root/build-with-external-strata.script index f5d86dfe..d722f907 100755 --- a/tests.as-root/build-with-external-strata.script +++ b/tests.as-root/build-with-external-strata.script @@ -34,7 +34,7 @@ cd "$DATADIR/workspace" # don't commit it, in one of the external strata, as a challenge for # 'morph build'. cd "branch1" -"$SRCDIR/scripts/test-morph" edit hello-system stratum2 +"$SRCDIR/scripts/test-morph" new-edit hello-system stratum2 cd "test:external-strata" awk ' diff --git a/tests.branching/add-then-edit.script b/tests.branching/add-then-edit.script index d6a2270f..cdb28fd2 100755 --- a/tests.branching/add-then-edit.script +++ b/tests.branching/add-then-edit.script @@ -30,7 +30,7 @@ cd "me/add-then-edit" cd test:morphs ## Sub-optimally, to alter the stratum, you have to `morph edit` it first -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum git apply <<'EOF' diff --git a/hello-stratum.morph b/hello-stratum.morph @@ -50,7 +50,7 @@ index 3b7be17..c79a9af 100644 name: hello-stratum EOF -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum goodbye +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum goodbye # check whether the stratum still contains the goodbye chunk grep -qFe goodbye hello-stratum.morph diff --git a/tests.branching/edit-checkouts-existing-chunk.script b/tests.branching/edit-checkouts-existing-chunk.script index a10a72d1..9584d1a3 100755 --- a/tests.branching/edit-checkouts-existing-chunk.script +++ b/tests.branching/edit-checkouts-existing-chunk.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2013 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 @@ -27,7 +27,7 @@ cd "$DATADIR/workspace" # Edit the hello chunk in alfred. cd "alfred" -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello echo "Current branches:" "$SRCDIR/scripts/test-morph" foreach git branch diff --git a/tests.branching/edit-clones-chunk.script b/tests.branching/edit-clones-chunk.script index 1b6b8a04..ecc2c55e 100755 --- a/tests.branching/edit-clones-chunk.script +++ b/tests.branching/edit-clones-chunk.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2013 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 @@ -26,7 +26,7 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" branch test:morphs newbranch # Edit chunk. -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello echo "Current branches:" "$SRCDIR/scripts/test-morph" foreach git branch diff --git a/tests.branching/edit-handles-submodules.script b/tests.branching/edit-handles-submodules.script index d164facc..389784ed 100755 --- a/tests.branching/edit-handles-submodules.script +++ b/tests.branching/edit-handles-submodules.script @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2013 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 @@ -26,7 +26,7 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" branch test:morphs newbranch # Submodules should be set up automatically -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello cd "$DATADIR/workspace/newbranch/test:hello" [ -e foolib/README ] diff --git a/tests.branching/edit-updates-stratum-build-depends.script b/tests.branching/edit-updates-stratum-build-depends.script index a108ce8a..ed11b584 100755 --- a/tests.branching/edit-updates-stratum-build-depends.script +++ b/tests.branching/edit-updates-stratum-build-depends.script @@ -63,7 +63,7 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" branch test:morphs newbranch # Edit chunk. -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello # See what effect the editing had. "$SRCDIR/scripts/run-git-in" "newbranch/test:morphs" diff diff --git a/tests.branching/edit-updates-stratum.script b/tests.branching/edit-updates-stratum.script index bfe16c8b..84974765 100755 --- a/tests.branching/edit-updates-stratum.script +++ b/tests.branching/edit-updates-stratum.script @@ -26,7 +26,7 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" branch test:morphs newbranch # Edit chunk. -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello # See what effect the editing had. "$SRCDIR/scripts/run-git-in" "newbranch/test:morphs" diff diff --git a/tests.branching/edit-works-after-branch-root-was-renamed.script b/tests.branching/edit-works-after-branch-root-was-renamed.script index c7043e27..9591b587 100755 --- a/tests.branching/edit-works-after-branch-root-was-renamed.script +++ b/tests.branching/edit-works-after-branch-root-was-renamed.script @@ -35,7 +35,7 @@ cd "$DATADIR/workspace" cd "$DATADIR/workspace/master" mv test:morphs my-renamed-morphs -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello "$SRCDIR/scripts/list-tree" "$DATADIR/workspace" | grep -v '/\.git/' | sed 's,/cache/gits/file_[^/]*_,/cache/gits/file_,' | diff --git a/tests.branching/petrify.script b/tests.branching/petrify.script index fed8e965..9a276d71 100755 --- a/tests.branching/petrify.script +++ b/tests.branching/petrify.script @@ -29,7 +29,7 @@ cd "$DATADIR/workspace" cd test/petrify/test:morphs git push --quiet origin HEAD -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum goodbye +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum goodbye (cd ../test:goodbye && git push --quiet origin HEAD) "$SRCDIR/scripts/test-morph" petrify diff --git a/tests.merging/move-chunk-repo.script b/tests.merging/move-chunk-repo.script index 3a00015b..40f3cc4a 100755 --- a/tests.merging/move-chunk-repo.script +++ b/tests.merging/move-chunk-repo.script @@ -26,7 +26,7 @@ cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init "$SRCDIR/scripts/test-morph" branch test:morphs baserock/newbranch -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello # Chunk moves to a new location (we manually update the ref back to master # here, so 'morph edit' can create a system branch in the new repo from it). @@ -38,7 +38,7 @@ sed -e 's/"repo": "test:hello"/"repo": "test:hello-lorried"/' \ git commit -q --all -m "'hello' repository has moved" # Now we further edit the chunk, just for fun. -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum hello cd "$DATADIR/workspace/baserock/newbranch/test:hello-lorried" touch newfile.txt git add newfile.txt diff --git a/tests.merging/rename-stratum.script b/tests.merging/rename-stratum.script index ba759fa3..5fa13130 100755 --- a/tests.merging/rename-stratum.script +++ b/tests.merging/rename-stratum.script @@ -31,7 +31,7 @@ cd "$DATADIR/workspace" # associate hello-stratum and goodbye-stratum at all. # Rename the stratum -"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum +"$SRCDIR/scripts/test-morph" new-edit hello-system hello-stratum cd baserock/newbranch/test:morphs sed -e 's/"morph": "hello-stratum"/"morph": "goodbye-stratum"/'\ diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn index 3af362a1..7c8715a7 100644 --- a/yarns/branches-workspaces.yarn +++ b/yarns/branches-workspaces.yarn @@ -90,7 +90,7 @@ to check for that locally. Similarly, attempting to branch a system branch should fail if the repository does not contain any system morphologies. - SCENARIO checking out a system branch with no systems + SCENARIO branching a system branch with no systems GIVEN a workspace AND a git server WHEN morph attempts to branch a repository with no systems diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn index cfb744f7..cc3ef3e5 100644 --- a/yarns/implementations.yarn +++ b/yarns/implementations.yarn @@ -226,11 +226,11 @@ Editing morphologies with `morph edit`. IMPLEMENTS WHEN editing stratum (\S+) in system (\S+) in branch (\S+) cd "$DATADIR/workspace/$MATCH_3/test:morphs" - run_morph edit "$MATCH_2" "$MATCH_1" + run_morph new-edit "$MATCH_2" "$MATCH_1" IMPLEMENTS WHEN editing chunk (\S+) in (\S+) in (\S+) in branch (\S+) cd "$DATADIR/workspace/$MATCH_4/test:morphs" - run_morph edit "$MATCH_3" "$MATCH_2" "$MATCH_1" + run_morph new-edit "$MATCH_3" "$MATCH_2" "$MATCH_1" IMPLEMENTS THEN edited chunk (\S+) has git branch (\S+) ls -l "$DATADIR/workspace/$MATCH_2" |