tdf#69640: Treat errors opening OLE stream gracefully
[LibreOffice.git] / logerrit
bloba88c56f383d7938a54b65efae3cfde6f9e210ae8
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 submit() {
12 TYPE=$1
13 BRANCH=$2
14 if test -z "$BRANCH"
15 then
16 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
17 BRANCH="${BRANCH##refs/heads/}"
18 if test -z "$BRANCH"
19 then
20 echo "no branch specified, and could not guess the current branch"
21 exit 1
23 echo "no branch specified, guessing current branch $BRANCH"
25 git push $GERRITURL HEAD:refs/$TYPE/$BRANCH
28 logerrit() {
29 echo "Host logerrit gerrit.libreoffice.org"
30 echo " IdentityFile ~/.ssh/id_rsa"
31 echo " User $1"
32 echo " Port 29418"
33 echo " HostName gerrit.libreoffice.org"
36 case "$1" in
37 help|--help|"")
38 echo "Usage: ./logerrit subcommand [options]"
39 echo "simple and basic tool to interact with LibreOffice gerrit"
40 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
41 echo
42 echo "subcommands:"
43 echo " setup walking you though your gerrit setup"
44 echo " test test your gerrit setup"
45 echo
46 echo " --- for submitters:"
47 echo " submit [BRANCH] submit your change for review"
48 echo " resubmit [BRANCH] create a new Change-Id and submit your change for review"
49 echo " (yes, this modifies your last commit)"
50 echo " submit-draft [BRANCH] submit your change as draft"
51 echo " resubmit-draft [BRANCH] create a new Change-Id and submit your change as draft"
52 echo " (yes, this modifies your last commit)"
53 echo " (yes, this modifies your last commit)"
54 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
55 echo " testfeature [BRANCH] trigger a test of a feature branch on gerrit"
56 echo "Note: drafts are only visibly to yourself and those that you explicitly add as reviewers."
57 echo
58 echo " --- for reviewers:"
59 echo " checkout CHANGEID checkout the changes for review"
60 echo " pull CHANGEID pull (and merge) the changes on current branch"
61 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
62 echo " patch CHANGEID show the change as a patch"
63 echo " query .... query for changes for review on project core"
64 echo " <any other gerrit command>"
65 echo
66 echo "advanced users should consider using git review instead:"
67 echo "http://wiki.documentfoundation.org/Development/GitReview"
68 exit
70 setup)
71 cd $(dirname $(readlink -f $0))
72 ssh_home="$HOME/.ssh";
73 ssh_key=
74 created_ssh=
75 if ! test -d $ssh_home; then
76 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
77 mkdir $ssh_home
78 chmod 0700 $ssh_home
79 created_ssh=TRUE
80 echo
81 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
82 echo
83 read
84 ssh-keygen -t rsa -f "$ssh_home/id_rsa"
86 if test -d $ssh_home; then
87 if test -f "$ssh_home/id_rsa.pub"; then
88 ssh_key=`cat $ssh_home/id_rsa.pub`;
89 elif test -f "$ssh_home/id_dsa.pub"; then
90 ssh_key=`cat $ssh_home/id_dsa.pub`;
93 echo "Please go to https://gerrit.libreoffice.org/ and:"
94 echo "- press the 'register' button in the top right corner"
95 echo "- after login set yourself a username (its recommended to use your IRC-nick)"
96 if test "z$ssh_key" = "z"; then
97 echo "- add your public ssh-key into the ssh keys settings."
98 else
99 echo "- paste the key below into the 'Add SSH Public Key' box."
100 echo
101 echo "$ssh_key"
102 echo
104 echo
105 echo "Note that you need to register additional email addresses, if you want to"
106 echo "commit from them. Additional emails must be confirmed with repling to the"
107 echo "invitation mail it sends you."
108 echo
109 read -p 'Which user name did you choose? ' GERRITUSER
110 if test "z$created_ssh" = "z"; then
111 echo
112 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
113 echo
114 logerrit $GERRITUSER
115 echo
116 else
117 echo "Automatically creating your ssh config"
118 (logerrit $GERRITUSER) > "$ssh_home/config"
120 # setup the remote properly ...
121 git config remote.origin.pushurl ssh://logerrit/core
122 echo "To see if your setup was successful, run './logerrit test' then."
123 # a good place to make sure the hooks are set up
124 ./g -z
126 test)
127 if test -n "`ssh $GERRITHOST 2>&1|grep \"Welcome to Gerrit Code Review\"`"
128 then
129 echo "Your gerrit setup was successful!"
130 else
131 echo "There seems to be trouble."
132 echo "please have the output of: ssh -vvvv logerrit"
133 echo "at hand when looking for help."
136 submit)
137 submit 'for' $2
139 resubmit)
140 git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
141 submit 'for' $2
143 submit-draft)
144 submit drafts $2
146 resubmit-draft)
147 git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
148 submit drafts $2
150 nextchange)
151 if test -n "`git status -s -uno`"
152 then
153 echo "You have uncommitted changes. Please commit or stash these:"
154 git status
155 exit 1
157 CHANGEID=`git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ `
158 if test -z "$CHANGEID"
159 then
160 CHANGEID="NOCHANGEID"
162 BACKUPBRANCH=backup/$CHANGEID-`date +%F-%H%M%S`
163 git branch $BACKUPBRANCH
164 echo "current state backed up as $BACKUPBRANCH"
165 BRANCH=$2
166 if test -z "$BRANCH"
167 then
168 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
169 BRANCH="${BRANCH##refs/heads/}"
170 if test -z "$BRANCH"
171 then
172 echo "no branch specified, and could not guess the current branch"
173 exit 1
175 echo "no branch specified, guessing current branch $BRANCH"
177 git reset --hard remotes/origin/$BRANCH
179 checkout)
180 get_SHA_for_change $2
181 git fetch $GERRITURL $SHA && git checkout FETCH_HEAD
183 review)
184 echo "'./logerrit review' has be removed as obsolete."
185 echo "Please use either:"
186 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
187 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
188 echo "Both provide a better experience."
189 exit 1;
191 pull)
192 get_SHA_for_change $2
193 git pull $GERRITURL $SHA
195 cherry-pick)
196 get_SHA_for_change $2
197 git fetch $GERRITURL $SHA && git cherry-pick FETCH_HEAD
199 patch)
200 get_SHA_for_change $2
201 git fetch $GERRITURL $SHA && git format-patch -1 --stdout FETCH_HEAD
203 query)
204 shift
205 ssh ${GERRITHOST?} gerrit query project:core $@
207 testfeature)
208 BRANCH=$2
209 if test -z "$BRANCH"
210 then
211 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
212 BRANCH="${BRANCH##refs/heads/}"
213 if test -z "$BRANCH"
214 then
215 echo "no branch specified, and could not guess the current branch"
216 exit 1
218 echo "no branch specified, guessing current branch $BRANCH"
220 BRANCH="${BRANCH##feature/}"
221 WORKDIR=`mktemp -d`
222 if test -z "$WORKDIR"
223 then
224 echo "could no create work directory."
225 exit 1
227 echo workdir at $WORKDIR
228 git clone -s `dirname $0` $WORKDIR/core
229 pushd $WORKDIR/core
230 echo "noop commit: trigger test build for branch feature/$BRANCH" > ../commitmsg
231 echo >> ../commitmsg
232 echo "branch is at:" >> ../commitmsg
233 git log -1|sed -e "s/Change-Id:/XXXXXX:/" >> ../commitmsg
234 git fetch git://gerrit.libreoffice.org/core.git feature/$BRANCH && \
235 git checkout -b featuretst FETCH_HEAD && \
236 cp -a .git-hooks/* .git/hooks
237 git commit --allow-empty -F ../commitmsg && \
238 git push $GERRITURL HEAD:refs/for/feature/$BRANCH
239 popd
240 rm -rf $WORKDIR/core
243 ssh ${GERRITHOST?} gerrit $@
245 esac