29
29
is_win ,
30
30
)
31
31
from 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
33
33
34
34
from .exc import (
35
35
GitCommandError ,
@@ -83,8 +83,8 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
83
83
line = line .decode (defenc )
84
84
handler (line )
85
85
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
88
88
finally :
89
89
stream .close ()
90
90
@@ -406,7 +406,7 @@ def read_all_from_possibly_closed_stream(stream):
406
406
if status != 0 :
407
407
errstr = read_all_from_possibly_closed_stream (self .proc .stderr )
408
408
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 )
410
410
# END status handling
411
411
return status
412
412
# END auto interrupt
@@ -683,8 +683,10 @@ def execute(self, command,
683
683
:note:
684
684
If you add additional keyword arguments to the signature of this method,
685
685
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 )
686
688
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 ))
688
690
689
691
# Allow the user to have the command executed in their working dir.
690
692
cwd = self ._working_dir or os .getcwd ()
@@ -705,7 +707,7 @@ def execute(self, command,
705
707
if is_win :
706
708
cmd_not_found_exception = OSError
707
709
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.' )
709
711
else :
710
712
if sys .version_info [0 ] > 2 :
711
713
cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
@@ -720,7 +722,7 @@ def execute(self, command,
720
722
if istream :
721
723
istream_ok = "<valid stream>"
722
724
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 )
724
726
try :
725
727
proc = Popen (command ,
726
728
env = env ,
@@ -736,7 +738,7 @@ def execute(self, command,
736
738
** subprocess_kwargs
737
739
)
738
740
except cmd_not_found_exception as err :
739
- raise GitCommandNotFound (command , err ) from err
741
+ raise GitCommandNotFound (redacted_command , err ) from err
740
742
741
743
if as_process :
742
744
return self .AutoInterrupt (proc , command )
@@ -786,7 +788,7 @@ def _kill_process(pid):
786
788
watchdog .cancel ()
787
789
if kill_check .isSet ():
788
790
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 ))
790
792
if not universal_newlines :
791
793
stderr_value = stderr_value .encode (defenc )
792
794
# strip trailing "\n"
@@ -810,7 +812,7 @@ def _kill_process(pid):
810
812
proc .stderr .close ()
811
813
812
814
if self .GIT_PYTHON_TRACE == 'full' :
813
- cmdstr = " " .join (command )
815
+ cmdstr = " " .join (redacted_command )
814
816
815
817
def as_text (stdout_value ):
816
818
return not output_stream and safe_decode (stdout_value ) or '<OUTPUT_STREAM>'
@@ -826,7 +828,7 @@ def as_text(stdout_value):
826
828
# END handle debug printing
827
829
828
830
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 )
830
832
831
833
if isinstance (stdout_value , bytes ) and stdout_as_string : # could also be output_stream
832
834
stdout_value = safe_decode (stdout_value )
0 commit comments