summaryrefslogtreecommitdiff
path: root/logerrit
blob: 68bf2ccbbc80232800a133cdb9c6c2b5249a3c5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh

#GERRITHOST=gerrit.libreoffice.org
GERRITHOST=logerrit
GERRITURL=ssh://$GERRITHOST/core

get_SHA_for_change() {
    SHA=`ssh ${GERRITHOST?} gerrit query --all-approvals change:$1|grep ref|tail -1|cut -d: -f2`
}

submit() {
        TYPE=$1
        BRANCH=$2
        if test -z "$BRANCH"
        then
            BRANCH=`git symbolic-ref HEAD 2> /dev/null`
            BRANCH="${BRANCH##refs/heads/}"
            if test -z "$BRANCH"
            then
                echo "no branch specified, and could not guess the current branch"
                exit 1
            fi
            echo "no branch specified, guessing current branch $BRANCH"
        fi
        git push $GERRITURL HEAD:refs/$TYPE/$BRANCH
}

case "$1" in
    help|--help|"")
        echo "Usage: ./logerrit subcommand [options]"
        echo "simple and basic tool to interact with LibreOffice gerrit"
        echo "subcommands:"
        echo "             setup                   walking you though your gerrit setup"
        echo "             test                    test your gerrit setup"
        echo
        echo " --- for submitters:"
        echo "             submit [BRANCH]         submit your change for review"
        echo "             resubmit [BRANCH]       create a new Change-Id and submit your change for review"
        echo "                                     (yes, this modifies your last commit)"
        echo "             submit-draft [BRANCH]   submit your change as draft"
        echo "             resubmit-draft [BRANCH] create a new Change-Id and submit your change as draft"
        echo "                                     (yes, this modifies your last commit)"
        echo "                                     (yes, this modifies your last commit)"
        echo "             nextchange [BRANCH]     reset branch to the remote to start with the next change"
        echo "Note: drafts are only visibly to yourself and those that you explicitly add as reviewers."
        echo
        echo " --- for reviewers:"
        echo "             checkout CHANGEID       checkout the changes for review"
        echo "             pull CHANGEID           pull (and merge) the changes on current branch"
        echo "             cherry-pick CHANGEID    cherry-pick the change on current branch"
        echo "             patch CHANGEID          show the change as a patch"
        echo "             query ....              query for changes for review on project core"
        echo "             <any other gerrit command>"
        echo
        echo "advanced users should consider using git review instead:"
        echo "http://wiki.documentfoundation.org/Development/GitReview"
        exit
    ;;
    setup)
        cd $(dirname $(readlink -f $0))
        echo "Please go to https://gerrit.libreoffice.org/ and:"
        echo "- press the 'register' button in the top right corner"
        echo "- after login set yourself a username (its recommended to use your IRC-nick)"
        echo "- upload your public ssh-key."
        echo
        echo "Note that you need to register additional email addresses, if you want to"
        echo "commit from them. Additional emails must be confirmed with repling to the"
        echo "invitation mail it sends you."
        echo
        read -p 'Which user name did you choose? ' GERRITUSER
        echo
        echo "Please now add the following to your ~/.ssh/config, creating the file if needed:"
        echo
        echo "Host logerrit"
        echo "    IdentityFile ~/.ssh/id_rsa"
        echo "    User $GERRIUSER"
        echo "    Port 29418"
        echo "    HostName gerrit.libreoffice.org"
        echo "Host gerrit.libreoffice.org"
        echo "    IdentityFile ~/.ssh/id_rsa"
        echo "    User $GERRIUSER"
        echo "    Port 29418"
        echo "    HostName gerrit.libreoffice.org"
        echo
        echo "To see if your setup was successful, run './logerrit test' then."
        # a good place to make sure the hooks are set up
        ./g -z
    ;;
    test)
        if test -n "`ssh $GERRITHOST 2>&1|grep \"Welcome to Gerrit Code Review\"`"
        then
            echo "Your gerrit setup was successful!"
        else
            echo "There seems to be trouble."
            echo "please have the output of: ssh -vvvv logerrit"
            echo "at hand when looking for help."
        fi
    ;;
    submit)
        submit 'for' $2
    ;;
    resubmit)
        git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
        submit 'for' $2
    ;;
    submit-draft)
        submit drafts $2
    ;;
    resubmit-draft)
        git log -1 --pretty=%B | grep -v ^Change-Id: | git commit --amend -F -
        submit drafts $2
    ;;
    nextchange)
        if test -n "`git status -s -uno`"
        then
            echo "You have uncommitted changes. Please commit or stash these:"
            git status
            exit 1
        fi
        CHANGEID=`git log --format=format:%b -1 HEAD|grep Change-Id|cut -d: -f2|tr -d \ `
        if test -z "$CHANGEID"
        then
            CHANGEID="NOCHANGEID"
        fi
        BACKUPBRANCH=backup/$CHANGEID-`date +%F-%H%M%S`
        git branch $BACKUPBRANCH
        echo "current state backed up as $BACKUPBRANCH"
        BRANCH=$2
        if test -z "$BRANCH"
        then
            BRANCH=`git symbolic-ref HEAD 2> /dev/null`
            BRANCH="${BRANCH##refs/heads/}"
            if test -z "$BRANCH"
            then
                echo "no branch specified, and could not guess the current branch"
                exit 1
            fi
            echo "no branch specified, guessing current branch $BRANCH"
        fi
        git reset --hard remotes/origin/$BRANCH
    ;;
    checkout)
        get_SHA_for_change $2
        git fetch $GERRITURL $SHA && git checkout FETCH_HEAD
    ;;
    review)
        echo "'./logerrit review' has be removed as obsolete."
        echo "Please use either:"
        echo " - git-review:              https://wiki.documentfoundation.org/Development/GitReview"
        echo " - or the web-UI directly:  https://gerrit.libreoffice.org/"
        echo "Both provide a better experience."
        exit 1;
    ;;
    pull)
        get_SHA_for_change $2
        git pull $GERRITURL $SHA
    ;;
    cherry-pick)
        get_SHA_for_change $2
        git fetch $GERRITURL $SHA && git cherry-pick FETCH_HEAD
    ;;
    patch)
        get_SHA_for_change $2
        git fetch $GERRITURL $SHA && git format-patch -1 --stdout FETCH_HEAD
    ;;
    query)
        shift
        ssh ${GERRITHOST?} gerrit query project:core $@
    ;;
    *)
        ssh ${GERRITHOST?} gerrit $@
    ;;
esac