@ -3443,7 +3443,22 @@ def GetRietveldCodereviewSettingsInteractively():
' run-post-upload-hook ' , False )
' run-post-upload-hook ' , False )
def _ensure_default_gitcookies_path ( configured_path , default_path ) :
class _GitCookiesChecker ( object ) :
""" Provides facilties for validating and suggesting fixes to .gitcookies. """
def ensure_configured_gitcookies ( self ) :
""" Runs checks and suggests fixes to make git use .gitcookies from default
path . """
default = gerrit_util . CookiesAuthenticator . get_gitcookies_path ( )
configured_path = RunGitSilent (
[ ' config ' , ' --global ' , ' http.cookiefile ' ] ) . strip ( )
if configured_path :
self . _ensure_default_gitcookies_path ( configured_path , default )
else :
self . _configure_gitcookies_path ( default )
@staticmethod
def _ensure_default_gitcookies_path ( configured_path , default_path ) :
assert configured_path
assert configured_path
if configured_path == default_path :
if configured_path == default_path :
print ( ' git is already configured to use your .gitcookies from %s ' %
print ( ' git is already configured to use your .gitcookies from %s ' %
@ -3462,7 +3477,8 @@ def _ensure_default_gitcookies_path(configured_path, default_path):
return
return
if os . path . exists ( default_path ) :
if os . path . exists ( default_path ) :
print ( ' WARNING: default .gitcookies file already exists %s ' % default_path )
print ( ' WARNING: default .gitcookies file already exists %s ' %
default_path )
DieWithError ( ' Please delete %s manually and re-run git cl creds-check ' %
DieWithError ( ' Please delete %s manually and re-run git cl creds-check ' %
default_path )
default_path )
@ -3470,10 +3486,11 @@ def _ensure_default_gitcookies_path(configured_path, default_path):
action = ' move ' )
action = ' move ' )
shutil . move ( configured_path , default_path )
shutil . move ( configured_path , default_path )
RunGit ( [ ' config ' , ' --global ' , ' http.cookiefile ' , default_path ] )
RunGit ( [ ' config ' , ' --global ' , ' http.cookiefile ' , default_path ] )
print ( ' Moved and reconfigured git to use .gitcookies from %s ' % default_path )
print ( ' Moved and reconfigured git to use .gitcookies from %s ' %
default_path )
def _configure_gitcookies_path ( gitcookies_path ) :
@staticmethod
def _configure_gitcookies_path ( default_path ) :
netrc_path = gerrit_util . CookiesAuthenticator . get_netrc_path ( )
netrc_path = gerrit_util . CookiesAuthenticator . get_netrc_path ( )
if os . path . exists ( netrc_path ) :
if os . path . exists ( netrc_path ) :
print ( ' You seem to be using outdated .netrc for git credentials: %s ' %
print ( ' You seem to be using outdated .netrc for git credentials: %s ' %
@ -3483,10 +3500,10 @@ def _configure_gitcookies_path(gitcookies_path):
' \n '
' \n '
' IMPORTANT: If something goes wrong and you decide to go back, do: \n '
' IMPORTANT: If something goes wrong and you decide to go back, do: \n '
' git config --global --unset http.cookiefile \n '
' git config --global --unset http.cookiefile \n '
' mv %s %s .backup \n \n ' % ( gitcookies_path, gitcookies _path) )
' mv %s %s .backup \n \n ' % ( default_path, default _path) )
confirm_or_exit ( action = ' setup .gitcookies ' )
confirm_or_exit ( action = ' setup .gitcookies ' )
RunGit ( [ ' config ' , ' --global ' , ' http.cookiefile ' , gitcookies _path] )
RunGit ( [ ' config ' , ' --global ' , ' http.cookiefile ' , default _path] )
print ( ' Configured git to use .gitcookies from %s ' % gitcookies _path)
print ( ' Configured git to use .gitcookies from %s ' % default _path)
def CMDcreds_check ( parser , args ) :
def CMDcreds_check ( parser , args ) :
@ -3496,13 +3513,8 @@ def CMDcreds_check(parser, args):
if gerrit_util . GceAuthenticator . is_gce ( ) :
if gerrit_util . GceAuthenticator . is_gce ( ) :
DieWithError ( ' this command is not designed for GCE, are you on a bot? ' )
DieWithError ( ' this command is not designed for GCE, are you on a bot? ' )
gitcookies_path = gerrit_util . CookiesAuthenticator . get_gitcookies_path ( )
checker = _GitCookiesChecker ( )
configured_gitcookies_path = RunGitSilent (
checker . ensure_configured_gitcookies ( )
[ ' config ' , ' --global ' , ' http.cookiefile ' ] ) . strip ( )
if configured_gitcookies_path :
_ensure_default_gitcookies_path ( configured_gitcookies_path , gitcookies_path )
else :
_configure_gitcookies_path ( gitcookies_path )
# TODO(tandrii): finish this.
# TODO(tandrii): finish this.
return 0
return 0