sandbox-git.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. SANDBOX_PUBLIC_THEMES_FOLDER='/home/wpdev/public_html/wp-content/themes/pub';
  3. # Display the status of the repo on sandbox
  4. if [[ $1 == "status" ]]; then
  5. ssh -TA wpcom-sandbox << EOF
  6. cd '$SANDBOX_PUBLIC_THEMES_FOLDER';
  7. git status;
  8. echo
  9. EOF
  10. # Clean the sandbox.
  11. # checkout origin/trunk and ensure it's up-to-date.
  12. # Remove any other changes.
  13. elif [[ $1 == "clean" ]]; then
  14. ssh -TA wpcom-sandbox << EOF
  15. cd '$SANDBOX_PUBLIC_THEMES_FOLDER';
  16. git reset --hard HEAD;
  17. git clean -fd;
  18. git checkout trunk;
  19. git pull;
  20. echo
  21. EOF
  22. # Add the public github as a remote to your sandbox
  23. # This is useful to checkout branches from github directly to your sandbox
  24. elif [[ $1 == "add-github-remote" ]]; then
  25. ssh -TA wpcom-sandbox << EOF
  26. cd '$SANDBOX_PUBLIC_THEMES_FOLDER';
  27. git remote add github git@github.com:Automattic/themes.git
  28. git fetch github
  29. echo
  30. EOF
  31. # Add the sandbox as a remote to your local
  32. # This doesn't seem to actually work right now...
  33. # This allows you to refer to the github as "origin" and your sandbox as "sandbox"
  34. # Note that for this to work your ~/.ssh/config must have
  35. # Host wpcom-sandbox
  36. # User wpdev
  37. # HostName SANDBOXURL.wordpress.com
  38. # ForwardAgent yes
  39. elif [[ $1 == "add-sandbox-remote" ]]; then
  40. git remote add sandbox wpdev@wpcom-sandbox:/home/wpdev/public_html/wp-content/themes/pub/.git
  41. # Switch the sandbox to a given github branch.
  42. # Defaults to current branch if not provided.
  43. elif [[ $1 == "checkout-branch" ]]; then
  44. if [[ -z $2 ]]; then
  45. BRANCH_NAME=$(git symbolic-ref --short HEAD)
  46. else
  47. BRANCH_NAME=$2;
  48. fi
  49. ssh -TA wpcom-sandbox << EOF
  50. cd '$SANDBOX_PUBLIC_THEMES_FOLDER'
  51. git fetch
  52. git checkout github/$BRANCH_NAME
  53. echo
  54. EOF
  55. # First ensure that the local and sandbox are on the same branch.
  56. # Then push whatever has changed in the local branch to the sandbox via rsync.
  57. # This isn't going to work because the public repo (github) and private repo (a8c)
  58. # don't have common ancestry
  59. elif [[ $1 == "push-local-diff" ]]; then
  60. ssh -TA wpcom-sandbox << EOF
  61. echo '#TODO: Everything';
  62. EOF
  63. elif [[ $1 == "push" ]]; then
  64. rsync -av --no-p --no-times --exclude-from='.sandbox-ignore' ./ wpcom-sandbox:$SANDBOX_PUBLIC_THEMES_FOLDER/
  65. elif [[ $1 == "create-diff" ]]; then
  66. #TODO: Do some fancy git stuff to build the commit message
  67. commit_message="Deploy Themes [THEME UMBRELLA PROJECT VERSION] to wpcom
  68. Summary:
  69. This is a test. Please ignore this diff
  70. This should reflect all of the Pull Requests between THIS BRANCH and TRUNK (stating at the point of diversion)
  71. Test Plan: Execute Smoke Test
  72. Reviewers:
  73. Subscribers:
  74. "
  75. ssh -TA wpcom-sandbox << EOF
  76. cd $SANDBOX_PUBLIC_THEMES_FOLDER
  77. git branch -D deploy
  78. git checkout -b deploy
  79. git add --all
  80. git commit -m "$commit_message"
  81. arc diff --create --verbatim
  82. EOF
  83. #TODO: Pull the Phabricator URL from the output above
  84. # Open phabricator URL in my browser
  85. # Add Phabricator URL to the PR I'm working with (as a comment) ???
  86. elif [[ $1 == "checkout-diff" ]]; then
  87. diff_id=$2
  88. ssh -TA wpcom-sandbox << EOF
  89. cd $SANDBOX_PUBLIC_THEMES_FOLDER
  90. arc patch $diff_id
  91. EOF
  92. elif [[ $1 == "deploy-diff" ]]; then
  93. ssh -TA wpcom-sandbox << EOF
  94. cd $SANDBOX_PUBLIC_THEMES_FOLDER
  95. arc land --onto trunk --preview
  96. EOF
  97. # Clone the sandbox here.
  98. # I don't think you would ever actually do this one... if you have this script then you've already cloned the repo from SOMEWHERE.
  99. # It's mostly here as a reference.
  100. elif [[ $1 == "clone" ]]; then
  101. git clone wpdev@wpcom-sandbox:/home/wpdev/public_html/wp-content/themes/pub/.git .
  102. # All Done
  103. fi