Commit 8797cab3 authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

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/951917Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent ccd62f4e
......@@ -27,6 +27,7 @@ import urlparse
from cStringIO import StringIO
import gclient_utils
import subprocess2
from third_party import httplib2
LOGGER = logging.getLogger()
......@@ -166,6 +167,10 @@ class CookiesAuthenticator(Authenticator):
def get_gitcookies_path(cls):
if os.getenv('GIT_COOKIES_PATH'):
return os.getenv('GIT_COOKIES_PATH')
try:
return subprocess2.check_output(
['git', 'config', '--path', 'http.cookiefile']).strip()
except subprocess2.CalledProcessError:
return os.path.join(os.environ['HOME'], '.gitcookies')
@classmethod
......
......@@ -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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment