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"
26 if [ "$BRANCH" = "master" ]; then
27 WEEKOLDDATE
=$
(date --date="7 days ago" +%s
2> /dev
/null
)
28 if [ "$WEEKOLDDATE" = "" ]; then
29 WEEKOLDDATE
=$
(date -v-7d +%s
) # BSD equivalent
31 PARENTDATE
=$
(git show
-s --format=%ct HEAD~
1)
32 if [[ $PARENTDATE -lt $WEEKOLDDATE ]]; then
33 echo "Your branch is older than a week, do './g pull -r' and retry"
37 git push
"$GERRITURL" "HEAD:refs/for/$BRANCH$TYPE"
41 echo "Host logerrit gerrit.libreoffice.org"
42 if test -n "${2-}" && test -f "$HOME/.ssh/id_$2"; then
43 echo " IdentityFile ~/.ssh/id_$2"
47 echo " HostName gerrit.libreoffice.org"
52 echo "Usage: ./logerrit subcommand [options]"
53 echo "simple and basic tool to interact with LibreOffice gerrit"
54 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
57 echo " setup walking you though your gerrit setup"
58 echo " test test your gerrit setup"
60 echo " --- for submitters:"
61 echo " submit [BRANCH] submit your change for review"
62 echo " submit [BRANCH]%private submit your change as private"
63 echo " submit [BRANCH]%wip submit your change as work-in-progress"
64 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
65 echo " testfeature [BRANCH] [CHANGEID]"
66 echo " trigger a test of a feature branch on gerrit"
68 echo "Note: private changes are only visibly to yourself and those that you explicitly add as reviewers."
69 echo "For full documentation, see https://gerrit.libreoffice.org/Documentation/intro-user.html#private-changes"
71 echo " --- for reviewers:"
72 echo " checkout CHANGEID checkout the changes for review"
73 echo " pull CHANGEID pull (and merge) the changes on current branch"
74 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
75 echo " patch CHANGEID show the change as a patch"
76 echo " query ... query for changes for review on project core"
77 echo " <any other gerrit command>"
79 echo "advanced users should consider using git review instead:"
80 echo "https://wiki.documentfoundation.org/Development/GitReview"
84 script_canonical_file
=$
(readlink
-f "$0")
85 script_canonical_dir
=$
(dirname "$script_canonical_file")
86 if ! cd "$script_canonical_dir"; then
87 echo "Can't cd to $script_canonical_dir"
90 ssh_home
="$HOME/.ssh";
93 if ! test -d "$ssh_home"; then
94 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
95 mkdir
-m0700 "$ssh_home"
98 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
101 ssh-keygen
-t rsa
-f "$ssh_home/id_rsa" # default type as of OpenSSH 8.1
103 if test -d "$ssh_home"; then
104 # order algos based on the PubkeyAcceptedKeyTypes option from OpenSSH 8.1
105 for ssh_key_type
in ecdsa ed25519 rsa
; do
106 pk
="$ssh_home/id_${ssh_key_type}.pub"
108 if test -f "$pk" && ssh_key
="$(< "$pk")" && test -n "$ssh_key"; then
113 echo "Please go to https://gerrit.libreoffice.org/ and click the \"Sign in\" link"
114 echo "at the top right of the page. You'll be sent to our Single Sign-On portal"
115 echo "for authentication (create an account if needs be), and automatically"
116 echo "redirected back to gerrit afterwards."
118 echo "Visit https://gerrit.libreoffice.org/settings/#SSHKeys and paste the public"
119 if test -z "$ssh_key"; then
120 echo "part of your SSH key in the 'New SSH key' form."
122 echo "key below in the 'New SSH key' form."
124 printf '%s\n' "$ssh_key"
128 echo "Note that you need to register additional email addresses, if you want to"
129 echo "commit from them. Each additional email address must be confirmed by"
130 echo "following the verification link sent to it."
132 read -r -p 'Which user name did you choose? ' GERRITUSER
133 if test -z "$created_ssh"; then
135 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
137 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
140 echo "Automatically creating your ssh config"
141 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"} >"$ssh_home/config"
143 # setup the remote properly ...
144 git config remote.origin.pushurl
ssh://logerrit
/core
145 echo "To see if your setup was successful, run './logerrit test' then."
146 # a good place to make sure the hooks are set up
150 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review
")"
152 echo "Your gerrit setup was successful!"
154 echo "There seems to be trouble. Please have the output of:"
155 echo "ssh -vvvv $GERRITHOST"
156 echo "at hand when looking for help."
163 if test -n "$(git status -s -uno)"
165 echo "You have uncommitted changes. Please commit or stash these:"
169 CHANGEID
=$
(git log
--format=format
:%b
-1 HEAD|
grep Change-Id|cut
-d: -f2|
tr -d \
)
170 if test -z "$CHANGEID"
172 CHANGEID
="NOCHANGEID"
174 BACKUPBRANCH
=backup
/$CHANGEID-$
(date +%F-
%H
%M
%S
)
175 git branch
"$BACKUPBRANCH"
176 echo "current state backed up as $BACKUPBRANCH"
180 BRANCH
=$
(git symbolic-ref HEAD
2> /dev
/null
)
181 BRANCH
="${BRANCH##refs/heads/}"
184 echo "no branch specified, and could not guess the current branch"
187 echo "no branch specified, guessing current branch $BRANCH"
189 git
reset --hard "remotes/origin/$BRANCH"
192 get_SHA_for_change
"$2"
193 git fetch
"$GERRITURL" "$SHA" && git checkout FETCH_HEAD
196 echo "'./logerrit review' has been removed as obsolete."
197 echo "Please use either:"
198 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
199 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
200 echo "Both provide a better experience."
204 get_SHA_for_change
"$2"
205 git pull
"$GERRITURL" "$SHA"
208 get_SHA_for_change
"$2"
209 git fetch
"$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
212 get_SHA_for_change
"$2"
213 git fetch
"$GERRITURL" "$SHA" && git format-patch
-1 --stdout FETCH_HEAD
217 ssh "${GERRITHOST?}" gerrit query project
:core
"${@@Q}"
221 if test -n "$3" -a \
( ${#3} -ne 41 -o -n "${CHANGEID//[0-9a-f]/}" \
)
223 echo "${3} is not a valid Gerrit change id"
231 BRANCH
=$
(git symbolic-ref HEAD
2> /dev
/null
)
232 BRANCH
="${BRANCH##refs/heads/}"
235 echo "no branch specified, and could not guess the current branch"
238 echo "no branch specified, guessing current branch $BRANCH"
240 BRANCH
="${BRANCH##feature/}"
242 if test -z "$WORKDIR"
244 echo "could not create work directory."
247 echo "workdir at $WORKDIR"
248 git clone
-s "$(dirname "$0")" "$WORKDIR/core"
250 pushd "$WORKDIR/core" ||
{ echo "Changing directory failed."; exit 1; }
251 echo "noop commit: trigger test build for branch feature/$BRANCH" > ..
/commitmsg
253 echo "branch is at:" >> ..
/commitmsg
255 git log
-1|
sed -e "s/Change-Id:/XXXXXX:/" >> ..
/commitmsg
256 if test -n "$CHANGEID"
259 echo "Change-Id: $CHANGEID" >> ..
/commitmsg
261 git fetch https
://git.libreoffice.org
/core
"feature/$BRANCH" && \
262 git checkout
-b featuretst FETCH_HEAD
&& \
263 cp -a .git-hooks
/* .git
/hooks
&& \
264 git commit
--allow-empty -F ..
/commitmsg
&& \
265 git push
"$GERRITURL" "HEAD:refs/for/feature/$BRANCH"
266 popd ||
{ echo "Changing directory failed."; exit 1; }
268 rm -rf "$WORKDIR/core"
269 rm -f "$WORKDIR/commitmsg"
273 ssh "${GERRITHOST?}" gerrit
"${@@Q}"
277 # vim: set noet sw=4 ts=4: