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 <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
changes/17/951917/2
Aaron Gable 8 years ago committed by Commit Bot
parent ccd62f4e56
commit 8797cab3ef

@ -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):

@ -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),

Loading…
Cancel
Save