Browse code

Add .gitreview config file for gerrit.

The CI team is developing a new tool, git-review:

https://github.com/openstack-ci/git-review

which is intendend to replace rfc.sh. This adds a .gitreview file
so that it can automatically determine the canonical gerrit location
for the repository when first run. Later, rfc.sh will be updated to
indicate it is deprecated, and then eventually removed.

Change-Id: I9f1be3e80aa40732ec500d329d31d3e880427a8a

James E. Blair authored on 2011/11/17 04:24:15
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+[gerrit]
1
+host=review.openstack.org
2
+port=29418
3
+project=openstack-dev/devstack.git
0 4
new file mode 100755
... ...
@@ -0,0 +1,145 @@
0
+#!/bin/sh -e
1
+# Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> 
2
+# This initial version of this file was taken from the source tree
3
+# of GlusterFS. It was not directly attributed, but is assumed to be
4
+# Copyright (c) 2010-2011 Gluster, Inc and release GPLv3
5
+# Subsequent modifications are Copyright (c) 2011 OpenStack, LLC.
6
+#
7
+# GlusterFS is free software; you can redistribute it and/or modify
8
+# it under the terms of the GNU General Public License as published
9
+# by the Free Software Foundation; either version 3 of the License,
10
+# or (at your option) any later version.
11
+#
12
+# GlusterFS is distributed in the hope that it will be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranty of
14
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+# General Public License for more details.
16
+#
17
+# You should have received a copy of the GNU General Public License
18
+# along with this program.  If not, see
19
+# <http://www.gnu.org/licenses/>.
20
+
21
+
22
+branch="master";
23
+
24
+set_hooks_commit_msg()
25
+{
26
+    top_dir=`git rev-parse --show-toplevel`
27
+    f="${top_dir}/.git/hooks/commit-msg";
28
+    u="https://review.openstack.org/tools/hooks/commit-msg";
29
+
30
+    if [ -x "$f" ]; then
31
+        return;
32
+    fi
33
+
34
+    curl -o $f $u || wget -O $f $u;
35
+
36
+    chmod +x $f;
37
+
38
+    GIT_EDITOR=true git commit --amend
39
+}
40
+
41
+add_remote()
42
+{
43
+    username=$1
44
+    project=$2
45
+
46
+    echo "No remote set, testing ssh://$username@review.openstack.org:29418"
47
+    if project_list=`ssh -p29418 -o StrictHostKeyChecking=no $username@review.openstack.org gerrit ls-projects 2>/dev/null`
48
+    then
49
+        echo "$username@review.openstack.org:29418 worked."
50
+        if echo $project_list | grep $project >/dev/null
51
+        then
52
+            echo "Creating a git remote called gerrit that maps to:"
53
+            echo "  ssh://$username@review.openstack.org:29418/$project"
54
+            git remote add gerrit ssh://$username@review.openstack.org:29418/$project
55
+        else
56
+            echo "The current project name, $project, is not a known project."
57
+            echo "Please either reclone from github/gerrit or create a"
58
+            echo "remote named gerrit that points to the intended project."
59
+            return 1
60
+        fi
61
+
62
+        return 0
63
+    fi
64
+    return 1
65
+}
66
+
67
+check_remote()
68
+{
69
+    if ! git remote | grep gerrit >/dev/null 2>&1
70
+    then
71
+        origin_project=`git remote show origin | grep 'Fetch URL' | perl -nle '@fields = split(m|[:/]|); $len = $#fields; print $fields[$len-1], "/", $fields[$len];'`
72
+        if add_remote $USERNAME $origin_project
73
+        then
74
+            return 0
75
+        else
76
+            echo "Your local name doesn't work on Gerrit."
77
+            echo -n "Enter Gerrit username (same as launchpad): "
78
+            read gerrit_user
79
+            if add_remote $gerrit_user $origin_project
80
+            then
81
+                return 0
82
+            else
83
+                echo "Can't infer where gerrit is - please set a remote named"
84
+                echo "gerrit manually and then try again."
85
+                echo
86
+                echo "For more information, please see:"
87
+                echo "\thttp://wiki.openstack.org/GerritWorkflow"
88
+                exit 1
89
+            fi
90
+        fi
91
+    fi
92
+}
93
+
94
+rebase_changes()
95
+{
96
+    git fetch;
97
+
98
+    GIT_EDITOR=true git rebase -i origin/$branch || exit $?;
99
+}
100
+
101
+
102
+assert_diverge()
103
+{
104
+    if ! git diff origin/$branch..HEAD | grep -q .
105
+    then
106
+	echo "No changes between the current branch and origin/$branch."
107
+	exit 1
108
+    fi
109
+}
110
+
111
+
112
+main()
113
+{
114
+    set_hooks_commit_msg;
115
+
116
+    check_remote;
117
+
118
+    rebase_changes;
119
+
120
+    assert_diverge;
121
+
122
+    bug=$(git show --format='%s %b' | perl -nle 'if (/\b([Bb]ug|[Ll][Pp])\s*[#:]?\s*(\d+)/) {print "$2"; exit}')
123
+
124
+    bp=$(git show --format='%s %b' | perl -nle 'if (/\b([Bb]lue[Pp]rint|[Bb][Pp])\s*[#:]?\s*([0-9a-zA-Z-_]+)/) {print "$2"; exit}')
125
+
126
+    if [ "$DRY_RUN" = 1 ]; then
127
+        drier='echo -e Please use the following command to send your commits to review:\n\n'
128
+    else
129
+        drier=
130
+    fi
131
+
132
+    local_branch=`git branch | grep -Ei "\* (.*)" | cut -f2 -d' '`
133
+    if [ -z "$bug" ]; then
134
+	if [ -z "$bp" ]; then
135
+            $drier git push gerrit HEAD:refs/for/$branch/$local_branch;
136
+	else
137
+	    $drier git push gerrit HEAD:refs/for/$branch/bp/$bp;
138
+	fi
139
+    else
140
+        $drier git push gerrit HEAD:refs/for/$branch/bug/$bug;
141
+    fi
142
+}
143
+
144
+main "$@"