lok: use "None" string item in the ListBox control
[LibreOffice.git] / logerrit
blob86f39cef99abcfac1dc76fddfd5dccc89dae1dbb
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] trigger a test of a feature branch on gerrit"
54 echo "Note: private changes are only visibly to yourself and those that you explicitly add as reviewers."
55 echo "For full documentation, see https://gerrit.libreoffice.org/Documentation/intro-user.html#private-changes"
56 echo
57 echo " --- for reviewers:"
58 echo " checkout CHANGEID checkout the changes for review"
59 echo " pull CHANGEID pull (and merge) the changes on current branch"
60 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
61 echo " patch CHANGEID show the change as a patch"
62 echo " query ... query for changes for review on project core"
63 echo " <any other gerrit command>"
64 echo
65 echo "advanced users should consider using git review instead:"
66 echo "https://wiki.documentfoundation.org/Development/GitReview"
67 exit
69 setup)
70 script_canonical_file=$(readlink -f "$0")
71 script_canonical_dir=$(dirname "$script_canonical_file")
72 if ! cd "$script_canonical_dir"; then
73 echo "Can't cd to $script_canonical_dir"
74 exit 1
76 ssh_home="$HOME/.ssh";
77 ssh_key=
78 created_ssh=
79 if ! test -d "$ssh_home"; then
80 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
81 mkdir -m0700 "$ssh_home"
82 created_ssh=TRUE
83 echo
84 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
85 echo
86 read -r
87 ssh-keygen -t rsa -f "$ssh_home/id_rsa" # default type as of OpenSSH 8.1
89 if test -d "$ssh_home"; then
90 # order algos based on the PubkeyAcceptedKeyTypes option from OpenSSH 8.1
91 for ssh_key_type in ecdsa ed25519 rsa; do
92 pk="$ssh_home/id_${ssh_key_type}.pub"
93 ssh_key=""
94 if test -f "$pk" && ssh_key="$(< "$pk")" && test -n "$ssh_key"; then
95 break
97 done
99 echo "Please go to https://gerrit.libreoffice.org/ and:"
100 echo " - press the 'register' button in the top right corner"
101 echo " - after login set yourself a username (it is recommended to use your IRC-nick)"
102 if test -z "$ssh_key"; then
103 echo " - add your public ssh-key into the ssh keys settings."
104 else
105 echo " - paste the key below into the 'Add SSH Public Key' box."
106 echo
107 printf '%s\n' "$ssh_key"
108 echo
110 echo
111 echo "Note that you need to register additional email addresses, if you want to"
112 echo "commit from them. Additional emails must be confirmed by replying to the"
113 echo "invitation mail it sends you."
114 echo
115 read -r -p 'Which user name did you choose? ' GERRITUSER
116 if test -z "$created_ssh"; then
117 echo
118 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
119 echo
120 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
121 echo
122 else
123 echo "Automatically creating your ssh config"
124 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
126 # setup the remote properly ...
127 git config remote.origin.pushurl ssh://logerrit/core
128 echo "To see if your setup was successful, run './logerrit test' then."
129 # a good place to make sure the hooks are set up
130 ./g -z
132 test)
133 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review")"
134 then
135 echo "Your gerrit setup was successful!"
136 else
137 echo "There seems to be trouble. Please have the output of:"
138 echo "ssh -vvvv $GERRITHOST"
139 echo "at hand when looking for help."
142 submit)
143 submit "$2"
145 submit-private)
146 submit "$2" '%private'
148 submit-wip)
149 submit "$2" '%wip'
151 submit-draft)
152 echo "Please use submit-private instead of submit-draft."
153 exit 1
155 nextchange)
156 if test -n "$(git status -s -uno)"
157 then
158 echo "You have uncommitted changes. Please commit or stash these:"
159 git status
160 exit 1
162 CHANGEID=$(git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ )
163 if test -z "$CHANGEID"
164 then
165 CHANGEID="NOCHANGEID"
167 BACKUPBRANCH=backup/$CHANGEID-$(date +%F-%H%M%S)
168 git branch "$BACKUPBRANCH"
169 echo "current state backed up as $BACKUPBRANCH"
170 BRANCH=$2
171 if test -z "$BRANCH"
172 then
173 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
174 BRANCH="${BRANCH##refs/heads/}"
175 if test -z "$BRANCH"
176 then
177 echo "no branch specified, and could not guess the current branch"
178 exit 1
180 echo "no branch specified, guessing current branch $BRANCH"
182 git reset --hard "remotes/origin/$BRANCH"
184 checkout)
185 get_SHA_for_change "$2"
186 git fetch "$GERRITURL" "$SHA" && git checkout FETCH_HEAD
188 review)
189 echo "'./logerrit review' has been removed as obsolete."
190 echo "Please use either:"
191 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
192 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
193 echo "Both provide a better experience."
194 exit 1;
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 "${@@Q}"
212 testfeature)
213 BRANCH=$2
214 if test -z "$BRANCH"
215 then
216 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
217 BRANCH="${BRANCH##refs/heads/}"
218 if test -z "$BRANCH"
219 then
220 echo "no branch specified, and could not guess the current branch"
221 exit 1
223 echo "no branch specified, guessing current branch $BRANCH"
225 BRANCH="${BRANCH##feature/}"
226 WORKDIR=$(mktemp -d)
227 if test -z "$WORKDIR"
228 then
229 echo "could not create work directory."
230 exit 1
232 echo "workdir at $WORKDIR"
233 git clone -s "$(dirname "$0")" "$WORKDIR/core"
234 pushd "$WORKDIR/core" || { echo "Changing directory failed."; exit 1; }
235 echo "noop commit: trigger test build for branch feature/$BRANCH" > ../commitmsg
236 echo >> ../commitmsg
237 echo "branch is at:" >> ../commitmsg
238 git log -1|sed -e "s/Change-Id:/XXXXXX:/" >> ../commitmsg
239 git fetch https://git.libreoffice.org/core "feature/$BRANCH" && \
240 git checkout -b featuretst FETCH_HEAD && \
241 cp -a .git-hooks/* .git/hooks
242 git commit --allow-empty -F ../commitmsg && \
243 git push "$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
244 popd || { echo "Changing directory failed."; exit 1; }
245 rm -rf "$WORKDIR/core"
248 ssh "${GERRITHOST?}" gerrit "${@@Q}"
250 esac