| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| Bjoern Michaelsen | fe49f23 | 2012-06-20 15:42:27 -0500 | [diff] [blame] | 2 | |
| 3 | #GERRITHOST=gerrit.libreoffice.org |
| 4 | GERRITHOST=logerrit |
| 5 | GERRITURL=ssh://$GERRITHOST/core |
| 6 | |
| 7 | get_SHA_for_change() { |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 8 | SHA=$(ssh ${GERRITHOST?} gerrit query --all-approvals change:$1|grep ref|tail -1|cut -d: -f2) |
| Bjoern Michaelsen | fe49f23 | 2012-06-20 15:42:27 -0500 | [diff] [blame] | 9 | } |
| 10 | |
| Bjoern Michaelsen | 4e15809 | 2012-07-25 01:13:53 +0200 | [diff] [blame] | 11 | submit() { |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 12 | TYPE=$1 |
| 13 | BRANCH=$2 |
| 14 | if test -z "$BRANCH" |
| 15 | then |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 16 | BRANCH=$(git symbolic-ref HEAD 2> /dev/null) |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 17 | BRANCH="${BRANCH##refs/heads/}" |
| 18 | if test -z "$BRANCH" |
| 19 | then |
| 20 | echo "no branch specified, and could not guess the current branch" |
| 21 | exit 1 |
| 22 | fi |
| 23 | echo "no branch specified, guessing current branch $BRANCH" |
| 24 | fi |
| 25 | git push $GERRITURL HEAD:refs/$TYPE/$BRANCH |
| Bjoern Michaelsen | 4e15809 | 2012-07-25 01:13:53 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 28 | logerrit() { |
| Mathieu Parent | b4f3b35 | 2014-10-03 12:46:36 +0200 | [diff] [blame] | 29 | echo "Host logerrit gerrit.libreoffice.org" |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 30 | echo " IdentityFile ~/.ssh/id_rsa" |
| 31 | echo " User $1" |
| 32 | echo " Port 29418" |
| 33 | echo " HostName gerrit.libreoffice.org" |
| 34 | } |
| 35 | |
| Bjoern Michaelsen | fe49f23 | 2012-06-20 15:42:27 -0500 | [diff] [blame] | 36 | case "$1" in |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 37 | help|--help|"") |
| 38 | echo "Usage: ./logerrit subcommand [options]" |
| 39 | echo "simple and basic tool to interact with LibreOffice gerrit" |
| Bjoern Michaelsen | b910d1d | 2013-03-29 02:03:56 +0100 | [diff] [blame] | 40 | echo "see https://wiki.documentfoundation.org/Development/gerrit for details." |
| 41 | echo |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 42 | echo "subcommands:" |
| 43 | echo " setup walking you though your gerrit setup" |
| 44 | echo " test test your gerrit setup" |
| 45 | echo |
| 46 | echo " --- for submitters:" |
| 47 | echo " submit [BRANCH] submit your change for review" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 48 | echo " submit-draft [BRANCH] submit your change as draft" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 49 | echo " nextchange [BRANCH] reset branch to the remote to start with the next change" |
| Bjoern Michaelsen | ef4fd9c | 2015-06-10 17:51:29 +0200 | [diff] [blame] | 50 | echo " testfeature [BRANCH] trigger a test of a feature branch on gerrit" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 51 | echo "Note: drafts are only visibly to yourself and those that you explicitly add as reviewers." |
| 52 | echo |
| 53 | echo " --- for reviewers:" |
| 54 | echo " checkout CHANGEID checkout the changes for review" |
| 55 | echo " pull CHANGEID pull (and merge) the changes on current branch" |
| 56 | echo " cherry-pick CHANGEID cherry-pick the change on current branch" |
| 57 | echo " patch CHANGEID show the change as a patch" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 58 | echo " query .... query for changes for review on project core" |
| 59 | echo " <any other gerrit command>" |
| 60 | echo |
| 61 | echo "advanced users should consider using git review instead:" |
| 62 | echo "http://wiki.documentfoundation.org/Development/GitReview" |
| 63 | exit |
| 64 | ;; |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 65 | setup) |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 66 | script_canonical_file=$(readlink -f "$0") |
| 67 | script_canonical_dir=$(dirname "$script_canonical_file") |
| 68 | if ! cd "$script_canonical_dir"; then |
| 69 | echo "Can't cd to $script_canonical_dir" |
| 70 | exit 1 |
| 71 | fi |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 72 | ssh_home="$HOME/.ssh"; |
| 73 | ssh_key= |
| 74 | created_ssh= |
| 75 | if ! test -d $ssh_home; then |
| 76 | echo "It appears that you have no ssh setup, running ssh-keygen to create that:" |
| 77 | mkdir $ssh_home |
| 78 | chmod 0700 $ssh_home |
| 79 | created_ssh=TRUE |
| 80 | echo |
| 81 | echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase" |
| 82 | echo |
| 83 | read |
| 84 | ssh-keygen -t rsa -f "$ssh_home/id_rsa" |
| 85 | fi |
| 86 | if test -d $ssh_home; then |
| 87 | if test -f "$ssh_home/id_rsa.pub"; then |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 88 | ssh_key=$(cat $ssh_home/id_rsa.pub); |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 89 | elif test -f "$ssh_home/id_dsa.pub"; then |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 90 | ssh_key=$(cat $ssh_home/id_dsa.pub); |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 91 | fi |
| 92 | fi |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 93 | echo "Please go to https://gerrit.libreoffice.org/ and:" |
| Bjoern Michaelsen | 53a536c | 2013-03-26 23:15:11 +0100 | [diff] [blame] | 94 | echo "- press the 'register' button in the top right corner" |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 95 | echo "- after login set yourself a username (its recommended to use your IRC-nick)" |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 96 | if test "z$ssh_key" = "z"; then |
| 97 | echo "- add your public ssh-key into the ssh keys settings." |
| 98 | else |
| 99 | echo "- paste the key below into the 'Add SSH Public Key' box." |
| 100 | echo |
| 101 | echo "$ssh_key" |
| 102 | echo |
| 103 | fi |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 104 | echo |
| 105 | echo "Note that you need to register additional email addresses, if you want to" |
| 106 | echo "commit from them. Additional emails must be confirmed with repling to the" |
| Miklos Vajna | 1ed4210 | 2013-03-26 16:21:37 +0100 | [diff] [blame] | 107 | echo "invitation mail it sends you." |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 108 | echo |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 109 | read -p 'Which user name did you choose? ' GERRITUSER |
| Michael Meeks | e8943d6 | 2013-03-27 17:26:23 +0000 | [diff] [blame] | 110 | if test "z$created_ssh" = "z"; then |
| 111 | echo |
| 112 | echo "Please now add the following to your ~/.ssh/config, creating the file if needed:" |
| 113 | echo |
| 114 | logerrit $GERRITUSER |
| 115 | echo |
| 116 | else |
| 117 | echo "Automatically creating your ssh config" |
| 118 | (logerrit $GERRITUSER) > "$ssh_home/config" |
| 119 | fi |
| 120 | # setup the remote properly ... |
| 121 | git config remote.origin.pushurl ssh://logerrit/core |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 122 | echo "To see if your setup was successful, run './logerrit test' then." |
| Bjoern Michaelsen | 8c8dc54 | 2013-03-26 23:20:56 +0100 | [diff] [blame] | 123 | # a good place to make sure the hooks are set up |
| 124 | ./g -z |
| Bjoern Michaelsen | 646b992 | 2013-03-26 15:26:20 +0100 | [diff] [blame] | 125 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 126 | test) |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 127 | if test -n "$(ssh $GERRITHOST 2>&1|grep "Welcome to Gerrit Code Review")" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 128 | then |
| 129 | echo "Your gerrit setup was successful!" |
| 130 | else |
| Shinnok | b9ddf19 | 2017-09-06 12:29:01 +0100 | [diff] [blame] | 131 | echo "There seems to be trouble. Please have the output of:" |
| 132 | echo "ssh -vvvv "$GERRITHOST |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 133 | echo "at hand when looking for help." |
| 134 | fi |
| 135 | ;; |
| 136 | submit) |
| 137 | submit 'for' $2 |
| 138 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 139 | submit-draft) |
| 140 | submit drafts $2 |
| 141 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 142 | nextchange) |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 143 | if test -n "$(git status -s -uno)" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 144 | then |
| 145 | echo "You have uncommitted changes. Please commit or stash these:" |
| 146 | git status |
| 147 | exit 1 |
| 148 | fi |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 149 | CHANGEID=$(git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ ) |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 150 | if test -z "$CHANGEID" |
| 151 | then |
| 152 | CHANGEID="NOCHANGEID" |
| 153 | fi |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 154 | BACKUPBRANCH=backup/$CHANGEID-$(date +%F-%H%M%S) |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 155 | git branch $BACKUPBRANCH |
| 156 | echo "current state backed up as $BACKUPBRANCH" |
| 157 | BRANCH=$2 |
| 158 | if test -z "$BRANCH" |
| 159 | then |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 160 | BRANCH=$(git symbolic-ref HEAD 2> /dev/null) |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 161 | BRANCH="${BRANCH##refs/heads/}" |
| 162 | if test -z "$BRANCH" |
| 163 | then |
| 164 | echo "no branch specified, and could not guess the current branch" |
| 165 | exit 1 |
| 166 | fi |
| 167 | echo "no branch specified, guessing current branch $BRANCH" |
| 168 | fi |
| 169 | git reset --hard remotes/origin/$BRANCH |
| 170 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 171 | checkout) |
| 172 | get_SHA_for_change $2 |
| 173 | git fetch $GERRITURL $SHA && git checkout FETCH_HEAD |
| 174 | ;; |
| Bjoern Michaelsen | d588e1c | 2013-03-26 23:26:06 +0100 | [diff] [blame] | 175 | review) |
| 176 | echo "'./logerrit review' has be removed as obsolete." |
| 177 | echo "Please use either:" |
| 178 | echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview" |
| 179 | echo " - or the web-UI directly: https://gerrit.libreoffice.org/" |
| 180 | echo "Both provide a better experience." |
| 181 | exit 1; |
| 182 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 183 | pull) |
| 184 | get_SHA_for_change $2 |
| 185 | git pull $GERRITURL $SHA |
| 186 | ;; |
| 187 | cherry-pick) |
| 188 | get_SHA_for_change $2 |
| 189 | git fetch $GERRITURL $SHA && git cherry-pick FETCH_HEAD |
| 190 | ;; |
| 191 | patch) |
| 192 | get_SHA_for_change $2 |
| 193 | git fetch $GERRITURL $SHA && git format-patch -1 --stdout FETCH_HEAD |
| 194 | ;; |
| 195 | query) |
| 196 | shift |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 197 | ssh ${GERRITHOST?} gerrit query project:core "$@" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 198 | ;; |
| Bjoern Michaelsen | ef4fd9c | 2015-06-10 17:51:29 +0200 | [diff] [blame] | 199 | testfeature) |
| 200 | BRANCH=$2 |
| 201 | if test -z "$BRANCH" |
| 202 | then |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 203 | BRANCH=$(git symbolic-ref HEAD 2> /dev/null) |
| Bjoern Michaelsen | ef4fd9c | 2015-06-10 17:51:29 +0200 | [diff] [blame] | 204 | BRANCH="${BRANCH##refs/heads/}" |
| 205 | if test -z "$BRANCH" |
| 206 | then |
| 207 | echo "no branch specified, and could not guess the current branch" |
| 208 | exit 1 |
| 209 | fi |
| 210 | echo "no branch specified, guessing current branch $BRANCH" |
| 211 | fi |
| 212 | BRANCH="${BRANCH##feature/}" |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 213 | WORKDIR=$(mktemp -d) |
| Bjoern Michaelsen | ef4fd9c | 2015-06-10 17:51:29 +0200 | [diff] [blame] | 214 | if test -z "$WORKDIR" |
| 215 | then |
| 216 | echo "could no create work directory." |
| 217 | exit 1 |
| 218 | fi |
| 219 | echo workdir at $WORKDIR |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 220 | git clone -s "$(dirname $0)" $WORKDIR/core |
| Bjoern Michaelsen | ef4fd9c | 2015-06-10 17:51:29 +0200 | [diff] [blame] | 221 | pushd $WORKDIR/core |
| 222 | echo "noop commit: trigger test build for branch feature/$BRANCH" > ../commitmsg |
| 223 | echo >> ../commitmsg |
| 224 | echo "branch is at:" >> ../commitmsg |
| 225 | git log -1|sed -e "s/Change-Id:/XXXXXX:/" >> ../commitmsg |
| 226 | git fetch git://gerrit.libreoffice.org/core.git feature/$BRANCH && \ |
| 227 | git checkout -b featuretst FETCH_HEAD && \ |
| 228 | cp -a .git-hooks/* .git/hooks |
| 229 | git commit --allow-empty -F ../commitmsg && \ |
| 230 | git push $GERRITURL HEAD:refs/for/feature/$BRANCH |
| 231 | popd |
| 232 | rm -rf $WORKDIR/core |
| 233 | ;; |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 234 | *) |
| qarkai | d33d2a6 | 2017-01-15 14:20:22 +0300 | [diff] [blame] | 235 | ssh ${GERRITHOST?} gerrit "$@" |
| Bjoern Michaelsen | 15e9f56 | 2013-03-26 15:39:55 +0100 | [diff] [blame] | 236 | ;; |
| Bjoern Michaelsen | fe49f23 | 2012-06-20 15:42:27 -0500 | [diff] [blame] | 237 | esac |