1 #!/usr/local/plan9/bin/rc
9 if(! ~ $#* 0 && ~ $1 -v) {
16 echo 'usage: codereview <command> <args>' >[1=2]
21 PLAN9=/usr/local/plan9
23 if(! test -d $PLAN9/lib/git) {
24 echo 'codereview: cannot find $PLAN9/lib/git' >[1=2]
28 if(! test -e $PLAN9/.git/hooks/commit-msg) {
30 echo '% ln -s ../../lib/git/commit-msg.hook $PLAN9/.git/hooks/commit-msg'
32 ln -s ../../lib/git/commit-msg.hook $PLAN9/.git/hooks/commit-msg
42 echo 'usage: codereview pending' >[1=2]
50 echo 'usage: codereview create branchname' >[1=2]
55 if(! git branch -l | 9 grep '\* master$' >/dev/null) {
56 echo 'codereview: create not on master branch; use codereview commit' >[1=2]
60 echo '% git branch '$branch' && git commit || git branch -d '$branch >[1=2]
62 git branch $branch && git checkout $branch && git commit -a $* || git branch -d $branch
66 if(git branch -l | 9 grep '\* master$' >/dev/null) {
67 echo 'codereview: commit on master branch; use codereview create <branchname>' >[1=2]
70 if(~ `{git merge-base HEAD HEAD} `{git merge-base HEAD master}) {
71 # first commit on branch, somehow.
75 $git commit --amend -a $*
79 if(git branch -l | 9 grep '\* master$' >/dev/null) {
80 echo 'codereview: upload on master branch' >[1=2]
83 if(~ `{git merge-base HEAD HEAD} `{git merge-base HEAD master}) {
85 echo 'codereview: no commits yet on this feature branch' >[1=2]
88 if(! 9 grep 'machine plan9port-review.googlesource.com' $HOME/.netrc >/dev/null >[2=1]) {
89 echo 'codereview: warning: cannot find plan9port-review in netrc' >[1=2]
91 if(! git status | 9 grep 'nothing to commit, working directory clean' >/dev/null) {
92 echo 'codereview: warning: local changes not yet committed' >[1=2]
95 $git push https://plan9port-review.googlesource.com/plan9 HEAD:refs/for/master >[2=1] | 9 sed 's/.*
//'
100 echo 'usage: codereview sync' >[1=2]
105 branch=`{git branch -l | 9 sed -n 's/^\* //p'}
106 if(~ $branch master) {
107 $git merge -q --ff-only origin/master
111 if(~ `{git merge-base HEAD HEAD} `{git merge-base HEAD master}) {
112 # no commit on branch
113 git merge -q --ff-only origin/master
117 # Exactly this commit in master. Fast-forward from master and delete this branch.
118 if(git branch -r --contains HEAD | 9 grep '^ *origin/master$' >/dev/null) {
119 $git checkout -q master
120 $git merge -q --ff-only origin/master
121 $git branch -q -d $branch
125 changeid=`{git log -n 1 | 9 sed -n 's/^ Change-Id: //p'}
127 echo 'codereview: cannot find change id'
131 if(git log --grep 'Change-Id: '$changeid origin/master | 9 grep . >/dev/null) {
132 # Something like this got submitted.
133 $git checkout -q master
134 $git merge -q --ff-only origin/master
135 echo 'Change submitted but perhaps not identical to your copy.' >[1=2]
136 echo 'To remove old copy:' git branch -d $branch >[1=2]
140 if(git branch -r --contains master | 9 grep '^ *origin/master$' >/dev/null)
141 $git branch -f master origin/master
142 $git rebase -q origin/master
145 echo 'codereview: unrecognized command '$1 >[1=2]