summaryrefslogtreecommitdiff
path: root/tests.merging
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2012-10-29 16:02:42 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2012-10-29 18:19:26 +0000
commit1342bf9006f28a08d1b32dc8218717ebda701dc2 (patch)
tree0872d902b6ad4af6c4e238a28bc0c01624c62e0b /tests.merging
parent9e4159ba97862c78a9cfa3e3816f18c708ccba5e (diff)
downloadmorph-1342bf9006f28a08d1b32dc8218717ebda701dc2.tar.gz
Split merge tests out from the other branching tests
Merge is by far the most complex of the branching and merging commands.
Diffstat (limited to 'tests.merging')
-rwxr-xr-xtests.merging/basic.script86
-rw-r--r--tests.merging/basic.stdout5
-rwxr-xr-xtests.merging/conflict-chunks.script85
-rw-r--r--tests.merging/conflict-chunks.stderr1
-rw-r--r--tests.merging/conflict-chunks.stdout4
-rw-r--r--tests.merging/conflict-morphology-kind.exit1
-rwxr-xr-xtests.merging/conflict-morphology-kind.script32
-rw-r--r--tests.merging/conflict-morphology-kind.stderr1
-rw-r--r--tests.merging/conflict-stratum-field-ordering.exit1
-rwxr-xr-xtests.merging/conflict-stratum-field-ordering.script106
-rw-r--r--tests.merging/conflict-stratum-field-ordering.stderr1
-rw-r--r--tests.merging/conflict-stratum-field-ordering.stdout2
-rwxr-xr-xtests.merging/from-branch-not-checked-out.script30
-rw-r--r--tests.merging/from-branch-not-checked-out.stderr1
-rw-r--r--tests.merging/move-chunk-repo.exit1
-rwxr-xr-xtests.merging/move-chunk-repo.script60
-rw-r--r--tests.merging/move-chunk-repo.stderr1
-rwxr-xr-xtests.merging/rename-chunk.script62
-rw-r--r--tests.merging/rename-stratum.exit1
-rwxr-xr-xtests.merging/rename-stratum.script58
-rw-r--r--tests.merging/rename-stratum.stderr1
-rwxr-xr-xtests.merging/setup115
-rwxr-xr-xtests.merging/warn-if-merging-petrified-morphologies.script32
-rw-r--r--tests.merging/warn-if-merging-petrified-morphologies.stdout1
24 files changed, 688 insertions, 0 deletions
diff --git a/tests.merging/basic.script b/tests.merging/basic.script
new file mode 100755
index 00000000..741e8a3f
--- /dev/null
+++ b/tests.merging/basic.script
@@ -0,0 +1,86 @@
+#!/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 merge" merges a system branch into a newly created
+# system branch
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ exit 0
+fi
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+
+# Create stable branch to merge TO
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/stable
+cd test/stable/baserock:morphs
+git push --quiet origin test/stable
+
+# Create feature branch to merge FROM
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/feature test/stable
+cd "$DATADIR/workspace/test/feature"
+
+# Edit hello in FROM
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello
+cd baserock:hello
+touch newfile.txt
+git add newfile.txt
+git commit -m foo --quiet
+
+# Commit in morphs repo
+# FIXME: this should become unnecessary since only the refs have
+# changed.
+cd ../baserock:morphs
+git commit --all --quiet -m "Update morph refs for test/feature"
+
+# Merge changes back to test/stable
+cd "$DATADIR/workspace"
+cd test/stable
+"$SRCDIR/scripts/test-morph" merge test/feature
+
+# Check results: changes to 'hello' should have been merged back to
+# test/stable.
+cd baserock:hello
+[ -e newfile.txt ]
+
+# Make sure all changes are committed and to the correct branch ('hello'
+# was built from 'master' before branching, so the changes should be
+# merged back to 'master').
+git status --short
+[ $(git rev-parse master) = $(git rev-parse HEAD) ]
+
+# Changes here should be on test/stable.
+cd ../baserock:morphs
+git status --short
+[ $(git rev-parse test/stable) = $(git rev-parse HEAD) ]
+
+# Make sure all refs to the merged branch have gone.
+! grep "\"ref\": \"test/feature\"" *.morph
+
+# The only change here was the branch refs, which have now been
+# changed back - so there should not be any new commits.
+echo "Commit message for baserock:morphs"
+git cat-file commit HEAD | tail -n 1
+
+echo
+echo "Commit message for baserock:hello"
+cd ../baserock:hello
+git cat-file commit HEAD | tail -n 1
+
diff --git a/tests.merging/basic.stdout b/tests.merging/basic.stdout
new file mode 100644
index 00000000..2bdde644
--- /dev/null
+++ b/tests.merging/basic.stdout
@@ -0,0 +1,5 @@
+Commit message for baserock:morphs
+initial
+
+Commit message for baserock:hello
+Merge system branch 'test/feature'
diff --git a/tests.merging/conflict-chunks.script b/tests.merging/conflict-chunks.script
new file mode 100755
index 00000000..98efcc3e
--- /dev/null
+++ b/tests.merging/conflict-chunks.script
@@ -0,0 +1,85 @@
+#!/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.
+
+# When conflicts occur outside the root morphs repository, 'morph merge'
+# should keep going until the end and report the list of failed repos.
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/merge-conflict-chunks.stdout"
+ cat "$SRCDIR/tests.branching/merge-conflict-chunks.stderr" >&2
+ exit 0
+fi
+
+. "$SRCDIR/scripts/setup-3rd-party-strata"
+
+# Create stable branch to merge TO
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/stable
+cd test/stable/baserock:morphs
+git push --quiet origin test/stable
+
+# Create feature branch to merge FROM
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/feature test/stable
+
+add_text_in_repo() {
+ REPO="$1"
+ TEXT="$2"
+
+ cd "$1"
+ echo $TEXT > conflict.txt
+ git add conflict.txt
+ git commit --quiet --message "Add some text"
+ cd - > /dev/null
+}
+
+# Sow the seeds of conflict
+cd "$DATADIR/workspace/test/stable"
+"$SRCDIR/scripts/test-morph" edit hello-system stratum2 hello
+"$SRCDIR/scripts/test-morph" edit hello-system stratum3 hello
+add_text_in_repo "baserock:stratum2-hello" "xyzzy"
+add_text_in_repo "baserock:stratum3-hello" "xyzzy"
+
+cd "$DATADIR/workspace/test/feature"
+"$SRCDIR/scripts/test-morph" edit hello-system stratum2 hello
+"$SRCDIR/scripts/test-morph" edit hello-system stratum3 hello
+add_text_in_repo "baserock:stratum2-hello" "plugh"
+add_text_in_repo "baserock:stratum3-hello" "plover"
+
+# This should not be necessary, one day
+cd "$DATADIR/workspace/test/stable/baserock:morphs"
+git commit --quiet --all --message "Commit refs for branch"
+cd "$DATADIR/workspace/test/stable/baserock:external-strata"
+git commit --quiet --all --message "Commit refs for branch"
+
+cd "$DATADIR/workspace/test/feature/baserock:morphs"
+git commit --quiet --all --message "Commit refs for branch"
+cd "$DATADIR/workspace/test/feature/baserock:external-strata"
+git commit --quiet --all --message "Commit refs for branch"
+
+# Merge changes from test/feature to test/stable
+cd "$DATADIR/workspace/test/stable"
+"$SRCDIR/scripts/test-morph" merge test/feature || true
+
+# Check that the repos are all clean
+for repo in "baserock:morphs" "baserock:external-strata" \
+ "baserock:stratum2-hello" "baserock:stratum3-hello"; do
+ cd "$DATADIR/workspace/test/stable/$repo"
+ git status --porcelain
+ [ $(git rev-parse HEAD) = $(git rev-parse test/stable) ]
+done
diff --git a/tests.merging/conflict-chunks.stderr b/tests.merging/conflict-chunks.stderr
new file mode 100644
index 00000000..57aafa5a
--- /dev/null
+++ b/tests.merging/conflict-chunks.stderr
@@ -0,0 +1 @@
+ERROR: merge errors were encountered. Please manually merge the target ref into test/feature in the remote system branch in each case, and then repeat the 'morph merge' operation.
diff --git a/tests.merging/conflict-chunks.stdout b/tests.merging/conflict-chunks.stdout
new file mode 100644
index 00000000..bf6d3828
--- /dev/null
+++ b/tests.merging/conflict-chunks.stdout
@@ -0,0 +1,4 @@
+Merge conflicts in baserock:stratum2-hello:
+ conflict.txt
+Merge conflicts in baserock:stratum3-hello:
+ conflict.txt
diff --git a/tests.merging/conflict-morphology-kind.exit b/tests.merging/conflict-morphology-kind.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests.merging/conflict-morphology-kind.exit
@@ -0,0 +1 @@
+1
diff --git a/tests.merging/conflict-morphology-kind.script b/tests.merging/conflict-morphology-kind.script
new file mode 100755
index 00000000..d8fcc6ef
--- /dev/null
+++ b/tests.merging/conflict-morphology-kind.script
@@ -0,0 +1,32 @@
+#!/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.
+
+# If morphology kind differs between branches, it's a merge conflict
+
+set -eu
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/unmergable
+
+cd "$DATADIR/workspace/test/unmergable/baserock:morphs"
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum
+sed -ie 's/"kind": "stratum"/"kind": "chunk"/' hello-stratum.morph
+git commit --quiet --all -m "Unmergeable because kind has changed"
+
+cd "$DATADIR/workspace/master/baserock:morphs"
+"$SRCDIR/scripts/test-morph" merge test/unmergable
diff --git a/tests.merging/conflict-morphology-kind.stderr b/tests.merging/conflict-morphology-kind.stderr
new file mode 100644
index 00000000..ff6539a7
--- /dev/null
+++ b/tests.merging/conflict-morphology-kind.stderr
@@ -0,0 +1 @@
+ERROR: merge conflict: "kind" of morphology hello-system.hello-stratum changed from stratum to chunk
diff --git a/tests.merging/conflict-stratum-field-ordering.exit b/tests.merging/conflict-stratum-field-ordering.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests.merging/conflict-stratum-field-ordering.exit
@@ -0,0 +1 @@
+1
diff --git a/tests.merging/conflict-stratum-field-ordering.script b/tests.merging/conflict-stratum-field-ordering.script
new file mode 100755
index 00000000..071d5204
--- /dev/null
+++ b/tests.merging/conflict-stratum-field-ordering.script
@@ -0,0 +1,106 @@
+#!/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.
+
+# Conflict caused by two equivalent strata having different order in two
+# different branches
+
+# Morph should possibly resolve this conflict automatically in the future,
+# because the meaning of the morphologies is unambiguious if not the
+# contents. It depends on how much weight we give to the sort order of
+# the morphology from a developer's point of view.
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/merge-conflict-stratum.stdout"
+ cat "$SRCDIR/tests.branching/merge-conflict-stratum.stderr" >&2
+ exit 1
+fi
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+
+# Create stable branch to merge TO
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/stable
+cd test/stable/baserock:morphs
+git push --quiet origin test/stable
+
+# Create feature branch to merge FROM
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/feature test/stable
+
+# Need 2 chunks!
+
+# Make a change in TO
+cd "$DATADIR/workspace/test/stable"
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum
+cd baserock:morphs
+cat <<EOF > "hello-stratum.morph"
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "hello-runtime",
+ "repo": "baserock:hello",
+ "ref": "master",
+ "morph": "hello",
+ "build-depends": []
+ },
+ {
+ "name": "hello-devel",
+ "repo": "baserock:hello",
+ "ref": "master",
+ "morph": "hello",
+ "build-depends": []
+ }
+ ]
+}
+EOF
+git commit --quiet --all -m "Split up 'hello' chunk into runtime and devel"
+
+# Make a change in FROM that isn't very mergable
+cd "$DATADIR/workspace/test/feature"
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum
+cd baserock:morphs
+cat <<EOF > "hello-stratum.morph"
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "hello-devel",
+ "repo": "baserock:hello",
+ "ref": "master",
+ "morph": "hello",
+ "build-depends": []
+ },
+ {
+ "name": "hello-runtime",
+ "repo": "baserock:hello",
+ "ref": "master",
+ "morph": "hello",
+ "build-depends": []
+ }
+ ]
+}
+EOF
+git commit --quiet --all -m "Split up 'hello' chunk into devel and runtime"
+
+# Merge changes from test/feature to test/stable - we expect failure
+cd "$DATADIR/workspace/test/stable"
+"$SRCDIR/scripts/test-morph" merge test/feature
diff --git a/tests.merging/conflict-stratum-field-ordering.stderr b/tests.merging/conflict-stratum-field-ordering.stderr
new file mode 100644
index 00000000..57aafa5a
--- /dev/null
+++ b/tests.merging/conflict-stratum-field-ordering.stderr
@@ -0,0 +1 @@
+ERROR: merge errors were encountered. Please manually merge the target ref into test/feature in the remote system branch in each case, and then repeat the 'morph merge' operation.
diff --git a/tests.merging/conflict-stratum-field-ordering.stdout b/tests.merging/conflict-stratum-field-ordering.stdout
new file mode 100644
index 00000000..cce0973c
--- /dev/null
+++ b/tests.merging/conflict-stratum-field-ordering.stdout
@@ -0,0 +1,2 @@
+Merge conflicts in baserock:morphs:
+ hello-stratum.morph
diff --git a/tests.merging/from-branch-not-checked-out.script b/tests.merging/from-branch-not-checked-out.script
new file mode 100755
index 00000000..2ead7f0f
--- /dev/null
+++ b/tests.merging/from-branch-not-checked-out.script
@@ -0,0 +1,30 @@
+#!/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.
+
+# Handle 'from' branch not being checked out
+
+set -eu
+
+# Create system branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+cd master
+
+# 'From' branch is not checked out (and also doesn't exist, but that
+# problem can only be detected when 'morph checkout' is run)
+"$SRCDIR/scripts/test-morph" merge baserock/newbranch || true
diff --git a/tests.merging/from-branch-not-checked-out.stderr b/tests.merging/from-branch-not-checked-out.stderr
new file mode 100644
index 00000000..6a9cc8a9
--- /dev/null
+++ b/tests.merging/from-branch-not-checked-out.stderr
@@ -0,0 +1 @@
+ERROR: branch baserock/newbranch must be checked out before it can be merged
diff --git a/tests.merging/move-chunk-repo.exit b/tests.merging/move-chunk-repo.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests.merging/move-chunk-repo.exit
@@ -0,0 +1 @@
+1
diff --git a/tests.merging/move-chunk-repo.script b/tests.merging/move-chunk-repo.script
new file mode 100755
index 00000000..d14d586f
--- /dev/null
+++ b/tests.merging/move-chunk-repo.script
@@ -0,0 +1,60 @@
+#!/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.
+
+# "morph merge" should detect changes in a repo that was added as part of the
+# branch and warn the user that the changes will not be merged automatically
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/merge-with-chunk-repo-moved.stderr" >&2
+ exit 1
+fi
+
+# Create system branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" branch baserock:morphs baserock/newbranch
+
+"$SRCDIR/scripts/test-morph" 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).
+git clone -q "$DATADIR/hello" "$DATADIR/hello-lorried"
+cd "$DATADIR/workspace/baserock/newbranch/baserock:morphs"
+sed -e 's/"repo": "baserock:hello"/"repo": "baserock:hello-lorried"/' \
+ -e 's/"ref": "baserock\/newbranch"/"ref": "master"/' \
+ -i hello-stratum.morph
+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
+cd "$DATADIR/workspace/baserock/newbranch/baserock:hello-lorried"
+touch newfile.txt
+git add newfile.txt
+git commit -m "Add new file" --quiet
+
+cd "$DATADIR/workspace/baserock/newbranch/baserock:morphs"
+git commit -q --all -m "Update system branch refs"
+
+# Try to merge changes back to master (should fail, because we don't support
+# adding chunks inside branches yet).
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+cd master
+"$SRCDIR/scripts/test-morph" merge baserock/newbranch
diff --git a/tests.merging/move-chunk-repo.stderr b/tests.merging/move-chunk-repo.stderr
new file mode 100644
index 00000000..95fe61e6
--- /dev/null
+++ b/tests.merging/move-chunk-repo.stderr
@@ -0,0 +1 @@
+ERROR: chunk hello was added within this branch and subsequently edited. This is not yet supported: refusing to merge.
diff --git a/tests.merging/rename-chunk.script b/tests.merging/rename-chunk.script
new file mode 100755
index 00000000..06969b70
--- /dev/null
+++ b/tests.merging/rename-chunk.script
@@ -0,0 +1,62 @@
+#!/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.
+
+# "morph merge" should pull changes from a chunk even if its name was changed
+# in the branch
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ exit 0
+fi
+
+# Create system branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" branch baserock:morphs baserock/newbranch
+
+# Rename the chunk, and then commit a seperate change
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum hello
+cd baserock/newbranch/baserock:hello
+
+cat hello.morph | sed -e 's/"name": "hello"/"name": "goodbye"/' > goodbye.morph
+git rm -q hello.morph
+git add goodbye.morph
+git commit -m "Rename chunk" --quiet
+
+touch newfile.txt
+git add newfile.txt
+git commit -m "Add new file" --quiet
+
+# Update stratum to point at the renamed chunk
+cd ../baserock:morphs
+sed -ie 's/"name": "hello"/"name": "goodbye"/' hello-stratum.morph
+git commit --all --quiet -m "Update morph refs for baserock/newbranch"
+
+# Merge changes back to master
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+cd master
+"$SRCDIR/scripts/test-morph" merge baserock/newbranch
+
+# Morph should have realised that 'goodbye' is not a new chunk,
+# and pulled in the changes from 'hello' in the old branch
+cd baserock:hello
+[ ! -e hello.morph ]
+[ -e goodbye.morph ]
+[ -e newfile.txt ]
diff --git a/tests.merging/rename-stratum.exit b/tests.merging/rename-stratum.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests.merging/rename-stratum.exit
@@ -0,0 +1 @@
+1
diff --git a/tests.merging/rename-stratum.script b/tests.merging/rename-stratum.script
new file mode 100755
index 00000000..6daac566
--- /dev/null
+++ b/tests.merging/rename-stratum.script
@@ -0,0 +1,58 @@
+#!/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.
+
+# "morph merge" should deal with stratum renames; currently it doesn't deal
+# very well, but at least we don't crash.
+
+set -eu
+
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/merge-with-stratum-renamed.stderr" 1>&2
+ exit 1
+fi
+
+# Create system branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" branch baserock:morphs baserock/newbranch
+
+# The user may 'morph edit hello-system hello-stratum hello' and commit here:
+# we currently silently ignore her changes on merge, because we don't
+# associate hello-stratum and goodbye-stratum at all.
+
+# Rename the stratum
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum
+cd baserock/newbranch/baserock:morphs
+
+sed -e 's/"morph": "hello-stratum"/"morph": "goodbye-stratum"/'\
+ -i hello-system.morph
+sed -e 's/"name": "hello-stratum"/"name": "goodbye-stratum"/' \
+ hello-stratum.morph > goodbye-stratum.morph
+git rm -q hello-stratum.morph
+git add goodbye-stratum.morph
+git commit -q --all -m "Rename hello-stratum to goodbye-stratum"
+
+# The user may 'morph edit hello-system goodbye-stratum hello' and commit
+# here, too: same problem.
+
+# Merge changes back to master (this should fail, because we don't support
+# adding strata inside branches yet).
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+cd master
+"$SRCDIR/scripts/test-morph" merge baserock/newbranch
diff --git a/tests.merging/rename-stratum.stderr b/tests.merging/rename-stratum.stderr
new file mode 100644
index 00000000..ff408036
--- /dev/null
+++ b/tests.merging/rename-stratum.stderr
@@ -0,0 +1 @@
+ERROR: goodbye-stratum.morph was not found in TMP/workspace/master/baserock:morphs at ref 804a475402fb6ded64a2749c7adf5b33c7c8ce1e
diff --git a/tests.merging/setup b/tests.merging/setup
new file mode 100755
index 00000000..f075e7b1
--- /dev/null
+++ b/tests.merging/setup
@@ -0,0 +1,115 @@
+#!/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.
+
+
+# Set up $DATADIR.
+#
+# - a morph.conf configuration file
+# - an empty morph workspace directory
+# - a git repository called "morphs" for fake system, stratum morphologies
+# - a git repository calle "hello" for a dummy chunk
+
+set -eu
+
+source "$SRCDIR/scripts/fix-committer-info"
+
+# Create a morph configuration file
+cat <<EOF > "$DATADIR/morph.conf"
+[config]
+repo-alias = baserock=file://$DATADIR/%s#file://$DATADIR/%s
+cachedir = $DATADIR/workspace/.morph/cache
+log = $DATADIR/morph.log
+keep-path = true
+no-distcc = true
+quiet = true
+EOF
+
+
+# Create an empty directory to be used as a morph workspace
+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",
+ "kind": "system",
+ "system-kind": "syslinux-disk",
+ "arch": "$(uname -m)",
+ "disk-size": "1G",
+ "strata": [
+ {
+ "morph": "hello-stratum",
+ "repo": "baserock:morphs",
+ "ref": "master"
+ }
+ ]
+}
+EOF
+
+cat <<EOF > "$DATADIR/morphs/hello-stratum.morph"
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "hello",
+ "repo": "baserock:hello",
+ "ref": "master",
+ "build-depends": []
+ }
+ ]
+}
+EOF
+
+scripts/run-git-in "$DATADIR/morphs" init
+scripts/run-git-in "$DATADIR/morphs" add .
+scripts/run-git-in "$DATADIR/morphs" commit -m initial
+
+
+# Add an extra branch to the morphs repo.
+scripts/run-git-in "$DATADIR/morphs" checkout -b alfred
+touch "$DATADIR/morphs/this.is.alfred"
+scripts/run-git-in "$DATADIR/morphs" add this.is.alfred
+scripts/run-git-in "$DATADIR/morphs" commit --quiet -m 'mark as alfred'
+scripts/run-git-in "$DATADIR/morphs" checkout master
+
+
+# Create a dummy chunk repository
+mkdir "$DATADIR/hello"
+
+cat <<EOF > "$DATADIR/hello/hello.morph"
+{
+ "name": "hello",
+ "kind": "chunk",
+ "build-system": "dummy"
+}
+EOF
+
+scripts/run-git-in "$DATADIR/hello" init
+scripts/run-git-in "$DATADIR/hello" add .
+scripts/run-git-in "$DATADIR/hello" commit -m initial
+
+
+# Add an extra branch to the hello repo.
+scripts/run-git-in "$DATADIR/hello" checkout -b alfred
+scripts/run-git-in "$DATADIR/hello" checkout master
+
diff --git a/tests.merging/warn-if-merging-petrified-morphologies.script b/tests.merging/warn-if-merging-petrified-morphologies.script
new file mode 100755
index 00000000..12e726ed
--- /dev/null
+++ b/tests.merging/warn-if-merging-petrified-morphologies.script
@@ -0,0 +1,32 @@
+#!/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.
+
+# If the user merges a petrified branch into an unpetrified branch,
+# we should warn them.
+
+set -eu
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
+"$SRCDIR/scripts/test-morph" branch baserock:morphs test/petrified
+
+cd "$DATADIR/workspace/test/petrified/baserock:morphs"
+"$SRCDIR/scripts/test-morph" petrify
+git commit --quiet --all -m "Petrify branch"
+
+cd "$DATADIR/workspace/master/baserock:morphs"
+"$SRCDIR/scripts/test-morph" merge test/petrified
diff --git a/tests.merging/warn-if-merging-petrified-morphologies.stdout b/tests.merging/warn-if-merging-petrified-morphologies.stdout
new file mode 100644
index 00000000..65985486
--- /dev/null
+++ b/tests.merging/warn-if-merging-petrified-morphologies.stdout
@@ -0,0 +1 @@
+WARNING: chunk "hello-system.hello-stratum.hello" is now petrified