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/^ *//')
13 if test -z "${branch}"; then
14 # Try to use the tracked branch
15 branch
=$
(git symbolic-ref HEAD|
sed 's|refs/heads/||')
16 local remote
=$
(git config branch.
${branch}.remote
)
17 branch
=$
(git rev-parse
--abbrev-ref --symbolic-full-name HEAD@
{upstream
}|
sed "s|${remote}/||")
18 if test -z "$branch"; then
19 branch
=$
(git symbolic-ref HEAD
2> /dev
/null
)
20 branch
="${branch##refs/heads/}"
21 if test -z "${branch}"; then
22 echo >&2 "no branch specified, and could not guess the current branch"
25 echo >&2 "no branch specified, guessing current branch ${branch}"
27 echo >&2 "no branch specified, guessing tracked branch ${branch}"
34 echo "Host logerrit gerrit.libreoffice.org"
35 if test -n "${2-}" && test -f "$HOME/.ssh/id_$2"; then
36 echo " IdentityFile ~/.ssh/id_$2"
40 echo " HostName gerrit.libreoffice.org"
45 echo "Usage: ./logerrit subcommand [options]"
46 echo "simple and basic tool to interact with LibreOffice gerrit"
47 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
50 echo " setup walking you though your gerrit setup"
51 echo " test test your gerrit setup"
53 echo " --- for submitters:"
54 echo " submit [BRANCH] submit your change for review"
55 echo " submit [BRANCH]%private submit your change as private"
56 echo " submit [BRANCH]%wip submit your change as work-in-progress"
57 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
58 echo " testfeature [BRANCH] [CHANGEID]"
59 echo " trigger a test of a feature branch on gerrit"
61 echo "Note: private changes are only visibly to yourself and those that you explicitly add as reviewers."
62 echo "For full documentation, see https://gerrit.libreoffice.org/Documentation/intro-user.html#private-changes"
64 echo " --- for reviewers:"
65 echo " checkout CHANGEID checkout the changes for review"
66 echo " pull CHANGEID pull (and merge) the changes on current branch"
67 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
68 echo " patch CHANGEID show the change as a patch"
69 echo " query ... query for changes for review on project core"
70 echo " <any other gerrit command>"
72 echo "advanced users should consider using git review instead:"
73 echo "https://wiki.documentfoundation.org/Development/GitReview"
77 script_canonical_file
=$
(readlink
-f "$0")
78 script_canonical_dir
=$
(dirname "$script_canonical_file")
79 if ! cd "$script_canonical_dir"; then
80 echo "Can't cd to $script_canonical_dir"
83 ssh_home
="$HOME/.ssh";
86 if ! test -d "$ssh_home"; then
87 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
88 mkdir
-m0700 "$ssh_home"
91 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
94 all_algo
="$(ssh -Q key)"
95 if grep -q -x ssh-ed25519
<<< "$all_algo"; then
97 elif grep -q -x ssh-rsa
<<< "$all_algo"; then
100 echo "Could not find 'ssh-ed25519' or 'ssh-rsa' in the output from 'ssh -Q key'"
103 ssh-keygen
-t "$algo" # Generate the key pair using the selected algorithm
105 if test -d "$ssh_home"; then
106 # order algos based on the PubkeyAcceptedKeyTypes option from OpenSSH 8.1
107 for ssh_key_type
in ecdsa ed25519 rsa
; do
108 pk
="$ssh_home/id_${ssh_key_type}.pub"
110 if test -f "$pk" && ssh_key
="$(< "$pk")" && test -n "$ssh_key"; then
115 echo "Please go to https://gerrit.libreoffice.org/ and click the \"Sign in\" link"
116 echo "at the top right of the page. You'll be sent to our Single Sign-On portal"
117 echo "for authentication (create an account if needs be), and automatically"
118 echo "redirected back to gerrit afterwards."
120 echo "Visit https://gerrit.libreoffice.org/settings/#SSHKeys and paste the public"
121 if test -z "$ssh_key"; then
122 echo "part of your SSH key in the 'New SSH key' form."
124 echo "key below in the 'New SSH key' form."
126 printf '%s\n' "$ssh_key"
130 echo "Note that you need to register additional email addresses, if you want to"
131 echo "commit from them. Each additional email address must be confirmed by"
132 echo "following the verification link sent to it."
134 read -r -p 'Which user name did you choose? ' GERRITUSER
135 if test -z "$created_ssh"; then
137 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
139 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
142 echo "Automatically creating your ssh config"
143 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
145 # setup the remote properly ...
146 git config remote.origin.pushurl
ssh://logerrit
/core
147 echo "To see if your setup was successful, run './logerrit test' then."
148 # a good place to make sure the hooks are set up
152 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review
")"; then
153 echo "Your gerrit setup was successful!"
155 echo "There seems to be trouble. Please have the output of:"
156 echo "ssh -vvvv $GERRITHOST"
157 echo "at hand when looking for help."
161 BRANCH
=$
(branch_or_default
$2)
164 if [ "$BRANCH" = "master" ]; then
165 WEEKOLDDATE
=$
(date --date="7 days ago" +%s
2> /dev
/null
)
166 if [ "$WEEKOLDDATE" = "" ]; then
167 WEEKOLDDATE
=$
(date -v-7d +%s
) # BSD equivalent
169 PARENTDATE
=$
(git show
-s --format=%ct HEAD~
1)
170 if [[ $PARENTDATE -lt $WEEKOLDDATE ]]; then
171 echo "Your branch is older than a week, do './g pull -r' and retry"
175 git push
"$GERRITURL" "HEAD:refs/for/$BRANCH$TYPE"
178 if test -n "$(git status -s -uno)"; then
179 echo "You have uncommitted changes. Please commit or stash these:"
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
=$
(branch_or_default
$2)
191 git
reset --hard "remotes/origin/$BRANCH"
194 get_SHA_for_change
"$2"
195 git fetch
"$GERRITURL" "$SHA" && git checkout FETCH_HEAD
198 echo "'./logerrit review' has been removed as obsolete."
199 echo "Please use either:"
200 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
201 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
202 echo "Both provide a better experience."
206 get_SHA_for_change
"$2"
207 git pull
"$GERRITURL" "$SHA"
210 get_SHA_for_change
"$2"
211 git fetch
"$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
214 get_SHA_for_change
"$2"
215 git fetch
"$GERRITURL" "$SHA" && git format-patch
-1 --stdout FETCH_HEAD
219 ssh "${GERRITHOST?}" gerrit query project
:core
"${@@Q}"
223 if test -n "$3" -a \
( ${#3} -ne 41 -o -n "${CHANGEID//[0-9a-f]/}" \
); then
224 echo "${3} is not a valid Gerrit change id"
229 BRANCH
=$
(branch_or_default
$2)
230 BRANCH
="${BRANCH##feature/}"
232 if test -z "$WORKDIR"; then
233 echo "could not create work directory."
236 echo "workdir at $WORKDIR"
237 git clone
-s "$(dirname "$0")" "$WORKDIR/core"
239 pushd "$WORKDIR/core" ||
{ echo "Changing directory failed."; exit 1; }
240 echo "noop commit: trigger test build for branch feature/$BRANCH" > ..
/commitmsg
242 echo "branch is at:" >> ..
/commitmsg
244 git log
-1|
sed -e "s/Change-Id:/XXXXXX:/" >> ..
/commitmsg
245 if test -n "$CHANGEID"; then
247 echo "Change-Id: $CHANGEID" >> ..
/commitmsg
249 git fetch https
://git.libreoffice.org
/core
"feature/$BRANCH" && \
250 git checkout
-b featuretst FETCH_HEAD
&& \
251 cp -a .git-hooks
/* .git
/hooks
&& \
252 git commit
--allow-empty -F ..
/commitmsg
&& \
253 git push
"$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
254 popd ||
{ echo "Changing directory failed."; exit 1; }
256 rm -rf "$WORKDIR/core"
257 rm -f "$WORKDIR/commitmsg"
261 ssh "${GERRITHOST?}" gerrit
"${@@Q}"
265 # vim: set noet sw=4 ts=4: