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