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
|
#!/bin/bash
set -ex
# Make a directory to work in:
{
ROOT=${BASH_SOURCE%.sh}
[ -n "$ROOT" ] || exit 1
rm -fr "$ROOT"
mkdir "$ROOT"
}
(
cd "$ROOT"
# Create "bare" repos to act as pushable upstreams
git init --bare parent-upstream
git init --bare child-upstream
# Clone the upstreams into local repos
git clone parent-upstream parent
git clone child-upstream child
(
cd parent
echo 'Initial parent commit' > parent.txt
git add parent.txt
git commit -m 'initial parent commit'
git push
)
(
cd child
echo 'Initial child commit' > child.txt
git add child.txt
git commit -m 'Initial child commit'
git push
)
(
cd parent
git subrepo clone ../child-upstream childrepo
)
(
cd child
echo 'Commit from child' >> child.txt
git commit -a -m 'commit from child'
git push
)
(
cd parent
git subrepo pull childrepo
)
(
cd parent
echo 'Commit from parent for pushing' >> childrepo/child.txt
echo 'Commit from parent for pushing' >> parent.txt
git commit -a -m 'Commit from parent for pushing'
git push
)
(
cd parent
git subrepo push childrepo -d || bash -i
)
)
|