From 22cdd15b5d8613a7fbc548b7f840e107d8790de1 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 14 Oct 2011 10:12:04 -0400 Subject: [PATCH] Check .gitreview file in repo for location of gerrit. Change-Id: I5f344bb28155c42538c4a93ea0cefbef999a2957 --- .gitreview | 4 ++++ README.md | 4 +++- doc/index.rst | 11 +++++++++++ git-review | 48 ++++++++++++++++++------------------------------ 4 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 .gitreview diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..2943161 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack-ci/git-review.git diff --git a/README.md b/README.md index c9bffc8..2a9dc99 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ git-review is a tool that helps submitting git branches to gerrit for review git-review, by default, looks for a git remote called gerrit, and submits the current branch to HEAD:refs/for/master at that remote. -For example, to set it to the OpenStack Compute (nova) project (assuming you have previously signed in to the [OpenStack Gerrit server](https://review.openstack.org) with your Launchpad account), you would do: +If the "gerrit" remote does not exist, git-review looks for a file called .gitreview at the root of the repository with information about the gerrit remote. + +If you want to manually create a gerrit remote, for example, to set it to the OpenStack Compute (nova) project (assuming you have previously signed in to the [OpenStack Gerrit server](https://review.openstack.org) with your Launchpad account), you would do: USERNAME=jsmith # Launchpad username here PROJECT=openstack/nova diff --git a/doc/index.rst b/doc/index.rst index a7795d5..5ab13fa 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -57,3 +57,14 @@ OPTIONS Turns on more verbose output. +PROJECT CONFIGURATION +--------------------- + +To use git-review with your project, it is recommended that you create +a file at the root of the repository called ".gitreview" and place +information about your gerrit installation in it. The format is:: + + [gerrit] + host=review.example.com + port=29418 + project=project.git diff --git a/git-review b/git-review index a9e10fc..708cf97 100755 --- a/git-review +++ b/git-review @@ -21,14 +21,13 @@ import json from distutils.version import StrictVersion from urlparse import urlparse - +import ConfigParser import os import sys import time import re - version = "1.2" VERBOSE = False @@ -117,7 +116,7 @@ def add_remote(username, hostname, port, project): if port is None: port = 29418 - remote_url = "ssh://%s@%s:%s/%s.git" % (username, hostname, port, project) + remote_url = "ssh://%s@%s:%s/%s" % (username, hostname, port, project) if VERBOSE: print "No remote set, testing %s" % remote_url @@ -155,30 +154,6 @@ def split_hostname(fetch_url): return (None, hostname, None) -def map_known_locations(hostname, team, project): - # Assume that if we don't know about it, it's a proper gerrit location - if VERBOSE: - print "Mapping %s, %s, %s to a gerrit" % (hostname, team, project) - - if hostname == "github.com": - # Welp, OBVIOUSLY _this_ isn't a gerrit - if team is not None and team in ("openstack", "openstack-ci"): - return ("review.openstack.org", "%s/%s" % (team, project)) - - os_github_url = "http://github.com/api/v2/json/repos/show/openstack" - os_projects_file = os.path.join(CONFIGDIR, "openstack.json") - os_json = json.load(urllib.urlopen(os_github_url)) - os_projects = [] - if os_json.get('repositories', None) is not None: - os_projects = [repo['name'] for repo in os_json['repositories']] - - if project in os_projects: - return ("review.openstack.org", "openstack/%s" % project) - else: - raise Exception("No possible way to guess given the input") - return hostname - - def parse_git_show(remote, verb): fetch_url = "" for line in run_command("git remote show -n %s" % remote).split("\n"): @@ -228,12 +203,25 @@ def check_remote(remote): print output return - (hostname, team, username, port, project_name) = \ - parse_git_show("origin", "Fetch") + # Check for a .gitreview at the top of the repo with the gerrit location + top_dir = run_command('git rev-parse --show-toplevel') + target_file = os.path.join(top_dir, ".gitreview") + + if os.path.exists(target_file): + config = ConfigParser.ConfigParser(dict(port='29418')) + config.read(target_file) + hostname = config.get("gerrit", "host") + port = config.get("gerrit", "port") + project = config.get("gerrit", "project") + username = None + else: + print "No '.gitreview' file found in this repository." + print "We don't know where your gerrit is. Please manually create " + print "a remote named gerrit and try again." + sys.exit(1) # Gerrit remote not present, try to add it try: - (hostname, project) = map_known_locations(hostname, team, project_name) add_remote(username, hostname, port, project) except: print sys.exc_info()[2]