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/^ *//')
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}/||"
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"
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"
44 git push
"$GERRITURL" "HEAD:refs/for/$BRANCH$TYPE"
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"
54 echo " HostName gerrit.libreoffice.org"
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."
64 echo " setup walking you though your gerrit setup"
65 echo " test test your gerrit setup"
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"
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"
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>"
86 echo "advanced users should consider using git review instead:"
87 echo "https://wiki.documentfoundation.org/Development/GitReview"
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"
97 ssh_home
="$HOME/.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"
105 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
108 all_algo
="$(ssh -Q key)"
109 if grep -q -x ssh-ed25519
<<< "$all_algo"; then
111 elif grep -q -x ssh-rsa
<<< "$all_algo"; then
114 echo "Could not find 'ssh-ed25519' or 'ssh-rsa' in the output from 'ssh -Q key'"
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"
124 if test -f "$pk" && ssh_key
="$(< "$pk")" && test -n "$ssh_key"; then
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."
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."
138 echo "key below in the 'New SSH key' form."
140 printf '%s\n' "$ssh_key"
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."
148 read -r -p 'Which user name did you choose? ' GERRITUSER
149 if test -z "$created_ssh"; then
151 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
153 logerrit
"$GERRITUSER" ${ssh_key:+"$ssh_key_type"}
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
166 if test -n "$(ssh "$GERRITHOST" 2>&1|grep "Welcome to Gerrit Code Review
")"; then
167 echo "Your gerrit setup was successful!"
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."
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"
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"
201 echo "no branch specified, guessing current branch $BRANCH"
203 git
reset --hard "remotes/origin/$BRANCH"
206 get_SHA_for_change
"$2"
207 git fetch
"$GERRITURL" "$SHA" && git checkout FETCH_HEAD
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."
218 get_SHA_for_change
"$2"
219 git pull
"$GERRITURL" "$SHA"
222 get_SHA_for_change
"$2"
223 git fetch
"$GERRITURL" "$SHA" && git cherry-pick FETCH_HEAD
226 get_SHA_for_change
"$2"
227 git fetch
"$GERRITURL" "$SHA" && git format-patch
-1 --stdout FETCH_HEAD
231 ssh "${GERRITHOST?}" gerrit query project
:core
"${@@Q}"
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"
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"
252 echo "no branch specified, guessing current branch $BRANCH"
254 BRANCH
="${BRANCH##feature/}"
256 if test -z "$WORKDIR"; then
257 echo "could not create work directory."
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
266 echo "branch is at:" >> ..
/commitmsg
268 git log
-1|
sed -e "s/Change-Id:/XXXXXX:/" >> ..
/commitmsg
269 if test -n "$CHANGEID"; then
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"
285 ssh "${GERRITHOST?}" gerrit
"${@@Q}"
289 # vim: set noet sw=4 ts=4: