Blob


1 #!/usr/local/plan9/bin/rc
3 git=git
4 show=false
5 fn gitshow {
6 echo '%' git $*
7 git $*
8 }
9 if(! ~ $#* 0 && ~ $1 -v) {
10 git=gitshow
11 show=true
12 shift
13 }
15 if(~ $#* 0) {
16 echo 'usage: codereview <command> <args>' >[1=2]
17 exit usage
18 }
20 if(~ $#PLAN9 0) {
21 PLAN9=/usr/local/plan9
22 }
23 if(! test -d $PLAN9/lib/git) {
24 echo 'codereview: cannot find $PLAN9/lib/git' >[1=2]
25 exit git
26 }
28 if(! test -e $PLAN9/.git/hooks/commit-msg) {
29 if($show) {
30 echo '% ln -s ../../lib/git/commit-msg.hook $PLAN9/.git/hooks/commit-msg'
31 }
32 ln -s ../../lib/git/commit-msg.hook $PLAN9/.git/hooks/commit-msg
33 }
35 switch($1) {
36 case help
37 9 man 1 codereview
39 case pending
40 shift
41 if(! ~ $#* 0) {
42 echo 'usage: codereview pending' >[1=2]
43 exit usage
44 }
45 $git branch -v
47 case create
48 shift
49 if(~ $#* 0) {
50 echo 'usage: codereview create branchname' >[1=2]
51 exit usage
52 }
53 branch=$1
54 shift
55 if(! git branch -l | 9 grep '\* master$' >/dev/null) {
56 echo 'codereview: create not on master branch; use codereview commit' >[1=2]
57 exit master
58 }
59 if($show) {
60 echo '% git branch '$branch' && git commit || git branch -d '$branch >[1=2]
61 }
62 git branch $branch && git checkout $branch && git commit -a $* || git branch -d $branch
64 case commit
65 shift
66 if(git branch -l | 9 grep '\* master$' >/dev/null) {
67 echo 'codereview: commit on master branch; use codereview create <branchname>' >[1=2]
68 exit master
69 }
70 if(~ `{git merge-base HEAD HEAD} `{git merge-base HEAD master}) {
71 # first commit on branch, somehow.
72 $git commit $*
73 exit $status
74 }
75 $git commit --amend -a $*
76 exit $status
78 case upload
79 if(git branch -l | 9 grep '\* master$' >/dev/null) {
80 echo 'codereview: upload on master branch' >[1=2]
81 exit master
82 }
83 if(~ `{git merge-base HEAD HEAD} `{git merge-base HEAD master}) {
84 # no commit on branch
85 echo 'codereview: no commits yet on this feature branch' >[1=2]
86 exit commit
87 }
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]
90 }
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]
93 git status
94 }
95 $git push https://plan9port-review.googlesource.com/plan9 HEAD:refs/for/master >[2=1] | 9 sed 's/.* //'
97 case sync
98 shift
99 if(! ~ $#* 0) {
100 echo 'usage: codereview sync' >[1=2]
101 exit usage
103 $git fetch -q
105 branch=`{git branch -l | 9 sed -n 's/^\* //p'}
106 if(~ $branch master) {
107 $git merge -q --ff-only origin/master
108 exit $status
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
114 exit $status
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
122 exit $status
125 changeid=`{git log -n 1 | 9 sed -n 's/^ Change-Id: //p'}
126 if(~ $#changeid 0) {
127 echo 'codereview: cannot find change id'
128 exit changeid
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]
137 exit 1
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
144 case *
145 echo 'codereview: unrecognized command '$1 >[1=2]
146 exit usage