nss: makefile bitrot: no need for android spcial case anymore
[LibreOffice.git] / logerrit
blob1d75904578e1c4f0521db2378ba820846988364a
1 #!/bin/bash
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 | sed 's/^ *//')
11 submit() {
12 BRANCH=$1
13 TYPE=${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/for/$BRANCH$TYPE"
28 logerrit() {
29 echo "Host logerrit gerrit.libreoffice.org"
30 if test -n "${2-}" && test -f "$HOME/.ssh/id_$2"; then
31 echo " IdentityFile ~/.ssh/id_$2"
33 echo " User $1"
34 echo " Port 29418"
35 echo " HostName gerrit.libreoffice.org"
38 case "$1" in
39 help|--help|"")
40 echo "Usage: ./logerrit subcommand [options]"
41 echo "simple and basic tool to interact with LibreOffice gerrit"
42 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
43 echo
44 echo "subcommands:"
45 echo " setup walking you though your gerrit setup"
46 echo " test test your gerrit setup"
47 echo
48 echo " --- for submitters:"
49 echo " submit [BRANCH] submit your change for review"
50 echo " submit-private [BRANCH] submit your change as private"
51 echo " submit-wip [BRANCH] submit your change as work-in-progress"
52 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
53 echo " testfeature [BRANCH] [CHANGEID]"
54 echo " trigger a test of a feature branch on gerrit"
55 echo
56 echo "Note: private changes are only visibly to yourself and those that you explicitly add as reviewers."
57 echo "For full documentation, see https://gerrit.libreoffice.org/Documentation/intro-user.html#private-changes"
58 echo
59 echo " --- for reviewers:"
60 echo " checkout CHANGEID checkout the changes for review"
61 echo " pull CHANGEID pull (and merge) the changes on current branch"
62 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
63 echo " patch CHANGEID show the change as a patch"
64 echo " query ... query for changes for review on project core"
65 echo " <any other gerrit command>"
66 echo
67 echo "advanced users should consider using git review instead:"
68 echo "https://wiki.documentfoundation.org/Development/GitReview"
69 exit
71 setup)
72 script_canonical_file=$(readlink -f "$0")
73 script_canonical_dir=$(dirname "$script_canonical_file")
74 if ! cd "$script_canonical_dir"; then
75 echo "Can't cd to $script_canonical_dir"
76 exit 1
78 ssh_home="$HOME/.ssh";
79 ssh_key=
80 created_ssh=
81 if ! test -d "$ssh_home"; then
82 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
83 mkdir -m0700 "$ssh_home"
84 created_ssh=TRUE
85 echo
86 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
87 echo
88 read -r
89 ssh-keygen -t rsa -f "$ssh_home/id_rsa" # default type as of OpenSSH 8.1
91 if test -d "$ssh_home"; then
92 # order algos based on the PubkeyAcceptedKeyTypes option from OpenSSH 8.1
93 for ssh_key_type in ecdsa ed25519 rsa; do
94 pk="$ssh_home/id_${ssh_key_type}.pub"
95 ssh_key=""
96 if test -f "$pk" && ssh_key="$(< "$pk")" && test -n "$ssh_key"; then
97 break
99 done
101 echo "Please go to https://gerrit.libreoffice.org/ and click the \"Sign in\" link"
102 echo "at the top right of the page. You'll be sent to our Single Sign-On portal"
103 echo "for authentication (create an account if needs be), and automatically"
104 echo "redirected back to gerrit afterwards."
105 echo
106 echo "Visit https://gerrit.libreoffice.org/settings/#SSHKeys and paste the public"
107 if test -z "$ssh_key"; then
108 echo "part of your SSH key in the 'New SSH key' form."
109 else
110 echo "key below in the 'New SSH key' form."
111 echo
112 printf '%s\n' "$ssh_key"
113 echo
115 echo
116 echo "Note that you need to register additional email addresses, if you want to"
117 echo "commit from them. Each additional email address must be confirmed by"
118 echo "following the verification link sent to it."
119 echo
120 read -r -p 'Which user name did you choose? ' GERRITUSER
121 if test -z "$created_ssh"; then
122 echo
123 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
124 echo
125 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
126 echo
127 else
128 echo "Automatically creating your ssh config"
129 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
131 # setup the remote properly ...
132 git config remote.origin.pushurl ssh://logerrit/core
133 echo "To see if your setup was successful, run './logerrit test' then."
134 # a good place to make sure the hooks are set up
135 ./g -z
137 test)
138 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review")"
139 then
140 echo "Your gerrit setup was successful!"
141 else
142 echo "There seems to be trouble. Please have the output of:"
143 echo "ssh -vvvv $GERRITHOST"
144 echo "at hand when looking for help."
147 submit)
148 submit "$2"
150 submit-private)
151 submit "$2" '%private'
153 submit-wip)
154 submit "$2" '%wip'
156 submit-draft)
157 echo "Please use submit-private instead of submit-draft."
158 exit 1
160 nextchange)
161 if test -n "$(git status -s -uno)"
162 then
163 echo "You have uncommitted changes. Please commit or stash these:"
164 git status
165 exit 1
167 CHANGEID=$(git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ )
168 if test -z "$CHANGEID"
169 then
170 CHANGEID="NOCHANGEID"
172 BACKUPBRANCH=backup/$CHANGEID-$(date +%F-%H%M%S)
173 git branch "$BACKUPBRANCH"
174 echo "current state backed up as $BACKUPBRANCH"
175 BRANCH=$2
176 if test -z "$BRANCH"
177 then
178 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
179 BRANCH="${BRANCH##refs/heads/}"
180 if test -z "$BRANCH"
181 then
182 echo "no branch specified, and could not guess the current branch"
183 exit 1
185 echo "no branch specified, guessing current branch $BRANCH"
187 git reset --hard "remotes/origin/$BRANCH"
189 checkout)
190 get_SHA_for_change "$2"
191 git fetch "$GERRITURL" "$SHA" && git checkout FETCH_HEAD
193 review)
194 echo "'./logerrit review' has been removed as obsolete."
195 echo "Please use either:"
196 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
197 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
198 echo "Both provide a better experience."
199 exit 1;
201 pull)
202 get_SHA_for_change "$2"
203 git pull "$GERRITURL" "$SHA"
205 cherry-pick)
206 get_SHA_for_change "$2"
207 git fetch "$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
209 patch)
210 get_SHA_for_change "$2"
211 git fetch "$GERRITURL" "$SHA" && git format-patch -1 --stdout FETCH_HEAD
213 query)
214 shift
215 ssh "${GERRITHOST?}" gerrit query project:core "${@@Q}"
217 testfeature)
218 CHANGEID=${3#I}
219 if test -n "$3" -a \( ${#3} -ne 41 -o -n "${CHANGEID//[0-9a-f]/}" \)
220 then
221 echo "${3} is not a valid Gerrit change id"
222 exit 1
224 CHANGEID=$3
226 BRANCH=$2
227 if test -z "$BRANCH"
228 then
229 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
230 BRANCH="${BRANCH##refs/heads/}"
231 if test -z "$BRANCH"
232 then
233 echo "no branch specified, and could not guess the current branch"
234 exit 1
236 echo "no branch specified, guessing current branch $BRANCH"
238 BRANCH="${BRANCH##feature/}"
239 WORKDIR=$(mktemp -d)
240 if test -z "$WORKDIR"
241 then
242 echo "could not create work directory."
243 exit 1
245 echo "workdir at $WORKDIR"
246 git clone -s "$(dirname "$0")" "$WORKDIR/core"
248 pushd "$WORKDIR/core" || { echo "Changing directory failed."; exit 1; }
249 echo "noop commit: trigger test build for branch feature/$BRANCH" > ../commitmsg
250 echo >> ../commitmsg
251 echo "branch is at:" >> ../commitmsg
252 echo >> ../commitmsg
253 git log -1|sed -e "s/Change-Id:/XXXXXX:/" >> ../commitmsg
254 if test -n "$CHANGEID"
255 then
256 echo >> ../commitmsg
257 echo "Change-Id: $CHANGEID" >> ../commitmsg
259 git fetch https://git.libreoffice.org/core "feature/$BRANCH" && \
260 git checkout -b featuretst FETCH_HEAD && \
261 cp -a .git-hooks/* .git/hooks && \
262 git commit --allow-empty -F ../commitmsg && \
263 git push "$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
264 popd || { echo "Changing directory failed."; exit 1; }
266 rm -rf "$WORKDIR/core"
267 rm -f "$WORKDIR/commitmsg"
268 rmdir "$WORKDIR"
271 ssh "${GERRITHOST?}" gerrit "${@@Q}"
273 esac
275 # vim: set noet sw=4 ts=4: