summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-09-26 11:20:34 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-09-26 11:21:09 +0000
commit151050c5b15e83cbfc6ac9fcd786dcb957022185 (patch)
treec3da24c1a3d3b2f2f76fb7c012cd7149d8729262
parent6a216934edb2423c9aa347329ea029041927a413 (diff)
downloadmorph-151050c5b15e83cbfc6ac9fcd786dcb957022185.tar.gz
Make branch commands work with null refs
-rw-r--r--morphlib/morphset.py8
-rw-r--r--morphlib/plugins/branch_and_merge_new_plugin.py7
-rw-r--r--yarns/branches-workspaces.yarn62
-rw-r--r--yarns/implementations.yarn12
-rw-r--r--yarns/morph.shell-lib21
5 files changed, 106 insertions, 4 deletions
diff --git a/morphlib/morphset.py b/morphlib/morphset.py
index 3c07d58e..9ef1e804 100644
--- a/morphlib/morphset.py
+++ b/morphlib/morphset.py
@@ -95,9 +95,11 @@ class MorphologySet(object):
repo_url, ref, morph = self._find_spec(
system_morph['strata'], stratum_name)
- if repo_url is None:
+ if (repo_url, ref, morph) == (None, None, None):
raise StratumNotInSystemError(system_morph['name'], stratum_name)
- m = self._get_morphology(repo_url, ref, '%s.morph' % morph)
+ m = self._get_morphology(repo_url or system_morph.repo_url,
+ ref or system_morph.ref,
+ '%s.morph' % morph)
if m is None:
raise StratumNotInSetError(stratum_name)
return m
@@ -118,7 +120,7 @@ class MorphologySet(object):
repo_url, ref, morph = self._find_spec(
stratum_morph['chunks'], chunk_name)
- if repo_url is None:
+ if (repo_url, ref, morph) == (None, None, None):
raise ChunkNotInStratumError(stratum_morph['name'], chunk_name)
return repo_url, ref, morph
diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py
index 39552ef0..edda7d9c 100644
--- a/morphlib/plugins/branch_and_merge_new_plugin.py
+++ b/morphlib/plugins/branch_and_merge_new_plugin.py
@@ -266,7 +266,9 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin):
# of triplets (repo url, ref, filename).
return [
- (spec['repo'], spec['ref'], '%s.morph' % spec['morph'])
+ (spec['repo'] or morph.repo_url,
+ spec['ref'] or morph.ref,
+ '%s.morph' % spec['morph'])
for spec in specs
]
@@ -679,6 +681,9 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin):
#TODO: Stop using app.resolve_ref
def resolve_refs(morphs):
for repo, ref in morphs.list_refs():
+ # You can't resolve null refs, so don't attempt to.
+ if repo is None or ref is None:
+ continue
# TODO: Handle refs that are only in workspace in general
if (repo == sb.root_repository_url
and ref == sb.system_branch_name):
diff --git a/yarns/branches-workspaces.yarn b/yarns/branches-workspaces.yarn
index 5273f396..f523ebcd 100644
--- a/yarns/branches-workspaces.yarn
+++ b/yarns/branches-workspaces.yarn
@@ -290,3 +290,65 @@ Creating a tag twice should fail.
WHEN attempting to tag system branch foo as test123
THEN morph failed
+Working with null repositories and refs
+---------------------------------------
+
+It is convenient to not explicitly name the repository and branch of
+a stratum morphology, instead assuming it is the same as the current
+morphology.
+
+These can be checked out like normal system branches.
+
+ SCENARIO check out an existing system branch with null refs
+ GIVEN a workspace
+ AND a git server
+ AND null refs for local strata
+ WHEN checking out the master system branch
+ THEN the system branch master is checked out
+
+Likewise we can also create new system branches from these, and we
+wouldn't need to worry about changing the system branch ref.
+
+
+ SCENARIO branch off a system branch with null refs
+ GIVEN a workspace
+ AND a git server
+ AND null refs for local strata
+ WHEN creating system branch foo
+ THEN the system branch foo is checked out
+
+When we edit a morphology with null refs, they stay null.
+
+ SCENARIO editing with null refs
+ GIVEN a workspace
+ AND a git server
+ AND null refs for local strata
+
+When creating the branch, the refs remain null.
+
+ WHEN creating system branch foo
+ THEN in branch foo, system test-system refs test-stratum in None
+
+After editing the stratum they remain null.
+
+ WHEN editing stratum test-stratum in system test-system in branch foo
+ THEN in branch foo, system test-system refs test-stratum in None
+
+Refs to chunks are still altered as usual
+
+ WHEN editing chunk test-chunk in test-stratum in test-system in branch foo
+ THEN in branch foo, system test-system refs test-stratum in None
+ AND in branch foo, stratum test-stratum refs test-chunk in foo
+ AND edited chunk test:test-chunk has git branch foo
+
+Petrifying also leaves null refs unmolested
+
+ SCENARIO morph petrifies null refs
+ GIVEN a workspace
+ AND a git server
+ AND null refs for local strata
+ WHEN creating system branch foo
+ AND pushing system branch foo to git server
+ AND remembering all refs in foo
+ AND petrifying foo
+ THEN in branch foo, system test-system refs test-stratum in None
diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn
index cfb744f7..e35e4219 100644
--- a/yarns/implementations.yarn
+++ b/yarns/implementations.yarn
@@ -114,6 +114,18 @@ another to hold a chunk.
repo-alias = test=file://$DATADIR/gits/%s#file://$DATADIR/gits/%s
EOF
+Morphologies need to support having a null ref, which means look for the
+stratum in the same repository and ref. Testing this requires different
+morphologies.
+
+ IMPLEMENTS GIVEN null refs for local strata
+ nullify_local_refs test:morphs master \
+ "$DATADIR/gits/morphs/test-system.morph" \
+ "$DATADIR/gits/morphs/test-stratum.morph"
+ run_in "$DATADIR/gits/morphs" git add .
+ run_in "$DATADIR/gits/morphs" git commit -m "Use null refs."
+
+
Implementation sections for system branch operations
----------------------------------------------------
diff --git a/yarns/morph.shell-lib b/yarns/morph.shell-lib
index 4fb1eb10..41ffbbbd 100644
--- a/yarns/morph.shell-lib
+++ b/yarns/morph.shell-lib
@@ -144,6 +144,27 @@ assert_morphologies_are_petrified()
}
+nullify_local_refs()
+{
+ python -c 'import yaml, sys
+repo = sys.argv[1]
+ref = sys.argv[2]
+for filename in sys.argv[3:]:
+ with open(filename, "r") as f:
+ d = yaml.load(f)
+ if "strata" in d:
+ for spec in d["strata"]:
+ if spec["repo"] == repo and spec["ref"] == ref:
+ spec["repo"] = spec["ref"] = None
+ if "build-depends" in d:
+ for spec in d["build-depends"]:
+ if spec["repo"] == repo and spec["ref"] == ref:
+ spec["repo"] = spec["ref"] = None
+ with open(filename, "w") as f:
+ yaml.dump(d, f)
+' "$@"
+}
+
# Currently, yarn isn't setting $SRCDIR to point at the project source
# directory. We simulate this here.