fbcode_to_main_sync.sh 1.1 KB

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