tdf#99528: revert vertical tabs changes (24.8 only)
[LibreOffice.git] / logerrit
blobf9077bd6b384030165675632f4c270ca5cffa4bb
1 #!/usr/bin/env 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 get_tracked_branch() {
12 local BRANCH=$(git symbolic-ref HEAD|sed 's|refs/heads/||')
13 local REMOTE=$(git config branch.$BRANCH.remote)
14 git rev-parse --abbrev-ref --symbolic-full-name HEAD@{upstream}|sed "s|${REMOTE}/||"
17 submit() {
18 BRANCH=$1
19 TYPE=${2:-''}
20 if test -z "$BRANCH"; then
21 BRANCH=$(get_tracked_branch)
22 if test -z "$BRANCH"; then
23 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
24 BRANCH="${BRANCH##refs/heads/}"
25 if test -z "$BRANCH"; then
26 echo "no branch specified, and could not guess the current branch"
27 exit 1
30 echo "no branch specified, guessing current branch $BRANCH"
33 if [ "$BRANCH" = "master" ]; then
34 WEEKOLDDATE=$(date --date="7 days ago" +%s 2> /dev/null)
35 if [ "$WEEKOLDDATE" = "" ]; then
36 WEEKOLDDATE=$(date -v-7d +%s) # BSD equivalent
38 PARENTDATE=$(git show -s --format=%ct HEAD~1)
39 if [[ $PARENTDATE -lt $WEEKOLDDATE ]]; then
40 echo "Your branch is older than a week, do './g pull -r' and retry"
41 exit 1
44 git push "$GERRITURL" "HEAD:refs/for/$BRANCH$TYPE"
47 logerrit() {
48 echo "Host logerrit gerrit.libreoffice.org"
49 if test -n "${2-}" && test -f "$HOME/.ssh/id_$2"; then
50 echo " IdentityFile ~/.ssh/id_$2"
52 echo " User $1"
53 echo " Port 29418"
54 echo " HostName gerrit.libreoffice.org"
57 case "$1" in
58 help|--help|"")
59 echo "Usage: ./logerrit subcommand [options]"
60 echo "simple and basic tool to interact with LibreOffice gerrit"
61 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
62 echo
63 echo "subcommands:"
64 echo " setup walking you though your gerrit setup"
65 echo " test test your gerrit setup"
66 echo
67 echo " --- for submitters:"
68 echo " submit [BRANCH] submit your change for review"
69 echo " submit [BRANCH]%private submit your change as private"
70 echo " submit [BRANCH]%wip submit your change as work-in-progress"
71 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
72 echo " testfeature [BRANCH] [CHANGEID]"
73 echo " trigger a test of a feature branch on gerrit"
74 echo
75 echo "Note: private changes are only visibly to yourself and those that you explicitly add as reviewers."
76 echo "For full documentation, see https://gerrit.libreoffice.org/Documentation/intro-user.html#private-changes"
77 echo
78 echo " --- for reviewers:"
79 echo " checkout CHANGEID checkout the changes for review"
80 echo " pull CHANGEID pull (and merge) the changes on current branch"
81 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
82 echo " patch CHANGEID show the change as a patch"
83 echo " query ... query for changes for review on project core"
84 echo " <any other gerrit command>"
85 echo
86 echo "advanced users should consider using git review instead:"
87 echo "https://wiki.documentfoundation.org/Development/GitReview"
88 exit
90 setup)
91 script_canonical_file=$(readlink -f "$0")
92 script_canonical_dir=$(dirname "$script_canonical_file")
93 if ! cd "$script_canonical_dir"; then
94 echo "Can't cd to $script_canonical_dir"
95 exit 1
97 ssh_home="$HOME/.ssh";
98 ssh_key=
99 created_ssh=
100 if ! test -d "$ssh_home"; then
101 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
102 mkdir -m0700 "$ssh_home"
103 created_ssh=TRUE
104 echo
105 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
106 echo
107 read -r
108 all_algo="$(ssh -Q key)"
109 if grep -q -x ssh-ed25519 <<< "$all_algo"; then
110 algo="ed25519"
111 elif grep -q -x ssh-rsa <<< "$all_algo"; then
112 algo="rsa"
113 else
114 echo "Could not find 'ssh-ed25519' or 'ssh-rsa' in the output from 'ssh -Q key'"
115 exit 1
117 ssh-keygen -t "$algo" # Generate the key pair using the selected algorithm
119 if test -d "$ssh_home"; then
120 # order algos based on the PubkeyAcceptedKeyTypes option from OpenSSH 8.1
121 for ssh_key_type in ecdsa ed25519 rsa; do
122 pk="$ssh_home/id_${ssh_key_type}.pub"
123 ssh_key=""
124 if test -f "$pk" && ssh_key="$(< "$pk")" && test -n "$ssh_key"; then
125 break
127 done
129 echo "Please go to https://gerrit.libreoffice.org/ and click the \"Sign in\" link"
130 echo "at the top right of the page. You'll be sent to our Single Sign-On portal"
131 echo "for authentication (create an account if needs be), and automatically"
132 echo "redirected back to gerrit afterwards."
133 echo
134 echo "Visit https://gerrit.libreoffice.org/settings/#SSHKeys and paste the public"
135 if test -z "$ssh_key"; then
136 echo "part of your SSH key in the 'New SSH key' form."
137 else
138 echo "key below in the 'New SSH key' form."
139 echo
140 printf '%s\n' "$ssh_key"
141 echo
143 echo
144 echo "Note that you need to register additional email addresses, if you want to"
145 echo "commit from them. Each additional email address must be confirmed by"
146 echo "following the verification link sent to it."
147 echo
148 read -r -p 'Which user name did you choose? ' GERRITUSER
149 if test -z "$created_ssh"; then
150 echo
151 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
152 echo
153 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
154 echo
155 else
156 echo "Automatically creating your ssh config"
157 logerrit "$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
159 # setup the remote properly ...
160 git config remote.origin.pushurl ssh://logerrit/core
161 echo "To see if your setup was successful, run './logerrit test' then."
162 # a good place to make sure the hooks are set up
163 ./g -z
165 test)
166 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review")"; then
167 echo "Your gerrit setup was successful!"
168 else
169 echo "There seems to be trouble. Please have the output of:"
170 echo "ssh -vvvv $GERRITHOST"
171 echo "at hand when looking for help."
174 submit)
175 submit "$2"
177 nextchange)
178 if test -n "$(git status -s -uno)"; then
179 echo "You have uncommitted changes. Please commit or stash these:"
180 git status
181 exit 1
183 CHANGEID=$(git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ )
184 if test -z "$CHANGEID"; then
185 CHANGEID="NOCHANGEID"
187 BACKUPBRANCH=backup/$CHANGEID-$(date +%F-%H%M%S)
188 git branch "$BACKUPBRANCH"
189 echo "current state backed up as $BACKUPBRANCH"
190 BRANCH=$2
191 if test -z "$BRANCH"; then
192 BRANCH=$(get_tracked_branch)
193 if test -z "$BRANCH"; then
194 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
195 BRANCH="${BRANCH##refs/heads/}"
196 if test -z "$BRANCH"; then
197 echo "no branch specified, and could not guess the current branch"
198 exit 1
201 echo "no branch specified, guessing current branch $BRANCH"
203 git reset --hard "remotes/origin/$BRANCH"
205 checkout)
206 get_SHA_for_change "$2"
207 git fetch "$GERRITURL" "$SHA" && git checkout FETCH_HEAD
209 review)
210 echo "'./logerrit review' has been removed as obsolete."
211 echo "Please use either:"
212 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
213 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
214 echo "Both provide a better experience."
215 exit 1;
217 pull)
218 get_SHA_for_change "$2"
219 git pull "$GERRITURL" "$SHA"
221 cherry-pick)
222 get_SHA_for_change "$2"
223 git fetch "$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
225 patch)
226 get_SHA_for_change "$2"
227 git fetch "$GERRITURL" "$SHA" && git format-patch -1 --stdout FETCH_HEAD
229 query)
230 shift
231 ssh "${GERRITHOST?}" gerrit query project:core "${@@Q}"
233 testfeature)
234 CHANGEID=${3#I}
235 if test -n "$3" -a \( ${#3} -ne 41 -o -n "${CHANGEID//[0-9a-f]/}" \); then
236 echo "${3} is not a valid Gerrit change id"
237 exit 1
239 CHANGEID=$3
241 BRANCH=$2
242 if test -z "$BRANCH"; then
243 BRANCH=$(get_tracked_branch)
244 if test -z "$BRANCH"; then
245 BRANCH=$(git symbolic-ref HEAD 2> /dev/null)
246 BRANCH="${BRANCH##refs/heads/}"
247 if test -z "$BRANCH"; then
248 echo "no branch specified, and could not guess the current branch"
249 exit 1
252 echo "no branch specified, guessing current branch $BRANCH"
254 BRANCH="${BRANCH##feature/}"
255 WORKDIR=$(mktemp -d)
256 if test -z "$WORKDIR"; then
257 echo "could not create work directory."
258 exit 1
260 echo "workdir at $WORKDIR"
261 git clone -s "$(dirname "$0")" "$WORKDIR/core"
263 pushd "$WORKDIR/core" || { echo "Changing directory failed."; exit 1; }
264 echo "noop commit: trigger test build for branch feature/$BRANCH" > ../commitmsg
265 echo >> ../commitmsg
266 echo "branch is at:" >> ../commitmsg
267 echo >> ../commitmsg
268 git log -1|sed -e "s/Change-Id:/XXXXXX:/" >> ../commitmsg
269 if test -n "$CHANGEID"; then
270 echo >> ../commitmsg
271 echo "Change-Id: $CHANGEID" >> ../commitmsg
273 git fetch https://git.libreoffice.org/core "feature/$BRANCH" && \
274 git checkout -b featuretst FETCH_HEAD && \
275 cp -a .git-hooks/* .git/hooks && \
276 git commit --allow-empty -F ../commitmsg && \
277 git push "$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
278 popd || { echo "Changing directory failed."; exit 1; }
280 rm -rf "$WORKDIR/core"
281 rm -f "$WORKDIR/commitmsg"
282 rmdir "$WORKDIR"
285 ssh "${GERRITHOST?}" gerrit "${@@Q}"
287 esac
289 # vim: set noet sw=4 ts=4: