summaryrefslogtreecommitdiff
path: root/tests.branching/workflow-separate-stratum-repos.script
blob: 06c4f3b859170866bf0c4b8befb5a13d20e98ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/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.


# Do a complete workflow test, with strata outside the main morphologies
# repository.


set -eu


create_chunk() {
    REPO="$1"
    NAME="$2"

    mkdir "$1"
    ln -s "$1" "$1.git"
    cd "$1"

    cat <<EOF > "$1/$2.morph"
{
    "name": "$2",
    "kind": "chunk",
    "build-system": "dummy"
}
EOF

    git init --quiet
    git add  .
    git commit --quiet -m "Initial commit"
}

write_stratum_morph() {
    REPO="$1"
    NAME="$2"

cat <<EOF > "$1/$2.morph"
{
    "name": "$2",
    "kind": "stratum",
    "chunks": [
        {
            "name": "hello",
            "repo": "baserock:$2-hello",
            "ref": "master",
            "build-depends": []
        }
    ]
}
EOF
}

# Create two more strata outside the baserock:morphs repository

EXTERNAL_STRATA_REPO="$DATADIR/external-strata"
mkdir "$EXTERNAL_STRATA_REPO"
ln -s "$EXTERNAL_STRATA_REPO" "$EXTERNAL_STRATA_REPO".git
cd "$EXTERNAL_STRATA_REPO"

git init --quiet .

write_stratum_morph "$EXTERNAL_STRATA_REPO" "stratum2"
write_stratum_morph "$EXTERNAL_STRATA_REPO" "stratum3"

git add .
git commit --quiet -m "Initial commit"

# To make life harder, both chunks have the same name too

create_chunk "$DATADIR/stratum2-hello" "hello"
create_chunk "$DATADIR/stratum3-hello" "hello"

# Update hello-system to include them ... using a system branch! Since the
# strata refs are 'master' not 'me/add-external-strata' this does not cause
# problems with merging.

cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
"$SRCDIR/scripts/test-morph" branch baserock:morphs me/add-external-strata

cd "$DATADIR/workspace/me/add-external-strata/baserock:morphs"

cat <<EOF > "hello-system.morph"
{
    "name": "hello-system",
    "kind": "system",
    "system-kind": "syslinux-disk",
    "arch": "x86_64",
    "disk-size": "1G",
    "strata": [
        {
            "morph": "hello-stratum",
            "repo": "baserock:morphs",
            "ref": "master"
        },
        {
            "morph": "stratum2",
            "repo": "baserock:external-strata",
            "ref": "master"
        },
        {
            "morph": "stratum3",
            "repo": "baserock:external-strata",
            "ref": "master"
        }
    ]
}
EOF
git commit --quiet --all -m "Add two more external strata"

# Merge to master
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
cd master/baserock:morphs
"$SRCDIR/scripts/test-morph" merge me/add-external-strata

# In reality the user would do: 'git push origin master' here,
# but since our remote repo is non-bare we must cheat a bit.
# We should consider a separate fixture for the workflow tests.
cd "$DATADIR/morphs"
git pull -q \
    "file://$DATADIR/workspace/master/baserock:morphs" master

# Now make another change to the system
# FIXME: we should try and build it, too
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" branch baserock:morphs me/readme-fixes

# Edit one chunk
cd "me/readme-fixes"
"$SRCDIR/scripts/test-morph" edit hello-system stratum2 hello
cd "$DATADIR/workspace/me/readme-fixes/baserock:stratum2-hello"
echo > README yoyoyo
git add README
git commit -m "Fix README in hello" --quiet

# Edit the other chunk too
"$SRCDIR/scripts/test-morph" edit hello-system stratum3 hello
cd "$DATADIR/workspace/me/readme-fixes/baserock:stratum3-hello"
echo > README yoyoyo
git add README
git commit -m "Fix README in hello" --quiet

# Update the morphology repos
cd ../baserock:external-strata
git commit --quiet --all -m "Commit changes for system branch"

cd ../baserock:morphs
git commit --quiet --all -m "Commit changes for system branch"

# Merge our system branch into master
cd "$DATADIR/workspace"
cd master
"$SRCDIR/scripts/test-morph" merge me/readme-fixes

# Check the changes have appeared
cd baserock:morphs
[ $(git rev-parse HEAD) = $(git rev-parse master) ]

cd ../baserock:stratum2-hello
[ -e README ]
[ $(git rev-parse HEAD) = $(git rev-parse master) ]

cd ../baserock:stratum3-hello
[ -e README ]
[ $(git rev-parse HEAD) = $(git rev-parse master) ]