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,66 @@ +#!/bin/bash + +# This script will sync github.com/llvm/llvm-project with +# github.com/llvm/llvm-project-release-prs and try to merge +# the changes in the release branch. + +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? +RELEASE_BRANCH="${RELEASE_BRANCH:-release/16.x}" + +# We will add two remotes here: +# main - which will point to $MAIN_URL +# release - which will point to $RELEASE_URL +# The remotes will use random strings to avoid +# collisions +MAIN_URL="https://github.com/llvm/llvm-project" +RELEASE_URL="https://github.com/llvm/llvm-project-release-prs" +MAIN_REMOTE=$(uuidgen) +RELEASE_REMOTE=$(uuidgen) + +git remote add $MAIN_REMOTE $MAIN_URL +git remote add $RELEASE_REMOTE $RELEASE_URL + +# Make sure we are up to date on all our repos first +git fetch $MAIN_REMOTE +git fetch $RELEASE_REMOTE + +# Create our sync branch. Starting with the main +# repo first since it's important to get those +# changes +MERGE_BRANCH=$(uuidgen) +git switch -c $MERGE_BRANCH $MAIN_REMOTE/$RELEASE_BRANCH + +# Merge changes from the release repo +git merge --ff-only $RELEASE_REMOTE/$RELEASE_BRANCH + +if ! git diff-index --quiet $RELEASE_REMOTE/$RELEASE_BRANCH; then + echo "Changes in the release remote - pushing to main remote" + git push origin $MERGE_BRANCH:$RELEASE_BRANCH +fi + +# Then we need to update again +git fetch $MAIN_REMOTE +git fetch $RELEASE_REMOTE + +# And merge all the new data to the current branch +git merge --ff-only $MAIN_REMOTE/$RELEASE_BRANCH + +# If anything changed let's merge it +if ! git diff-index --quiet $RELEASE_REMOTE/$RELEASE_BRANCH; then + echo "Changes in upstream - pushing to origin" + git push upstream $MERGE_BRANCH:$RELEASE_BRANCH +fi + +# Cleanup - enable for debug +if false; then + git remote remove $RELEASE_REMOTE + git remote remove $MAIN_REMOTE + + git switch main + git branch -D $MERGE_BRANCH +fi \ No newline at end of file