Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active July 30, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhensby/85287c631edf139148ecc331902c1c81 to your computer and use it in GitHub Desktop.
Save dhensby/85287c631edf139148ecc331902c1c81 to your computer and use it in GitHub Desktop.
Merge up core SS modules
#!/usr/bin/env bash
LEGACY_CORE=('cms' 'reports' 'siteconfig' 'framework' 'installer')
LEGACY_BRANCHES=('4.2.0' '4.2' '4' 'master')
RECIPES=('recipe-cms' 'recipe-core')
RECIPE_BRANCHES=('4.2.0' '4.2' '4' 'master');
NEW_CORE=('assets' 'admin' 'asset-admin' 'campaign-admin' 'errorpage' 'versioned')
NEW_BRANCHES=('1.2.0' '1.2' '1' 'master')
GRAPHQL=('graphql')
GRAPHQL_BRANCHES=('2.0.0' '2.0' '2' 'master')
CONFIG=('config')
CONFIG_BRANCHES=('1.0.5' '1.0' '1.1' '1' 'master')
ALLOWED_MODULES=()
function skipmodule() {
if [ "${#ALLOWED_MODULES[@]}" -eq 0 ]; then
return 1;
else
for module in "${ALLOWED_MODULES[@]}"; do
if [[ "${module}" == "$1" ]]; then
return 1;
fi
done
fi
return 0
}
function usage() {
echo "$1 [modules] [--help]"
echo "Where modules is a list of modules to mergeup eg:"
echo "$1 config cms framework"
}
for arg in "$@"; do
if [[ ! "${arg}" =~ ^- ]]; then
ALLOWED_MODULES+=("${arg}")
elif [[ "${arg}" == '--help' ]]; then
usage "$0"
read -p "Continue"
exit
fi
done
for i in "${LEGACY_CORE[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Merging up $i"
FROM_BRANCH=''
if [ ! -d "$i" ]; then
echo "Checking out $i"
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
if [ $? -ne 0 ]; then
echo "Unable to clone, skipping"
if [ -d "./$i" ]; then
rm -rf "./$i"
fi
continue
fi
else
echo "Repo $i exists"
fi;
echo "Navigating to $i"
cd "$i"
pwd
echo "Fetch remotes"
git fetch --all --tags --prune
for b in "${LEGACY_BRANCHES[@]}"; do
echo "Looking for branch $b"
git rev-parse --quiet --verify "$b"
if [ $? -ne 0 ]; then
echo "Branch $b doesn't exist, creating it"
git checkout -b "$b" "origin/$b"
else
echo "Branch $b exists, resetting it"
git checkout "$b"
git checkout -- .
git clean -f -d
git reset --hard "origin/$b"
fi
if [ -n "$FROM_BRANCH" ]; then
echo "Merging up $FROM_BRANCH"
git merge --no-edit "$FROM_BRANCH"
if [ $? -ne 0 ]; then
read -p "Resolve merge then press enter to continue"
git commmit --no-edit
else
echo "Merge successful"
fi
fi
echo "Pushing to origin"
git push -u origin "$b"
FROM_BRANCH="$b"
done
cd ..
done
for i in "${RECIPES[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Merging up $i"
FROM_BRANCH=''
if [ ! -d "$i" ]; then
echo "Checking out $i"
git clone "https://github.com/silverstripe/$i" "$i"
if [ $? -ne 0 ]; then
echo "Unable to clone, skipping"
if [ -d "./$i" ]; then
rm -rf "./$i"
fi
continue
fi
else
echo "Repo $i exists"
fi;
echo "Navigating to $i"
cd "$i"
pwd
echo "Fetch remotes"
git fetch --all --tags --prune
for b in "${RECIPE_BRANCHES[@]}"; do
echo "Looking for branch $b"
git rev-parse --quiet --verify "$b"
if [ $? -ne 0 ]; then
echo "Branch $b doesn't exist, creating it"
git checkout -b "$b" "origin/$b"
else
echo "Branch $b exists, resetting it"
git checkout "$b"
git checkout -- .
git clean -f -d
git reset --hard "origin/$b"
fi
if [ -n "$FROM_BRANCH" ]; then
echo "Merging up $FROM_BRANCH"
git merge --no-edit "$FROM_BRANCH"
if [ $? -ne 0 ]; then
echo "$i - $b"
read -p "Resolve merge then press enter to continue"
git commmit --no-edit
else
echo "Merge successful"
fi
fi
echo "Pushing to origin"
git push -u origin "$b"
FROM_BRANCH="$b"
done
cd ..
done
for i in "${NEW_CORE[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Merging up $i"
FROM_BRANCH=''
if [ ! -d "$i" ]; then
echo "Checking out $i"
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
if [ $? -ne 0 ]; then
echo "Unable to clone, skipping"
if [ -d "./$i" ]; then
rm -rf "./$i"
fi
continue
fi
else
echo "Repo $i exists"
fi;
echo "Navigating to $i"
cd "$i"
pwd
echo "Fetch remotes"
git fetch --all --tags --prune
for b in "${NEW_BRANCHES[@]}"; do
echo "Looking for branch $b"
git rev-parse --quiet --verify "$b"
if [ $? -ne 0 ]; then
echo "Branch $b doesn't exist, creating it"
git checkout -b "$b" "origin/$b"
else
echo "Branch $b exists, resetting it"
git checkout "$b"
git checkout -- .
git clean -f -d
git reset --hard "origin/$b"
fi
if [ -n "$FROM_BRANCH" ]; then
echo "Merging up $FROM_BRANCH"
git merge --no-edit "$FROM_BRANCH"
if [ $? -ne 0 ]; then
echo "$i - $b"
read -p "Resolve merge then press enter to continue"
git commmit --no-edit
else
echo "Merge successful"
fi
fi
echo "Pushing to origin"
git push -u origin "$b"
FROM_BRANCH="$b"
done
cd ..
done
for i in "${GRAPHQL[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Merging up $i"
FROM_BRANCH=''
if [ ! -d "$i" ]; then
echo "Checking out $i"
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
if [ $? -ne 0 ]; then
echo "Unable to clone, skipping"
if [ -d "./$i" ]; then
rm -rf "./$i"
fi
continue
fi
else
echo "Repo $i exists"
fi;
echo "Navigating to $i"
cd "$i"
pwd
echo "Fetch remotes"
git fetch --all --tags --prune
for b in "${GRAPHQL_BRANCHES[@]}"; do
echo "Looking for branch $b"
git rev-parse --quiet --verify "$b"
if [ $? -ne 0 ]; then
echo "Branch $b doesn't exist, creating it"
git checkout -b "$b" "origin/$b"
else
echo "Branch $b exists, resetting it"
git checkout "$b"
git checkout -- .
git clean -f -d
git reset --hard "origin/$b"
fi
if [ -n "$FROM_BRANCH" ]; then
echo "Merging up $FROM_BRANCH"
git merge --no-edit "$FROM_BRANCH"
if [ $? -ne 0 ]; then
echo "$i - $b"
read -p "Resolve merge then press enter to continue"
git commmit --no-edit
else
echo "Merge successful"
fi
fi
echo "Pushing to origin"
git push -u origin "$b"
FROM_BRANCH="$b"
done
cd ..
done
for i in "${CONFIG[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Merging up $i"
FROM_BRANCH=''
if [ ! -d "$i" ]; then
echo "Checking out $i"
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
if [ $? -ne 0 ]; then
echo "Unable to clone, skipping"
if [ -d "./$i" ]; then
rm -rf "./$i"
fi
continue
fi
else
echo "Repo $i exists"
fi;
echo "Navigating to $i"
cd "$i"
pwd
echo "Fetch remotes"
git fetch --all --tags --prune
for b in "${CONFIG_BRANCHES[@]}"; do
echo "Looking for branch $b"
git rev-parse --quiet --verify "$b"
if [ $? -ne 0 ]; then
echo "Branch $b doesn't exist, creating it"
git checkout -b "$b" "origin/$b"
else
echo "Branch $b exists, resetting it"
git checkout "$b"
git checkout -- .
git clean -f -d
git reset --hard "origin/$b"
fi
if [ -n "$FROM_BRANCH" ]; then
echo "Merging up $FROM_BRANCH"
git merge --no-edit "$FROM_BRANCH"
if [ $? -ne 0 ]; then
echo "$i - $b"
read -p "Resolve merge then press enter to continue"
git commit --no-edit
else
echo "Merge successful"
fi
fi
echo "Pushing to origin"
git push -u origin "$b"
FROM_BRANCH="$b"
done
cd ..
done
read -p "Press enter to quit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment