Check git config for default username.
Let users specify a (global) default username for git-review by using git config. Change-Id: I1a8df009e2b1b7cf67cac04255a039625c5efa09
This commit is contained in:
15
git-review
15
git-review
@@ -143,10 +143,13 @@ def make_remote_url(username, hostname, port, project):
|
|||||||
|
|
||||||
def add_remote(username, hostname, port, project):
|
def add_remote(username, hostname, port, project):
|
||||||
""" Adds a gerrit remote. """
|
""" Adds a gerrit remote. """
|
||||||
|
asked_for_username = False
|
||||||
|
|
||||||
if username is None:
|
if not username:
|
||||||
username = os.getenv("USERNAME")
|
username = os.getenv("USERNAME")
|
||||||
if username is None:
|
if not username:
|
||||||
|
username = run_command('git config --get gitreview.username')
|
||||||
|
if not username:
|
||||||
username = os.getenv("USER")
|
username = os.getenv("USER")
|
||||||
if port is None:
|
if port is None:
|
||||||
port = 29418
|
port = 29418
|
||||||
@@ -161,6 +164,7 @@ def add_remote(username, hostname, port, project):
|
|||||||
print "Trying again with %s" % remote_url
|
print "Trying again with %s" % remote_url
|
||||||
if not test_remote(username, hostname, port, project):
|
if not test_remote(username, hostname, port, project):
|
||||||
raise Exception("Could not connect to gerrit at %s" % remote_url)
|
raise Exception("Could not connect to gerrit at %s" % remote_url)
|
||||||
|
asked_for_username = True
|
||||||
|
|
||||||
print "Creating a git remote called gerrit that maps to:"
|
print "Creating a git remote called gerrit that maps to:"
|
||||||
print "\t%s" % remote_url
|
print "\t%s" % remote_url
|
||||||
@@ -170,6 +174,13 @@ def add_remote(username, hostname, port, project):
|
|||||||
if status != 0:
|
if status != 0:
|
||||||
raise Exception("Error running %s" % cmd)
|
raise Exception("Error running %s" % cmd)
|
||||||
|
|
||||||
|
if asked_for_username:
|
||||||
|
print
|
||||||
|
print "This repository is now set up for use with git-review."
|
||||||
|
print "You can set the default username for future repositories with:"
|
||||||
|
print ' git config --global --add gitreview.username "%s"' % username
|
||||||
|
print
|
||||||
|
|
||||||
|
|
||||||
def split_hostname(fetch_url):
|
def split_hostname(fetch_url):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user