blob: 9e7f2b87fd1eea9680212e261b87aeae0c0a5ef0 [file] [log] [blame]
Bjoern Michaelsenfe49f232012-06-20 15:42:27 -05001#!/bin/sh
2
3#GERRITHOST=gerrit.libreoffice.org
4GERRITHOST=logerrit
5GERRITURL=ssh://$GERRITHOST/core
6
7get_SHA_for_change() {
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +01008 SHA=`ssh ${GERRITHOST?} gerrit query --all-approvals change:$1|grep ref|tail -1|cut -d: -f2`
Bjoern Michaelsenfe49f232012-06-20 15:42:27 -05009}
10
Bjoern Michaelsen4e158092012-07-25 01:13:53 +020011submit() {
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +010012 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 Michaelsen4e158092012-07-25 01:13:53 +020026}
27
Michael Meekse8943d62013-03-27 17:26:23 +000028logerrit() {
Mathieu Parentb4f3b352014-10-03 12:46:36 +020029 echo "Host logerrit gerrit.libreoffice.org"
Michael Meekse8943d62013-03-27 17:26:23 +000030 echo " IdentityFile ~/.ssh/id_rsa"
31 echo " User $1"
32 echo " Port 29418"
33 echo " HostName gerrit.libreoffice.org"
34}
35
Bjoern Michaelsenfe49f232012-06-20 15:42:27 -050036case "$1" in
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +010037 help|--help|"")
38 echo "Usage: ./logerrit subcommand [options]"
39 echo "simple and basic tool to interact with LibreOffice gerrit"
Bjoern Michaelsenb910d1d2013-03-29 02:03:56 +010040 echo "see https://wiki.documentfoundation.org/Development/gerrit for details."
41 echo
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +010042 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"
48 echo " resubmit [BRANCH] create a new Change-Id and submit your change for review"
49 echo " (yes, this modifies your last commit)"
50 echo " submit-draft [BRANCH] submit your change as draft"
51 echo " resubmit-draft [BRANCH] create a new Change-Id and submit your change as draft"
52 echo " (yes, this modifies your last commit)"
53 echo " (yes, this modifies your last commit)"
54 echo " nextchange [BRANCH] reset branch to the remote to start with the next change"
55 echo "Note: drafts are only visibly to yourself and those that you explicitly add as reviewers."
56 echo
57 echo " --- for reviewers:"
58 echo " checkout CHANGEID checkout the changes for review"
59 echo " pull CHANGEID pull (and merge) the changes on current branch"
60 echo " cherry-pick CHANGEID cherry-pick the change on current branch"
61 echo " patch CHANGEID show the change as a patch"
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +010062 echo " query .... query for changes for review on project core"
63 echo " <any other gerrit command>"
64 echo
65 echo "advanced users should consider using git review instead:"
66 echo "http://wiki.documentfoundation.org/Development/GitReview"
67 exit
68 ;;
Bjoern Michaelsen646b9922013-03-26 15:26:20 +010069 setup)
Bjoern Michaelsen8c8dc542013-03-26 23:20:56 +010070 cd $(dirname $(readlink -f $0))
Michael Meekse8943d62013-03-27 17:26:23 +000071 ssh_home="$HOME/.ssh";
72 ssh_key=
73 created_ssh=
74 if ! test -d $ssh_home; then
75 echo "It appears that you have no ssh setup, running ssh-keygen to create that:"
76 mkdir $ssh_home
77 chmod 0700 $ssh_home
78 created_ssh=TRUE
79 echo
80 echo "Hit enter to generate an ssh key - you will need to enter a pass-phrase"
81 echo
82 read
83 ssh-keygen -t rsa -f "$ssh_home/id_rsa"
84 fi
85 if test -d $ssh_home; then
86 if test -f "$ssh_home/id_rsa.pub"; then
87 ssh_key=`cat $ssh_home/id_rsa.pub`;
88 elif test -f "$ssh_home/id_dsa.pub"; then
89 ssh_key=`cat $ssh_home/id_dsa.pub`;
90 fi
91 fi
Bjoern Michaelsen646b9922013-03-26 15:26:20 +010092 echo "Please go to https://gerrit.libreoffice.org/ and:"
Bjoern Michaelsen53a536c2013-03-26 23:15:11 +010093 echo "- press the 'register' button in the top right corner"
Bjoern Michaelsen646b9922013-03-26 15:26:20 +010094 echo "- after login set yourself a username (its recommended to use your IRC-nick)"
Michael Meekse8943d62013-03-27 17:26:23 +000095 if test "z$ssh_key" = "z"; then
96 echo "- add your public ssh-key into the ssh keys settings."
97 else
98 echo "- paste the key below into the 'Add SSH Public Key' box."
99 echo
100 echo "$ssh_key"
101 echo
102 fi
Bjoern Michaelsen646b9922013-03-26 15:26:20 +0100103 echo
104 echo "Note that you need to register additional email addresses, if you want to"
105 echo "commit from them. Additional emails must be confirmed with repling to the"
Miklos Vajna1ed42102013-03-26 16:21:37 +0100106 echo "invitation mail it sends you."
Bjoern Michaelsen646b9922013-03-26 15:26:20 +0100107 echo
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100108 read -p 'Which user name did you choose? ' GERRITUSER
Michael Meekse8943d62013-03-27 17:26:23 +0000109 if test "z$created_ssh" = "z"; then
110 echo
111 echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
112 echo
113 logerrit $GERRITUSER
114 echo
115 else
116 echo "Automatically creating your ssh config"
117 (logerrit $GERRITUSER) > "$ssh_home/config"
118 fi
119 # setup the remote properly ...
120 git config remote.origin.pushurl ssh://logerrit/core
Bjoern Michaelsen646b9922013-03-26 15:26:20 +0100121 echo "To see if your setup was successful, run './logerrit test' then."
Bjoern Michaelsen8c8dc542013-03-26 23:20:56 +0100122 # a good place to make sure the hooks are set up
123 ./g -z
Bjoern Michaelsen646b9922013-03-26 15:26:20 +0100124 ;;
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100125 test)
126 if test -n "`ssh $GERRITHOST 2>&1|grep \"Welcome to Gerrit Code Review\"`"
127 then
128 echo "Your gerrit setup was successful!"
129 else
130 echo "There seems to be trouble."
131 echo "please have the output of: ssh -vvvv logerrit"
132 echo "at hand when looking for help."
133 fi
134 ;;
135 submit)
136 submit 'for' $2
137 ;;
Bjoern Michaelsen4e158092012-07-25 01:13:53 +0200138 resubmit)
139 git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100140 submit 'for' $2
Bjoern Michaelsen4e158092012-07-25 01:13:53 +0200141 ;;
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100142 submit-draft)
143 submit drafts $2
144 ;;
145 resubmit-draft)
146 git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
147 submit drafts $2
148 ;;
149 nextchange)
150 if test -n "`git status -s -uno`"
151 then
152 echo "You have uncommitted changes. Please commit or stash these:"
153 git status
154 exit 1
155 fi
156 CHANGEID=`git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ `
157 if test -z "$CHANGEID"
158 then
159 CHANGEID="NOCHANGEID"
160 fi
161 BACKUPBRANCH=backup/$CHANGEID-`date +%F-%H%M%S`
162 git branch $BACKUPBRANCH
163 echo "current state backed up as $BACKUPBRANCH"
164 BRANCH=$2
165 if test -z "$BRANCH"
166 then
167 BRANCH=`git symbolic-ref HEAD 2> /dev/null`
168 BRANCH="${BRANCH##refs/heads/}"
169 if test -z "$BRANCH"
170 then
171 echo "no branch specified, and could not guess the current branch"
172 exit 1
173 fi
174 echo "no branch specified, guessing current branch $BRANCH"
175 fi
176 git reset --hard remotes/origin/$BRANCH
177 ;;
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100178 checkout)
179 get_SHA_for_change $2
180 git fetch $GERRITURL $SHA && git checkout FETCH_HEAD
181 ;;
Bjoern Michaelsend588e1c2013-03-26 23:26:06 +0100182 review)
183 echo "'./logerrit review' has be removed as obsolete."
184 echo "Please use either:"
185 echo " - git-review: https://wiki.documentfoundation.org/Development/GitReview"
186 echo " - or the web-UI directly: https://gerrit.libreoffice.org/"
187 echo "Both provide a better experience."
188 exit 1;
189 ;;
Bjoern Michaelsen15e9f562013-03-26 15:39:55 +0100190 pull)
191 get_SHA_for_change $2
192 git pull $GERRITURL $SHA
193 ;;
194 cherry-pick)
195 get_SHA_for_change $2
196 git fetch $GERRITURL $SHA && git cherry-pick FETCH_HEAD
197 ;;
198 patch)
199 get_SHA_for_change $2
200 git fetch $GERRITURL $SHA && git format-patch -1 --stdout FETCH_HEAD
201 ;;
202 query)
203 shift
204 ssh ${GERRITHOST?} gerrit query project:core $@
205 ;;
206 *)
207 ssh ${GERRITHOST?} gerrit $@
208 ;;
Bjoern Michaelsenfe49f232012-06-20 15:42:27 -0500209esac