From 67c4c8f5df0de55f4668cfe72b2464caf9f834ec Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Wed, 27 Oct 2021 18:09:23 +0100 Subject: [PATCH 1/7] [WIP] Added script to sync fbcode changes with main branch --- scripts/README.rst | 17 +++++++++++++++++ scripts/fbcode_to_main_sync.sh | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 scripts/README.rst create mode 100755 scripts/fbcode_to_main_sync.sh diff --git a/scripts/README.rst b/scripts/README.rst new file mode 100644 index 00000000000..4be7d7d28df --- /dev/null +++ b/scripts/README.rst @@ -0,0 +1,17 @@ +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 of the PR in fbsync branch from where we should start the sync. + +This script will create PRs corresponding to the PRs in fbsync. Please review these, add [FBCode->GH] tag on the title and publish them. Remember to add [FBCode->GH] tag 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..190c710be3a --- /dev/null +++ b/scripts/fbcode_to_main_sync.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ -z $1 ] +then + echo "commit hash is required to be passed when running this script" +fi +git checkout fbsync +commit_hash=$1 +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 master + git checkout -B cherrypick_$hash + git cherry-pick -x "$hash" + git push origin cherrypick_$hash + git checkout fbsync + fi +done +echo "Please review the PRs, add [FBCode->GH] tag on the title and publish them." From 4e98902a3a8015b5596993e5877f0b18d7f88216 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Wed, 27 Oct 2021 21:29:42 +0100 Subject: [PATCH 2/7] Make unique branches for multiple runs of the script --- scripts/fbcode_to_main_sync.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/fbcode_to_main_sync.sh b/scripts/fbcode_to_main_sync.sh index 190c710be3a..129924b93a9 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -4,8 +4,10 @@ if [ -z $1 ] then echo "commit hash is required to be passed when running this script" fi +git stash git checkout fbsync commit_hash=$1 +prefix=$RANDOM IFS=' ' for line in $(git log --pretty=oneline "$commit_hash"..HEAD) @@ -15,9 +17,9 @@ do echo "Parsing $line" hash=$(echo $line | cut -f1 -d' ') git checkout master - git checkout -B cherrypick_$hash + git checkout -B cherrypick_${prefix}_${hash} git cherry-pick -x "$hash" - git push origin cherrypick_$hash + git push origin cherrypick_${prefix}_${hash} git checkout fbsync fi done From e2c84aff291e5d1f3d5c709dece2972dd83fe9bc Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 28 Oct 2021 12:58:29 +0100 Subject: [PATCH 3/7] Updated the files --- scripts/README.rst | 20 ++++++++++++++--- scripts/fbcode_to_main_sync.sh | 40 +++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/scripts/README.rst b/scripts/README.rst index 4be7d7d28df..df8825f08ba 100644 --- a/scripts/README.rst +++ b/scripts/README.rst @@ -10,8 +10,22 @@ To run this script: .. code:: bash chmod +x fbcode_to_main_sync.sh - ./fbcode_to_main_sync.sh + ./fbcode_to_main_sync.sh -where ``commit_hash`` represents the commit hash of the PR in fbsync branch from where we should start the sync. +where -This script will create PRs corresponding to the PRs in fbsync. Please review these, add [FBCode->GH] tag on the title and publish them. Remember to add [FBCode->GH] tag at the beginning of the merge message as well. +``from_repo`` represents the name of the repository from which commits are to be cherry-picked. + +``commit_hash`` represents the commit hash of the PR in fbsync branch from where we should start the sync. + +``fork_main_branch`` is the name of the main branch on your fork. + +``fork_name`` is the name assigned to your fork, you can check it by doing `"git remote -v"`. + +Example: + +.. code:: bash + + ./fbcode_to_main_sync.sh fbsync main origin + +This script will create PRs corresponding to the PRs in your ``from_repo`` (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 index 129924b93a9..9b7e6505626 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -2,11 +2,39 @@ if [ -z $1 ] then - echo "commit hash is required to be passed when running this script" + echo "From repo is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 fi +from_repo=$1 + +if [ -z $2 ] +then + echo "Commit hash is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 +fi +commit_hash=$2 + +if [ -z $3 ] +then + echo "Fork main branch name is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 +fi +fork_main_branch=$3 + +if [ -z $4 ] +then + echo "Fork name is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " + exit 1 +fi +fork_name=$4 + git stash -git checkout fbsync -commit_hash=$1 +git checkout $from_repo +git fetch prefix=$RANDOM IFS=' ' @@ -16,11 +44,11 @@ do then echo "Parsing $line" hash=$(echo $line | cut -f1 -d' ') - git checkout master + git checkout $fork_main_branch git checkout -B cherrypick_${prefix}_${hash} git cherry-pick -x "$hash" - git push origin cherrypick_${prefix}_${hash} - git checkout fbsync + git push $fork_name cherrypick_${prefix}_${hash} + git checkout $from_repo fi done echo "Please review the PRs, add [FBCode->GH] tag on the title and publish them." From c7f783502dc0b9740f342bbd2ad9b82516e5d7d8 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 28 Oct 2021 14:02:58 +0100 Subject: [PATCH 4/7] Change echo message --- scripts/fbcode_to_main_sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fbcode_to_main_sync.sh b/scripts/fbcode_to_main_sync.sh index 9b7e6505626..73db7905a44 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -51,4 +51,4 @@ do git checkout $from_repo fi done -echo "Please review the PRs, add [FBCode->GH] tag on the title and publish them." +echo "Please review the PRs, add [FBCode->GH] prefix in the title and publish them." From d2c96df1cbcfa6550dbab85e268ac955c41ef9e7 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 28 Oct 2021 14:50:30 +0100 Subject: [PATCH 5/7] Addressed review comments --- scripts/README.rst | 4 ++-- scripts/fbcode_to_main_sync.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/README.rst b/scripts/README.rst index df8825f08ba..03a8a31b3d1 100644 --- a/scripts/README.rst +++ b/scripts/README.rst @@ -16,11 +16,11 @@ where ``from_repo`` represents the name of the repository from which commits are to be cherry-picked. -``commit_hash`` represents the commit hash of the PR in fbsync branch from where we should start the sync. +``commit_hash`` represents the commit hash in fbsync branch from where we should start the sync. ``fork_main_branch`` is the name of the main branch on your fork. -``fork_name`` is the name assigned to your fork, you can check it by doing `"git remote -v"`. +``fork_name`` is the name of the remote corresponding to your fork, you can check it by doing `"git remote -v"`. Example: diff --git a/scripts/fbcode_to_main_sync.sh b/scripts/fbcode_to_main_sync.sh index 73db7905a44..ce2abeade36 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -34,7 +34,7 @@ fork_name=$4 git stash git checkout $from_repo -git fetch +git pull prefix=$RANDOM IFS=' ' From d552d1bc471699226eb3500e28364b2a12640117 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 28 Oct 2021 16:44:30 +0100 Subject: [PATCH 6/7] Removed from_repo command line argument --- scripts/README.rst | 12 ++---------- scripts/fbcode_to_main_sync.sh | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/scripts/README.rst b/scripts/README.rst index 03a8a31b3d1..90a82b650ab 100644 --- a/scripts/README.rst +++ b/scripts/README.rst @@ -10,22 +10,14 @@ To run this script: .. code:: bash chmod +x fbcode_to_main_sync.sh - ./fbcode_to_main_sync.sh + ./fbcode_to_main_sync.sh where -``from_repo`` represents the name of the repository from which commits are to be cherry-picked. - ``commit_hash`` represents the commit hash in fbsync branch from where we should start the sync. ``fork_main_branch`` is the name of the main branch on your fork. ``fork_name`` is the name of the remote corresponding to your fork, you can check it by doing `"git remote -v"`. -Example: - -.. code:: bash - - ./fbcode_to_main_sync.sh fbsync main origin - -This script will create PRs corresponding to the PRs in your ``from_repo`` (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. +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 index ce2abeade36..ac76805a3f8 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -1,40 +1,34 @@ #!/bin/bash if [ -z $1 ] -then - echo "From repo is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " - exit 1 -fi -from_repo=$1 - -if [ -z $2 ] then echo "Commit hash is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " + echo "./fbcode_to_main_sync.sh " exit 1 fi -commit_hash=$2 +commit_hash=$1 -if [ -z $3 ] +if [ -z $2 ] then echo "Fork main branch name is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " + echo "./fbcode_to_main_sync.sh " exit 1 fi -fork_main_branch=$3 +fork_main_branch=$2 -if [ -z $4 ] +if [ -z $3 ] then echo "Fork name is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " + echo "./fbcode_to_main_sync.sh " exit 1 fi -fork_name=$4 +fork_name=$3 +from_branch="fbsync" git stash -git checkout $from_repo +git checkout $from_branch git pull +# Add random prefix in the new branch name to keep it unique per run prefix=$RANDOM IFS=' ' @@ -48,7 +42,7 @@ do git checkout -B cherrypick_${prefix}_${hash} git cherry-pick -x "$hash" git push $fork_name cherrypick_${prefix}_${hash} - git checkout $from_repo + git checkout $from_branch fi done echo "Please review the PRs, add [FBCode->GH] prefix in the title and publish them." From 644edd5e5ff4da5f0b87fcd73660e51aba739127 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 28 Oct 2021 17:49:03 +0100 Subject: [PATCH 7/7] Make fork_main_branch optional --- scripts/README.rst | 6 +++--- scripts/fbcode_to_main_sync.sh | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/README.rst b/scripts/README.rst index 90a82b650ab..37cbb43bd58 100644 --- a/scripts/README.rst +++ b/scripts/README.rst @@ -10,14 +10,14 @@ To run this script: .. code:: bash chmod +x fbcode_to_main_sync.sh - ./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_main_branch`` is the name of the main branch on your fork. - ``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 index ac76805a3f8..c08d61690da 100755 --- a/scripts/fbcode_to_main_sync.sh +++ b/scripts/fbcode_to_main_sync.sh @@ -3,26 +3,25 @@ if [ -z $1 ] then echo "Commit hash is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " + echo "./fbcode_to_main_sync.sh " exit 1 fi commit_hash=$1 if [ -z $2 ] then - echo "Fork main branch name is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " + echo "Fork name is required to be passed when running this script." + echo "./fbcode_to_main_sync.sh " exit 1 fi -fork_main_branch=$2 +fork_name=$2 if [ -z $3 ] then - echo "Fork name is required to be passed when running this script." - echo "./fbcode_to_main_sync.sh " - exit 1 + fork_main_branch="main" +else + fork_main_branch=$3 fi -fork_name=$3 from_branch="fbsync" git stash