3 #GERRITHOST=gerrit.libreoffice.org
5 GERRITURL
="ssh://$GERRITHOST/core"
8 SHA
=$
(ssh "${GERRITHOST?}" gerrit query
--all-approvals change
:"$1" |
grep ref |
tail -1 | cut
-d: -f2 |
sed 's/^ *//')
16 BRANCH
=$
(git symbolic-ref HEAD
2> /dev
/null
)
17 BRANCH
="${BRANCH##refs/heads/}"
20 echo "no branch specified, and could not guess the current branch"
23 echo "no branch specified, guessing current branch $BRANCH"
25 git push
"$GERRITURL" "HEAD:refs/for/$BRANCH$TYPE"
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"
35 echo " HostName gerrit.libreoffice.org"
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."
45 echo " setup walking you though your gerrit setup"
46 echo " test test your gerrit setup"
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"
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>"
65 echo "advanced users should consider using git review instead:"
66 echo "https://wiki.documentfoundation.org/Development/GitReview"
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"
76 ssh_home
="$HOME/.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"
84 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
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"
94 if test -f "$pk" && ssh_key
="$(< "$pk")" && test -n "$ssh_key"; then
99 echo "Please go to https://gerrit.libreoffice.org/ and click the \"Sign in\" link"
100 echo "at the top right of the page. You'll be sent to our Single Sign-On portal"
101 echo "for authentication (create an account if needs be), and automatically"
102 echo "redirected back to gerrit afterwards."
104 echo "Visit https://gerrit.libreoffice.org/settings/#SSHKeys and paste the public"
105 if test -z "$ssh_key"; then
106 echo "part of your SSH key in the 'New SSH key' form."
108 echo "key below in the 'New SSH key' form."
110 printf '%s\n' "$ssh_key"
114 echo "Note that you need to register additional email addresses, if you want to"
115 echo "commit from them. Each additional email address must be confirmed by"
116 echo "following the verification link sent to it."
118 read -r -p 'Which user name did you choose? ' GERRITUSER
119 if test -z "$created_ssh"; then
121 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
123 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
126 echo "Automatically creating your ssh config"
127 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
129 # setup the remote properly ...
130 git config remote.origin.pushurl
ssh://logerrit
/core
131 echo "To see if your setup was successful, run './logerrit test' then."
132 # a good place to make sure the hooks are set up
136 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review
")"
138 echo "Your gerrit setup was successful!"
140 echo "There seems to be trouble. Please have the output of:"
141 echo "ssh -vvvv $GERRITHOST"
142 echo "at hand when looking for help."
149 submit
"$2" '%private'
155 echo "Please use submit-private instead of submit-draft."
159 if test -n "$(git status -s -uno)"
161 echo "You have uncommitted changes. Please commit or stash these:"
165 CHANGEID
=$
(git log
--format=format
:%b
-1 HEAD|
grep Change-Id|cut
-d: -f2|
tr -d \
)
166 if test -z "$CHANGEID"
168 CHANGEID
="NOCHANGEID"
170 BACKUPBRANCH
=backup
/$CHANGEID-$
(date +%F-
%H
%M
%S
)
171 git branch
"$BACKUPBRANCH"
172 echo "current state backed up as $BACKUPBRANCH"
176 BRANCH
=$
(git symbolic-ref HEAD
2> /dev
/null
)
177 BRANCH
="${BRANCH##refs/heads/}"
180 echo "no branch specified, and could not guess the current branch"
183 echo "no branch specified, guessing current branch $BRANCH"
185 git
reset --hard "remotes/origin/$BRANCH"
188 get_SHA_for_change
"$2"
189 git fetch
"$GERRITURL" "$SHA" && git checkout FETCH_HEAD
192 echo "'./logerrit review' has been removed as obsolete."
193 echo "Please use either:"
194 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
195 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
196 echo "Both provide a better experience."
200 get_SHA_for_change
"$2"
201 git pull
"$GERRITURL" "$SHA"
204 get_SHA_for_change
"$2"
205 git fetch
"$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
208 get_SHA_for_change
"$2"
209 git fetch
"$GERRITURL" "$SHA" && git format-patch
-1 --stdout FETCH_HEAD
213 ssh "${GERRITHOST?}" gerrit query project
:core
"${@@Q}"
219 BRANCH
=$
(git symbolic-ref HEAD
2> /dev
/null
)
220 BRANCH
="${BRANCH##refs/heads/}"
223 echo "no branch specified, and could not guess the current branch"
226 echo "no branch specified, guessing current branch $BRANCH"
228 BRANCH
="${BRANCH##feature/}"
230 if test -z "$WORKDIR"
232 echo "could not create work directory."
235 echo "workdir at $WORKDIR"
236 git clone
-s "$(dirname "$0")" "$WORKDIR/core"
237 pushd "$WORKDIR/core" ||
{ echo "Changing directory failed."; exit 1; }
238 echo "noop commit: trigger test build for branch feature/$BRANCH" > ..
/commitmsg
240 echo "branch is at:" >> ..
/commitmsg
241 git log
-1|
sed -e "s/Change-Id:/XXXXXX:/" >> ..
/commitmsg
242 git fetch https
://git.libreoffice.org
/core
"feature/$BRANCH" && \
243 git checkout
-b featuretst FETCH_HEAD
&& \
244 cp -a .git-hooks
/* .git
/hooks
245 git commit
--allow-empty -F ..
/commitmsg
&& \
246 git push
"$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
247 popd ||
{ echo "Changing directory failed."; exit 1; }
248 rm -rf "$WORKDIR/core"
251 ssh "${GERRITHOST?}" gerrit
"${@@Q}"