-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-review-branch
executable file
·51 lines (40 loc) · 1.67 KB
/
git-review-branch
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
#!/bin/sh -e
USAGE=`cat<<EOF
USAGE: git review-branch <branchname> [parent -- defaults to branch.review-parent-default]
Creates a new local branch ensuring that it's not based off master.
This is useful as part of GitHub-style deploys. Such a branch is called
a 'review branch'.
All review branches should be based off a deploy branch.
See git deploy-branch.
If you've run 'git config --add branch.review-parent-default XXX',
then when you run 'git review-branch foo' it will base foo off of
the XXX branch. You can override this behavior via
git review-branch foo other-deploy-branch
See also Git workflow at KA:
https://khanacademy.org/r/git-at-ka
EOF`
[ -n "$1" ] || {
echo "$USAGE"
exit 1
}
# If the second argument is provided, switch to it
if [ -n "$2" ]; then
git co $2
elif [ -n "`git config --get branch.review-parent-default`" ]; then
# If they have a default parent branch, switch to *that*
git co "`git config --get branch.review-parent-default`"
fi
RED='\033[0;31m'
NC='\033[0m' # No Color
# Stop people from landing directly to master
# TODO(benkraft): After ka-clone has been setting kaclone.protect-master
# for a while (2020 should be safe), remove the first half of the || as
# it should be redundant (and it's kinda hacky).
if git remote -v | grep -q Khan/webapp || git config kaclone.protect-master | grep -q true; then
if [ "`git rev-parse --abbrev-ref HEAD`" = "master" ]; then
echo "${RED}FATAL ERROR: Review branches must not be based off master${NC}";
exit 1
fi
fi
# Apart from that check, this command just creates a local branch
git co --track -b $1