From 8797cab3efd9e207f40a6e86aca66c369ed7b8e2 Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Tue, 6 Mar 2018 13:55:00 -0800 Subject: [PATCH] git-cl: respect http.cookieFile for finding gitcookies This allows people to configure their gitcookies file to be whereever they want. As long as it actually exists and has credentials in it, we'll accept it, just like git itself. Change-Id: I4aa4806ddca0e61b28b003b0d3bc486407c13ab4 Reviewed-on: https://chromium-review.googlesource.com/951917 Reviewed-by: Robbie Iannucci Commit-Queue: Aaron Gable --- gerrit_util.py | 7 ++++++- tests/git_cl_test.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gerrit_util.py b/gerrit_util.py index fac982314c..6bebdea197 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -27,6 +27,7 @@ import urlparse from cStringIO import StringIO import gclient_utils +import subprocess2 from third_party import httplib2 LOGGER = logging.getLogger() @@ -166,7 +167,11 @@ class CookiesAuthenticator(Authenticator): def get_gitcookies_path(cls): if os.getenv('GIT_COOKIES_PATH'): return os.getenv('GIT_COOKIES_PATH') - return os.path.join(os.environ['HOME'], '.gitcookies') + try: + return subprocess2.check_output( + ['git', 'config', '--path', 'http.cookiefile']).strip() + except subprocess2.CalledProcessError: + return os.path.join(os.environ['HOME'], '.gitcookies') @classmethod def _get_gitcookies(cls): diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index d41306e54a..ae7621c8dc 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -3455,6 +3455,7 @@ class TestGitCl(TestCase): self.mock(git_cl._GitCookiesChecker, 'get_hosts_with_creds', lambda _, include_netrc=False: []) self.calls = [ + ((['git', 'config', '--path', 'http.cookiefile'],), CERR1), ((['git', 'config', '--global', 'http.cookiefile'],), CERR1), (('os.path.exists', '~/.netrc'), True), (('ask_for_data', 'Press Enter to setup .gitcookies, ' @@ -3475,6 +3476,7 @@ class TestGitCl(TestCase): self.mock(git_cl._GitCookiesChecker, 'get_hosts_with_creds', lambda _, include_netrc=False: []) self.calls = [ + ((['git', 'config', '--path', 'http.cookiefile'],), CERR1), ((['git', 'config', '--global', 'http.cookiefile'],), '/custom/.gitcookies'), (('os.path.exists', '/custom/.gitcookies'), False),