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