summaryrefslogtreecommitdiff
path: root/tests.branching
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-12-05 17:51:47 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-12-13 14:30:35 +0000
commit51e4bbb4dffde9574404df9c5e947f518dc49a41 (patch)
tree208d2826e88932f2442c44b4268bdda76346206f /tests.branching
parentd63c97a0bef1cd2f03ca266acda67cad065632df (diff)
downloadmorph-51e4bbb4dffde9574404df9c5e947f518dc49a41.tar.gz
Add an initial implementation of "morph tag"
In order to make releases and freeze system branches entirely, we need to be able to 100% petrify a system branch (that is, resolve ALL refs into SHA1s) and tag this state to be able to check it out again later. This is essentially what "morph tag" does. It takes a tag name and an arbitrary amount of arguments to "git tag", petrifies all morphologies of the current system branch behind the scenes, creates a dangling commit and attaches an annotated tag to it. Petrifying in this case means that all refs used for chunks are resolved into commit SHA1s. For stratum and system morphologies, the refs are replaced by the name of the tag that's being created. The "tag" command also supports tagging when stratum morphologies are spread across multiple repositories. In this case, it will include all statum morphologies from other repos in the tag commi in the branch root repo. The references to these morphologies are updated so that they point to the branch root repo and the tag being created. This commit also adds a few tests for "morph tag" to verify that all this works.
Diffstat (limited to 'tests.branching')
-rwxr-xr-xtests.branching/morph-tag-creates-commit-and-tag.script39
-rw-r--r--tests.branching/morph-tag-creates-commit-and-tag.stdout55
-rw-r--r--tests.branching/morph-tag-fails-if-tag-exists.exit1
-rwxr-xr-xtests.branching/morph-tag-fails-if-tag-exists.script33
-rw-r--r--tests.branching/morph-tag-fails-if-tag-exists.stderr3
-rwxr-xr-xtests.branching/morph-tag-tag-works-as-expected.script46
-rw-r--r--tests.branching/morph-tag-tag-works-as-expected.stdout58
-rwxr-xr-xtests.branching/morph-tag-works-with-multiple-morphs-repos.script123
-rw-r--r--tests.branching/morph-tag-works-with-multiple-morphs-repos.stdout172
9 files changed, 530 insertions, 0 deletions
diff --git a/tests.branching/morph-tag-creates-commit-and-tag.script b/tests.branching/morph-tag-creates-commit-and-tag.script
new file mode 100755
index 00000000..4de3e4b9
--- /dev/null
+++ b/tests.branching/morph-tag-creates-commit-and-tag.script
@@ -0,0 +1,39 @@
+#!/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 tag example-tag' successfully creates a dangling
+## commit and an annotated tag pointing to this commit.
+
+set -eu
+
+# Make sure the commits always have the same SHA1s.
+source "$SRCDIR/scripts/fix-committer-info"
+
+# Create a workspace and branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout test:morphs master
+
+# Tag the system branch.
+"$SRCDIR/scripts/test-morph" tag example-tag -- -m Message
+
+# Show the tag itself and its log. This allows to verify a couple of things,
+# including that the commit and tag are created, that the commit message is
+# set correctly and that all references are petrified.
+"$SRCDIR/scripts/test-morph" foreach -- git show example-tag
+"$SRCDIR/scripts/test-morph" foreach -- git log example-tag
diff --git a/tests.branching/morph-tag-creates-commit-and-tag.stdout b/tests.branching/morph-tag-creates-commit-and-tag.stdout
new file mode 100644
index 00000000..38bca41b
--- /dev/null
+++ b/tests.branching/morph-tag-creates-commit-and-tag.stdout
@@ -0,0 +1,55 @@
+test:morphs
+tag example-tag
+Tagger: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+Message
+
+commit 7cab6b5f121518b3ecd585c4af3c5bc267947bae
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ Message
+
+diff --git a/hello-stratum.morph b/hello-stratum.morph
+index 3b7be17..87561c1 100644
+--- a/hello-stratum.morph
++++ b/hello-stratum.morph
+@@ -5,8 +5,9 @@
+ {
+ "name": "hello",
+ "repo": "test:hello",
+- "ref": "master",
+- "build-depends": []
++ "ref": "f4d032b42c0134e67bdf19a43fa99072493667d7",
++ "build-depends": [],
++ "unpetrify-ref": "master"
+ }
+ ]
+ }
+diff --git a/hello-system.morph b/hello-system.morph
+index f3f64b4..d26675d 100644
+--- a/hello-system.morph
++++ b/hello-system.morph
+@@ -8,7 +8,8 @@
+ {
+ "morph": "hello-stratum",
+ "repo": "test:morphs",
+- "ref": "master"
++ "ref": "example-tag",
++ "unpetrify-ref": "master"
+ }
+ ]
+ }
+test:morphs
+commit 7cab6b5f121518b3ecd585c4af3c5bc267947bae
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ Message
+
+commit 48d38ef3f39857d7dba4ed1ffc51653c6bed4906
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ initial
diff --git a/tests.branching/morph-tag-fails-if-tag-exists.exit b/tests.branching/morph-tag-fails-if-tag-exists.exit
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests.branching/morph-tag-fails-if-tag-exists.exit
@@ -0,0 +1 @@
+1
diff --git a/tests.branching/morph-tag-fails-if-tag-exists.script b/tests.branching/morph-tag-fails-if-tag-exists.script
new file mode 100755
index 00000000..a30bb774
--- /dev/null
+++ b/tests.branching/morph-tag-fails-if-tag-exists.script
@@ -0,0 +1,33 @@
+#!/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 tag example-tag' fails if 'example-tag' already exists.
+
+set -eu
+
+# Make sure the commits always have the same SHA1s.
+source "$SRCDIR/scripts/fix-committer-info"
+
+# Create a workspace and branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout test:morphs master
+
+# Tag the system branch twice.
+"$SRCDIR/scripts/test-morph" tag example-tag -- -m First
+"$SRCDIR/scripts/test-morph" tag example-tag -- -m Second
diff --git a/tests.branching/morph-tag-fails-if-tag-exists.stderr b/tests.branching/morph-tag-fails-if-tag-exists.stderr
new file mode 100644
index 00000000..66c71252
--- /dev/null
+++ b/tests.branching/morph-tag-fails-if-tag-exists.stderr
@@ -0,0 +1,3 @@
+ERROR: Command failed: git tag -a example-tag -m Second 70d7adfe89033309e0494efbe6df3e4a5604e558
+fatal: tag 'example-tag' already exists
+
diff --git a/tests.branching/morph-tag-tag-works-as-expected.script b/tests.branching/morph-tag-tag-works-as-expected.script
new file mode 100755
index 00000000..25ba4a51
--- /dev/null
+++ b/tests.branching/morph-tag-tag-works-as-expected.script
@@ -0,0 +1,46 @@
+#!/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 tagging an existing tag commit with 'morph tag' preserves
+## the unpetrify-ref and does not "double-petrify" apart from updating
+## references to "example-tag" to "tagged-tag".
+
+set -eu
+
+# Make sure the commits always have the same SHA1s.
+source "$SRCDIR/scripts/fix-committer-info"
+
+# Create a workspace and branch.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" checkout test:morphs master
+
+# Tag the system branch.
+"$SRCDIR/scripts/test-morph" tag example-tag -- -m First
+
+# Check out the tag.
+"$SRCDIR/scripts/run-git-in" master/test:morphs checkout -b example-tag \
+ 2>/dev/null
+
+# Tag the tag.
+"$SRCDIR/scripts/test-morph" tag tagged-tag -- -m Second
+
+# List all tags and show the second one.
+"$SRCDIR/scripts/test-morph" foreach -- git tag -l
+"$SRCDIR/scripts/test-morph" foreach -- git show tagged-tag
+"$SRCDIR/scripts/test-morph" foreach -- git log tagged-tag
diff --git a/tests.branching/morph-tag-tag-works-as-expected.stdout b/tests.branching/morph-tag-tag-works-as-expected.stdout
new file mode 100644
index 00000000..58d77714
--- /dev/null
+++ b/tests.branching/morph-tag-tag-works-as-expected.stdout
@@ -0,0 +1,58 @@
+test:morphs
+example-tag
+tagged-tag
+test:morphs
+tag tagged-tag
+Tagger: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+Second
+
+commit f7f04d63ec5e494cf5b4fd2e94ad5f2f26265c3f
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ Second
+
+diff --git a/hello-stratum.morph b/hello-stratum.morph
+index 3b7be17..87561c1 100644
+--- a/hello-stratum.morph
++++ b/hello-stratum.morph
+@@ -5,8 +5,9 @@
+ {
+ "name": "hello",
+ "repo": "test:hello",
+- "ref": "master",
+- "build-depends": []
++ "ref": "f4d032b42c0134e67bdf19a43fa99072493667d7",
++ "build-depends": [],
++ "unpetrify-ref": "master"
+ }
+ ]
+ }
+diff --git a/hello-system.morph b/hello-system.morph
+index f3f64b4..2981e9b 100644
+--- a/hello-system.morph
++++ b/hello-system.morph
+@@ -8,7 +8,8 @@
+ {
+ "morph": "hello-stratum",
+ "repo": "test:morphs",
+- "ref": "master"
++ "ref": "tagged-tag",
++ "unpetrify-ref": "master"
+ }
+ ]
+ }
+test:morphs
+commit f7f04d63ec5e494cf5b4fd2e94ad5f2f26265c3f
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ Second
+
+commit 48d38ef3f39857d7dba4ed1ffc51653c6bed4906
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ initial
diff --git a/tests.branching/morph-tag-works-with-multiple-morphs-repos.script b/tests.branching/morph-tag-works-with-multiple-morphs-repos.script
new file mode 100755
index 00000000..374c9ff5
--- /dev/null
+++ b/tests.branching/morph-tag-works-with-multiple-morphs-repos.script
@@ -0,0 +1,123 @@
+#!/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 tag" works if morphologies are spread across multiple
+## repositories. In this case, it should copy all petrified morphologies
+## into the branch root repository and only create the tag there.
+
+set -eu
+
+# Make sure the commits always have the same SHA1s.
+source "$SRCDIR/scripts/fix-committer-info"
+
+# Create new directory for repos used in this test.
+mkdir -p "$DATADIR/repos"
+
+# Create the first morphs repository.
+mkdir "$DATADIR/repos/morphs1"
+
+# Create system morphology in first morphs repository.
+cat <<EOF > "$DATADIR/repos/morphs1/test-system.morph"
+{
+ "name": "test-system",
+ "kind": "system",
+ "system-kind": "syslinux-disk",
+ "arch": "$(uname -m)",
+ "disk-size": "1G",
+ "strata": [
+ {
+ "morph": "stratum1",
+ "repo": "repos:morphs1",
+ "ref": "master"
+ },
+ {
+ "morph": "stratum2",
+ "repo": "repos:morphs2",
+ "ref": "master"
+ }
+ ]
+}
+EOF
+
+# Create stratum that depends on another stratum.
+cat <<EOF > "$DATADIR/repos/morphs1/stratum1.morph"
+{
+ "name": "stratum1",
+ "kind": "stratum",
+ "build-depends": [
+ {
+ "morph": "stratum3",
+ "repo": "repos:morphs2",
+ "ref": "master"
+ }
+ ]
+}
+EOF
+
+# Commit all files to the first repository.
+scripts/run-git-in "$DATADIR/repos/morphs1" init
+scripts/run-git-in "$DATADIR/repos/morphs1" add .
+scripts/run-git-in "$DATADIR/repos/morphs1" commit -m initial
+
+# Create second morphs repository.
+mkdir "$DATADIR/repos/morphs2"
+
+# Create two strata in the second repository.
+cat <<EOF > "$DATADIR/repos/morphs2/stratum2.morph"
+{
+ "name": "stratum2",
+ "kind": "stratum",
+ "build-depends": [
+ {
+ "morph": "stratum3",
+ "repo": "repos:morphs2",
+ "ref": "master"
+ }
+ ]
+}
+EOF
+cat <<EOF > "$DATADIR/repos/morphs2/stratum3.morph"
+{
+ "name": "stratum3",
+ "kind": "stratum"
+}
+EOF
+
+# Commit all files to the second repository.
+"$SRCDIR/scripts/run-git-in" "$DATADIR/repos/morphs2" init
+"$SRCDIR/scripts/run-git-in" "$DATADIR/repos/morphs2" add .
+"$SRCDIR/scripts/run-git-in" "$DATADIR/repos/morphs2" commit -m initial
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+
+# Check out the master system branch.
+"$SRCDIR/scripts/test-morph" \
+ --repo-alias=repos="file://$DATADIR/repos/%s#file://$DATADIR/%s" \
+ checkout repos:morphs1 master
+
+# Tag the master system branch.
+"$SRCDIR/scripts/test-morph" \
+ --repo-alias=repos="file://$DATADIR/repos/%s#file://$DATADIR/%s" \
+ tag tag-across-multiple-repos -- -m "create tag"
+
+# Show the tag.
+GIT_DIR="$DATADIR/workspace/master/repos:morphs1/.git" \
+ git show tag-across-multiple-repos
+GIT_DIR="$DATADIR/workspace/master/repos:morphs1/.git" \
+ git log -n1 -p --stat tag-across-multiple-repos
diff --git a/tests.branching/morph-tag-works-with-multiple-morphs-repos.stdout b/tests.branching/morph-tag-works-with-multiple-morphs-repos.stdout
new file mode 100644
index 00000000..91b36f99
--- /dev/null
+++ b/tests.branching/morph-tag-works-with-multiple-morphs-repos.stdout
@@ -0,0 +1,172 @@
+Initialized empty Git repository in TMP/repos/morphs1/.git/
+[master (root-commit) 0bfadac] initial
+ 2 files changed, 30 insertions(+), 0 deletions(-)
+ create mode 100644 stratum1.morph
+ create mode 100644 test-system.morph
+Initialized empty Git repository in TMP/repos/morphs2/.git/
+[master (root-commit) 06b1b9c] initial
+ 2 files changed, 15 insertions(+), 0 deletions(-)
+ create mode 100644 stratum2.morph
+ create mode 100644 stratum3.morph
+tag tag-across-multiple-repos
+Tagger: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+create tag
+
+commit 8fe8196c4eb87e5967d7b08eb8da9d7d0764c25d
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ create tag
+
+diff --git a/stratum1.morph b/stratum1.morph
+index 93a2d04..bf622db 100644
+--- a/stratum1.morph
++++ b/stratum1.morph
+@@ -4,8 +4,10 @@
+ "build-depends": [
+ {
+ "morph": "stratum3",
+- "repo": "repos:morphs2",
+- "ref": "master"
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
+ }
+ ]
+ }
+diff --git a/stratum2.morph b/stratum2.morph
+new file mode 100644
+index 0000000..d27599c
+--- /dev/null
++++ b/stratum2.morph
+@@ -0,0 +1,13 @@
++{
++ "name": "stratum2",
++ "kind": "stratum",
++ "build-depends": [
++ {
++ "morph": "stratum3",
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
++ }
++ ]
++}
+diff --git a/stratum3.morph b/stratum3.morph
+new file mode 100644
+index 0000000..a735127
+--- /dev/null
++++ b/stratum3.morph
+@@ -0,0 +1,4 @@
++{
++ "name": "stratum3",
++ "kind": "stratum"
++}
+diff --git a/test-system.morph b/test-system.morph
+index 27806c1..c5e4d98 100644
+--- a/test-system.morph
++++ b/test-system.morph
+@@ -8,12 +8,15 @@
+ {
+ "morph": "stratum1",
+ "repo": "repos:morphs1",
+- "ref": "master"
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master"
+ },
+ {
+ "morph": "stratum2",
+- "repo": "repos:morphs2",
+- "ref": "master"
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
+ }
+ ]
+ }
+commit 8fe8196c4eb87e5967d7b08eb8da9d7d0764c25d
+Author: developer <developer@example.com>
+Date: Tue Jul 31 16:51:54 2012 +0000
+
+ create tag
+---
+ stratum1.morph | 6 ++++--
+ stratum2.morph | 13 +++++++++++++
+ stratum3.morph | 4 ++++
+ test-system.morph | 9 ++++++---
+ 4 files changed, 27 insertions(+), 5 deletions(-)
+
+diff --git a/stratum1.morph b/stratum1.morph
+index 93a2d04..bf622db 100644
+--- a/stratum1.morph
++++ b/stratum1.morph
+@@ -4,8 +4,10 @@
+ "build-depends": [
+ {
+ "morph": "stratum3",
+- "repo": "repos:morphs2",
+- "ref": "master"
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
+ }
+ ]
+ }
+diff --git a/stratum2.morph b/stratum2.morph
+new file mode 100644
+index 0000000..d27599c
+--- /dev/null
++++ b/stratum2.morph
+@@ -0,0 +1,13 @@
++{
++ "name": "stratum2",
++ "kind": "stratum",
++ "build-depends": [
++ {
++ "morph": "stratum3",
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
++ }
++ ]
++}
+diff --git a/stratum3.morph b/stratum3.morph
+new file mode 100644
+index 0000000..a735127
+--- /dev/null
++++ b/stratum3.morph
+@@ -0,0 +1,4 @@
++{
++ "name": "stratum3",
++ "kind": "stratum"
++}
+diff --git a/test-system.morph b/test-system.morph
+index 27806c1..c5e4d98 100644
+--- a/test-system.morph
++++ b/test-system.morph
+@@ -8,12 +8,15 @@
+ {
+ "morph": "stratum1",
+ "repo": "repos:morphs1",
+- "ref": "master"
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master"
+ },
+ {
+ "morph": "stratum2",
+- "repo": "repos:morphs2",
+- "ref": "master"
++ "repo": "repos:morphs1",
++ "ref": "tag-across-multiple-repos",
++ "unpetrify-ref": "master",
++ "unpetrify-repo": "repos:morphs2"
+ }
+ ]
+ }