Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / logerrit
blobbb604734a2538eb7d6b6da2aeabfcecb01595772
1 #!/bin/sh
3 #GERRITHOST=gerrit.libreoffice.org
4 GERRITHOST=logerrit
5 GERRITURL=ssh://$GERRITHOST/core
7 get_SHA_for_change() {
8 SHA=`ssh ${GERRITHOST?} gerrit query --all-approvals change:$1|grep ref|tail -1|cut -d: -f2`
11 get_REVISION_for_change() {
12 REVISION=`ssh ${GERRITHOST?} gerrit query --all-approvals change:$1|grep revision|tail -1|cut -d: -f2`
15 ask_tristate() {
16 case $1 in
17 [yY] | [yY][Ee][Ss] | [+] )
18 ANSWER=y
20 [nN] | [n|N][O|o] | [-] )
21 ANSWER=n
23 [] )
24 ANSWER=
26 * )
27 echo "Please answer with either +,-,y,n,yes,no or the empty string."
28 exit 1
30 esac
34 submit() {
35 BRANCH=$1
36 if test -z "$BRANCH"
37 then
38 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
39 BRANCH="${BRANCH##refs/heads/}"
40 if test -z "$BRANCH"
41 then
42 echo "no branch specified, and could not guess the current branch"
43 exit 1
45 echo "no branch specified, guessing current branch $BRANCH"
47 git push $GERRITURL HEAD:refs/for/$BRANCH
50 case "$1" in
51 help)
52 echo "Usage: ./logerrit subcommand [options]"
53 echo "simple and basic tool to interact with LibreOffice gerrit"
54 echo "subcommands:"
55 echo " test test your gerrit setup"
56 echo " --- for submitters:"
57 echo " submit [BRANCH] submit your change for review"
58 echo " resubmit [BRANCH] create a new Change-Id and submit your change for review"
59 echo " (yes, this modifies your last commit)"
60 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
61 echo " --- for reviewers:"
62 echo " checkout CHANGEID checkout the changes for review"
63 echo " pull CHANGEID pull (and merge) the changes on current branch"
64 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
65 echo " patch CHANGEID show the change as a patch"
66 echo " review [CHANGEID] interactively review a change (current one if no changeid given)"
67 echo " query .... query for changes for review on project core"
68 echo " <any other gerrit command>"
69 echo "advanced users should consider using git review instead:"
70 echo "http://wiki.documentfoundation.org/Development/GitReview"
71 exit
73 test)
74 if test -n "`ssh $GERRITHOST 2>&1|grep \"Welcome to Gerrit Code Review\"`"
75 then
76 echo "Your gerrit setup was successful!"
77 else
78 echo "There seems to be trouble."
79 echo "please have the output of: ssh -vvvv logerrit"
80 echo "at hand when looking for help."
83 submit)
84 submit $2
86 resubmit)
87 git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
88 submit $2
90 nextchange)
91 if test -n "`git status -s -uno`"
92 then
93 echo "You have uncommitted changes. Please commit or stash these:"
94 git status
95 exit 1
97 CHANGEID=`git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ `
98 if test -z "$CHANGEID"
99 then
100 CHANGEID="NOCHANGEID"
102 BACKUPBRANCH=backup/$CHANGEID-`date +%F-%H%M%S`
103 git branch $BACKUPBRANCH
104 echo "current state backed up as $BACKUPBRANCH"
105 BRANCH=$2
106 if test -z "$BRANCH"
107 then
108 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
109 BRANCH="${BRANCH##refs/heads/}"
110 if test -z "$BRANCH"
111 then
112 echo "no branch specified, and could not guess the current branch"
113 exit 1
115 echo "no branch specified, guessing current branch $BRANCH"
117 git reset --hard remotes/origin/$BRANCH
119 review)
120 CHANGEID=$2
121 if test -z "$CHANGEID"
122 then
123 CHANGEID=`git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2`
124 if test -z "$CHANGEID"
125 then
126 echo "could not find a Change-Id in your last commit, sorry"
127 exit 1
129 echo "no Change-Id given on the command line, reviewing change$CHANGEID"
131 MESSAGEREQ=""
132 read -p 'was the change verified to build successfully (+) or found not to build (-) or none of that ()? ' VERIFIED
133 ask_tristate $VERIFIED
134 case "$ANSWER" in
135 "y")
136 VERIFIEDFLAG=--verified=+1
138 "n")
139 VERIFIEDFLAG="--verified=-1"
140 MESSAGEREQ="$MESSAGEREQ and explain why you could not verify this"
143 VERIFIEDFLAG="--verified=0"
146 esac
147 read -p 'is the code looking good (+), bad (-) or none of that ()? ' CODEREVIEW
148 ask_tristate $CODEREVIEW
149 SUBMITFLAG=""
150 case "$ANSWER" in
151 "y")
152 read -p 'do you approve the change (+) too, or prefer someone else to do that ()? ' CODEREVIEW
153 ask_tristate $CODEREVIEW
154 case "$ANSWER" in
155 "y")
156 CODEREVIEWFLAG="--code-review=2"
157 SUBMITFLAG="--submit"
159 "n")
160 CODEREVIEWFLAG="--code-review=1"
163 CODEREVIEWFLAG="--code-review=1"
165 esac
167 "n")
168 read -p 'do you still allow the change to go in () or not (-)? ' CODEREVIEW
169 ask_tristate $CODEREVIEW
170 case "$ANSWER" in
171 "y")
172 CODEREVIEWFLAG="--code-review=-1"
173 MESSAGEREQ="$MESSAGEREQ and explain why you have reservations about the code"
175 "n")
176 CODEREVIEWFLAG="--code-review=-2"
177 MESSAGEREQ="$MESSAGEREQ and explain why you want to block this"
180 CODEREVIEWFLAG="--code-review=-1"
181 MESSAGEREQ="$MESSAGEREQ and explain why you have reservations about the code"
183 esac
187 esac
188 read -p "please type a friendly comment$MESSAGEREQ: " MESSAGE
189 get_REVISION_for_change $CHANGEID
190 ssh ${GERRITHOST?} gerrit review -m \"$MESSAGE\" $VERIFIEDFLAG $CODEREVIEWFLAG $SUBMITFLAG $REVISION
192 checkout)
193 get_SHA_for_change $2
194 git fetch $GERRITURL $SHA && git checkout FETCH_HEAD
196 pull)
197 get_SHA_for_change $2
198 git pull $GERRITURL $SHA
200 cherry-pick)
201 get_SHA_for_change $2
202 git fetch $GERRITURL $SHA && git cherry-pick FETCH_HEAD
204 patch)
205 get_SHA_for_change $2
206 git fetch $GERRITURL $SHA && git format-patch -1 --stdout FETCH_HEAD
208 query)
209 shift
210 ssh ${GERRITHOST?} gerrit query project:core $@
213 ssh ${GERRITHOST?} gerrit $@
215 esac