From e90565215dde7c8e28ca191e9a131b36c21907e2 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 19 Nov 2011 17:58:54 -0800 Subject: [PATCH] Check git config for default username. Let users specify a (global) default username for git-review by using git config. Change-Id: I1a8df009e2b1b7cf67cac04255a039625c5efa09 --- git-review | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/git-review b/git-review index 2c7411f..fca98fe 100755 --- a/git-review +++ b/git-review @@ -143,10 +143,13 @@ def make_remote_url(username, hostname, port, project): def add_remote(username, hostname, port, project): """ Adds a gerrit remote. """ + asked_for_username = False - if username is None: + if not 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") if port is None: port = 29418 @@ -161,6 +164,7 @@ def add_remote(username, hostname, port, project): print "Trying again with %s" % remote_url if not test_remote(username, hostname, port, project): 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 "\t%s" % remote_url @@ -170,6 +174,13 @@ def add_remote(username, hostname, port, project): if status != 0: 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):