diff --git a/scripts/README.rst b/scripts/README.rst new file mode 100644 index 00000000000..37cbb43bd58 --- /dev/null +++ b/scripts/README.rst @@ -0,0 +1,23 @@ +Utility scripts +=============== + +* `fbcode_to_main_sync.sh` + +This shell script is used to synchronise internal changes with the main repository. + +To run this script: + +.. code:: bash + + chmod +x fbcode_to_main_sync.sh + ./fbcode_to_main_sync.sh + +where + +``commit_hash`` represents the commit hash in fbsync branch from where we should start the sync. + +``fork_name`` is the name of the remote corresponding to your fork, you can check it by doing `"git remote -v"`. + +``fork_main_branch`` (optional) is the name of the main branch on your fork(default="main"). + +This script will create PRs corresponding to the commits in fbsync. Please review these, add the [FBCode->GH] prefix on the title and publish them. Most importantly, add the [FBCode->GH] prefix at the beginning of the merge message as well. diff --git a/scripts/fbcode_to_main_sync.sh b/scripts/fbcode_to_main_sync.sh new file mode 100755 index 00000000000..c08d61690da --- /dev/null +++ b/scripts/fbcode_to_main_sync.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +if [ -z $1 ] +then + echo "Commit hash is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 +fi +commit_hash=$1 + +if [ -z $2 ] +then + echo "Fork name is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 +fi +fork_name=$2 + +if [ -z $3 ] +then + fork_main_branch="main" +else + fork_main_branch=$3 +fi + +from_branch="fbsync" +git stash +git checkout $from_branch +git pull +# Add random prefix in the new branch name to keep it unique per run +prefix=$RANDOM +IFS=' +' +for line in $(git log --pretty=oneline "$commit_hash"..HEAD) +do + if [[ $line != *\[fbsync\]* ]] + then + echo "Parsing $line" + hash=$(echo $line | cut -f1 -d' ') + git checkout $fork_main_branch + git checkout -B cherrypick_${prefix}_${hash} + git cherry-pick -x "$hash" + git push $fork_name cherrypick_${prefix}_${hash} + git checkout $from_branch + fi +done +echo "Please review the PRs, add [FBCode->GH] prefix in the title and publish them."