Skip to content

Commit 79b350e

Browse files
authored
Added script to sync fbcode changes with main branch (#4769)
* [WIP] Added script to sync fbcode changes with main branch * Make unique branches for multiple runs of the script * Updated the files * Change echo message * Addressed review comments * Removed from_repo command line argument * Make fork_main_branch optional
1 parent c786d12 commit 79b350e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

scripts/README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Utility scripts
2+
===============
3+
4+
* `fbcode_to_main_sync.sh`
5+
6+
This shell script is used to synchronise internal changes with the main repository.
7+
8+
To run this script:
9+
10+
.. code:: bash
11+
12+
chmod +x fbcode_to_main_sync.sh
13+
./fbcode_to_main_sync.sh <commit_hash> <fork_name> <fork_main_branch>
14+
15+
where
16+
17+
``commit_hash`` represents the commit hash in fbsync branch from where we should start the sync.
18+
19+
``fork_name`` is the name of the remote corresponding to your fork, you can check it by doing `"git remote -v"`.
20+
21+
``fork_main_branch`` (optional) is the name of the main branch on your fork(default="main").
22+
23+
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.

scripts/fbcode_to_main_sync.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
if [ -z $1 ]
4+
then
5+
echo "Commit hash is required to be passed when running this script."
6+
echo "./fbcode_to_main_sync.sh <commit_hash> <fork_name> <fork_main_branch>"
7+
exit 1
8+
fi
9+
commit_hash=$1
10+
11+
if [ -z $2 ]
12+
then
13+
echo "Fork name is required to be passed when running this script."
14+
echo "./fbcode_to_main_sync.sh <commit_hash> <fork_name> <fork_main_branch>"
15+
exit 1
16+
fi
17+
fork_name=$2
18+
19+
if [ -z $3 ]
20+
then
21+
fork_main_branch="main"
22+
else
23+
fork_main_branch=$3
24+
fi
25+
26+
from_branch="fbsync"
27+
git stash
28+
git checkout $from_branch
29+
git pull
30+
# Add random prefix in the new branch name to keep it unique per run
31+
prefix=$RANDOM
32+
IFS='
33+
'
34+
for line in $(git log --pretty=oneline "$commit_hash"..HEAD)
35+
do
36+
if [[ $line != *\[fbsync\]* ]]
37+
then
38+
echo "Parsing $line"
39+
hash=$(echo $line | cut -f1 -d' ')
40+
git checkout $fork_main_branch
41+
git checkout -B cherrypick_${prefix}_${hash}
42+
git cherry-pick -x "$hash"
43+
git push $fork_name cherrypick_${prefix}_${hash}
44+
git checkout $from_branch
45+
fi
46+
done
47+
echo "Please review the PRs, add [FBCode->GH] prefix in the title and publish them."

0 commit comments

Comments
 (0)