2929 is_win ,
3030)
3131from git .exc import CommandError
32- from git .util import is_cygwin_git , cygpath , expand_path
32+ from git .util import is_cygwin_git , cygpath , expand_path , remove_password_if_present
3333
3434from .exc import (
3535 GitCommandError ,
@@ -83,8 +83,8 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
8383 line = line .decode (defenc )
8484 handler (line )
8585 except Exception as ex :
86- log .error ("Pumping %r of cmd(%s) failed due to: %r" , name , cmdline , ex )
87- raise CommandError (['<%s-pump>' % name ] + cmdline , ex ) from ex
86+ log .error ("Pumping %r of cmd(%s) failed due to: %r" , name , remove_password_if_present ( cmdline ) , ex )
87+ raise CommandError (['<%s-pump>' % name ] + remove_password_if_present ( cmdline ) , ex ) from ex
8888 finally :
8989 stream .close ()
9090
@@ -406,7 +406,7 @@ def read_all_from_possibly_closed_stream(stream):
406406 if status != 0 :
407407 errstr = read_all_from_possibly_closed_stream (self .proc .stderr )
408408 log .debug ('AutoInterrupt wait stderr: %r' % (errstr ,))
409- raise GitCommandError (self .args , status , errstr )
409+ raise GitCommandError (remove_password_if_present ( self .args ) , status , errstr )
410410 # END status handling
411411 return status
412412 # END auto interrupt
@@ -683,8 +683,10 @@ def execute(self, command,
683683 :note:
684684 If you add additional keyword arguments to the signature of this method,
685685 you must update the execute_kwargs tuple housed in this module."""
686+ # Remove password for the command if present
687+ redacted_command = remove_password_if_present (command )
686688 if self .GIT_PYTHON_TRACE and (self .GIT_PYTHON_TRACE != 'full' or as_process ):
687- log .info (' ' .join (command ))
689+ log .info (' ' .join (redacted_command ))
688690
689691 # Allow the user to have the command executed in their working dir.
690692 cwd = self ._working_dir or os .getcwd ()
@@ -705,7 +707,7 @@ def execute(self, command,
705707 if is_win :
706708 cmd_not_found_exception = OSError
707709 if kill_after_timeout :
708- raise GitCommandError (command , '"kill_after_timeout" feature is not supported on Windows.' )
710+ raise GitCommandError (redacted_command , '"kill_after_timeout" feature is not supported on Windows.' )
709711 else :
710712 if sys .version_info [0 ] > 2 :
711713 cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
@@ -720,7 +722,7 @@ def execute(self, command,
720722 if istream :
721723 istream_ok = "<valid stream>"
722724 log .debug ("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s, istream=%s)" ,
723- command , cwd , universal_newlines , shell , istream_ok )
725+ redacted_command , cwd , universal_newlines , shell , istream_ok )
724726 try :
725727 proc = Popen (command ,
726728 env = env ,
@@ -736,7 +738,7 @@ def execute(self, command,
736738 ** subprocess_kwargs
737739 )
738740 except cmd_not_found_exception as err :
739- raise GitCommandNotFound (command , err ) from err
741+ raise GitCommandNotFound (redacted_command , err ) from err
740742
741743 if as_process :
742744 return self .AutoInterrupt (proc , command )
@@ -786,7 +788,7 @@ def _kill_process(pid):
786788 watchdog .cancel ()
787789 if kill_check .isSet ():
788790 stderr_value = ('Timeout: the command "%s" did not complete in %d '
789- 'secs.' % (" " .join (command ), kill_after_timeout ))
791+ 'secs.' % (" " .join (redacted_command ), kill_after_timeout ))
790792 if not universal_newlines :
791793 stderr_value = stderr_value .encode (defenc )
792794 # strip trailing "\n"
@@ -810,7 +812,7 @@ def _kill_process(pid):
810812 proc .stderr .close ()
811813
812814 if self .GIT_PYTHON_TRACE == 'full' :
813- cmdstr = " " .join (command )
815+ cmdstr = " " .join (redacted_command )
814816
815817 def as_text (stdout_value ):
816818 return not output_stream and safe_decode (stdout_value ) or '<OUTPUT_STREAM>'
@@ -826,7 +828,7 @@ def as_text(stdout_value):
826828 # END handle debug printing
827829
828830 if with_exceptions and status != 0 :
829- raise GitCommandError (command , status , stderr_value , stdout_value )
831+ raise GitCommandError (redacted_command , status , stderr_value , stdout_value )
830832
831833 if isinstance (stdout_value , bytes ) and stdout_as_string : # could also be output_stream
832834 stdout_value = safe_decode (stdout_value )
0 commit comments