diff --git a/llvm/utils/git/sync-release-repo.sh b/llvm/utils/git/sync-release-repo.sh new file mode 100755 --- /dev/null +++ b/llvm/utils/git/sync-release-repo.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# This script is meant to sync the llvm-project-release-prs repo with the +# main repo to make the updating automatic. It's meant to be executed from +# GitHub actions. +# The script should be executed from a repo cloned from release-prs. + +set -e +set -x + +# We should always get the branch from the environment. +# But otherwise just default to something. We can probably +# have a better default here? +BRANCH="${BRANCH:-release/16.x}" +REPO="https://github.com/llvm/llvm-project" + +git config remote.upstream.url >&- || git remote add upstream $REPO + +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +# Make sure we are up to date on all our repos first +git fetch --all + +# Start by resetting to the upstream release branch - this is the most important +# branch always +git switch -c sync-repos upstream/$BRANCH +git merge --ff-only origin/$BRANCH + +if ! git diff-index --quiet origin/$BRANCH; then + echo "Changes in origin - pushing to upstream" + git push origin sync-repos:$BRANCH +fi + +# Then we need to update again +git fetch --all + +# And merge all the new data to the current branch +git merge --ff-only upstream/$BRANCH + +# If anything changed let's merge it +if ! git diff-index --quiet upstream/$BRANCH; then + echo "Changes in upstream - pushing to origin" + git push upstream sync-repos:$BRANCH +fi + +# Done - let's clean up +git switch $CURRENT_BRANCH + +if git diff-index --quiet HEAD; then + git reset --hard @{u} +fi + +git branch -d sync-repos