100100
101101
102102def handle_process_output (
103- process : "Git.AutoInterrupt" | Popen ,
103+ process : Union [ "Git.AutoInterrupt" , Popen ] ,
104104 stdout_handler : Union [
105105 None ,
106106 Callable [[AnyStr ], None ],
@@ -395,9 +395,7 @@ def wait(self, stderr: Union[None, str, bytes] = b"") -> int:
395395 :raise git.exc.GitCommandError:
396396 If the return status is not 0.
397397 """
398- if stderr is None :
399- stderr_b = b""
400- stderr_b = force_bytes (data = stderr , encoding = "utf-8" )
398+ stderr_b = force_bytes (data = stderr , encoding = "utf-8" ) or b""
401399 status : Union [int , None ]
402400 if self .proc is not None :
403401 status = self .proc .wait ()
@@ -1180,52 +1178,112 @@ def version_info(self) -> Tuple[int, ...]:
11801178 def execute (
11811179 self ,
11821180 command : Union [str , Sequence [Any ]],
1181+ istream : Union [None , int , BinaryIO ] = None ,
11831182 * ,
11841183 as_process : Literal [True ],
1184+ ** subprocess_kwargs : Any ,
11851185 ) -> "AutoInterrupt" : ...
11861186
11871187 @overload
11881188 def execute (
11891189 self ,
11901190 command : Union [str , Sequence [Any ]],
1191+ istream : Union [None , int , BinaryIO ] = None ,
11911192 * ,
11921193 as_process : Literal [False ] = False ,
1193- stdout_as_string : Literal [True ],
1194- ) -> Union [str , Tuple [int , str , str ]]: ...
1194+ with_extended_output : Literal [False ] = False ,
1195+ stdout_as_string : Literal [True ] = True ,
1196+ with_stdout : Literal [True ] = True ,
1197+ ** subprocess_kwargs : Any ,
1198+ ) -> str : ...
11951199
11961200 @overload
11971201 def execute (
11981202 self ,
11991203 command : Union [str , Sequence [Any ]],
1204+ istream : Union [None , int , BinaryIO ] = None ,
12001205 * ,
12011206 as_process : Literal [False ] = False ,
1202- stdout_as_string : Literal [False ] = False ,
1203- ) -> Union [bytes , Tuple [int , bytes , str ]]: ...
1207+ with_extended_output : Literal [False ] = False ,
1208+ stdout_as_string : Literal [False ],
1209+ universal_newlines : Literal [False ] = False ,
1210+ with_stdout : Literal [True ] = True ,
1211+ ** subprocess_kwargs : Any ,
1212+ ) -> bytes : ...
12041213
12051214 @overload
12061215 def execute (
12071216 self ,
12081217 command : Union [str , Sequence [Any ]],
1218+ istream : Union [None , int , BinaryIO ] = None ,
12091219 * ,
1210- with_extended_output : Literal [False ],
1211- as_process : Literal [False ],
1212- stdout_as_string : Literal [True ],
1213- ) -> str : ...
1220+ as_process : Literal [False ] = False ,
1221+ with_extended_output : Literal [True ],
1222+ stdout_as_string : Literal [True ] = True ,
1223+ with_stdout : Literal [True ] = True ,
1224+ ** subprocess_kwargs : Any ,
1225+ ) -> Tuple [int , str , str ]: ...
12141226
12151227 @overload
12161228 def execute (
12171229 self ,
12181230 command : Union [str , Sequence [Any ]],
1231+ istream : Union [None , int , BinaryIO ] = None ,
12191232 * ,
1220- with_extended_output : Literal [False ],
1221- as_process : Literal [False ],
1233+ as_process : Literal [False ] = False ,
1234+ with_extended_output : Literal [True ],
12221235 stdout_as_string : Literal [False ],
1223- ) -> bytes : ...
1236+ universal_newlines : Literal [False ] = False ,
1237+ with_stdout : Literal [True ] = True ,
1238+ ** subprocess_kwargs : Any ,
1239+ ) -> Tuple [int , bytes , str ]: ...
1240+
1241+ @overload
1242+ def execute (
1243+ self ,
1244+ command : Union [str , Sequence [Any ]],
1245+ istream : Union [None , int , BinaryIO ] = None ,
1246+ * ,
1247+ as_process : Literal [False ] = False ,
1248+ with_extended_output : Literal [True ],
1249+ ** subprocess_kwargs : Any ,
1250+ ) -> Tuple [int , Union [str , bytes , None ], str ]: ...
1251+
1252+ @overload
1253+ def execute (
1254+ self ,
1255+ command : Union [str , Sequence [Any ]],
1256+ istream : Union [None , int , BinaryIO ] = None ,
1257+ * ,
1258+ as_process : Literal [False ] = False ,
1259+ with_extended_output : Literal [False ] = False ,
1260+ ** subprocess_kwargs : Any ,
1261+ ) -> Union [str , bytes , None ]: ...
1262+
1263+ @overload
1264+ def execute (
1265+ self ,
1266+ command : Union [str , Sequence [Any ]],
1267+ istream : Union [None , int , BinaryIO ] = None ,
1268+ with_extended_output : bool = False ,
1269+ with_exceptions : bool = True ,
1270+ as_process : bool = False ,
1271+ output_stream : Union [None , BinaryIO ] = None ,
1272+ stdout_as_string : bool = True ,
1273+ kill_after_timeout : Union [None , float ] = None ,
1274+ with_stdout : bool = True ,
1275+ universal_newlines : bool = False ,
1276+ shell : Union [None , bool ] = None ,
1277+ env : Union [None , Mapping [str , str ]] = None ,
1278+ max_chunk_size : int = io .DEFAULT_BUFFER_SIZE ,
1279+ strip_newline_in_stdout : bool = True ,
1280+ ** subprocess_kwargs : Any ,
1281+ ) -> Union [None , str , bytes , Tuple [int , Union [str , bytes , None ], str ], AutoInterrupt ]: ...
12241282
12251283 def execute (
12261284 self ,
12271285 command : Union [str , Sequence [Any ]],
1228- istream : Union [None , BinaryIO ] = None ,
1286+ istream : Union [None , int , BinaryIO ] = None ,
12291287 with_extended_output : bool = False ,
12301288 with_exceptions : bool = True ,
12311289 as_process : bool = False ,
@@ -1239,7 +1297,7 @@ def execute(
12391297 max_chunk_size : int = io .DEFAULT_BUFFER_SIZE ,
12401298 strip_newline_in_stdout : bool = True ,
12411299 ** subprocess_kwargs : Any ,
1242- ) -> Union [str , bytes , Tuple [int , Union [str , bytes ], str ], AutoInterrupt ]:
1300+ ) -> Union [None , str , bytes , Tuple [int , Union [str , bytes , None ], str ], AutoInterrupt ]:
12431301 R"""Handle executing the command, and consume and return the returned
12441302 information (stdout).
12451303
@@ -1503,7 +1561,7 @@ def make_timeout_error() -> Union[str, bytes]:
15031561 err = f'Timeout: the command "{ " " .join (redacted_command )} " did not complete in { timeout :g} secs.'
15041562 return err if universal_newlines else err .encode (defenc )
15051563
1506- def communicate () -> Tuple [AnyStr , AnyStr ]:
1564+ def communicate () -> Tuple [Union [ str , bytes , None ], Union [ str , bytes , None ] ]:
15071565 assert watchdog is not None
15081566 assert kill_check is not None
15091567 watchdog .start ()
@@ -1523,8 +1581,8 @@ def communicate() -> Tuple[AnyStr, AnyStr]:
15231581
15241582 # Wait for the process to return.
15251583 status = 0
1526- stdout_value : Union [str , bytes ] = b""
1527- stderr_value : Union [str , bytes ] = b""
1584+ stdout_value : Union [str , bytes , None ] = b""
1585+ stderr_value : Union [str , bytes , None ] = b""
15281586 newline = "\n " if universal_newlines else b"\n "
15291587 try :
15301588 if output_stream is None :
@@ -1566,7 +1624,7 @@ def communicate() -> Tuple[AnyStr, AnyStr]:
15661624 if self .GIT_PYTHON_TRACE == "full" :
15671625 cmdstr = " " .join (redacted_command )
15681626
1569- def as_text (stdout_value : Union [bytes , str ]) -> str :
1627+ def as_text (stdout_value : Union [bytes , str , None ]) -> str :
15701628 return not output_stream and safe_decode (stdout_value ) or "<OUTPUT_STREAM>"
15711629
15721630 # END as_text
@@ -1591,6 +1649,8 @@ def as_text(stdout_value: Union[bytes, str]) -> str:
15911649 if isinstance (stdout_value , bytes ) and stdout_as_string : # Could also be output_stream.
15921650 stdout_value = safe_decode (stdout_value )
15931651
1652+ # stderr is always captured through PIPE.
1653+ assert stderr_value is not None
15941654 # Allow access to the command's status code.
15951655 if with_extended_output :
15961656 return (status , stdout_value , safe_decode (stderr_value ))
@@ -1829,7 +1889,7 @@ def _parse_object_header(self, header_line: str) -> Tuple[str, str, int]:
18291889 raise ValueError ("Failed to parse header: %r" % header_line )
18301890 return (tokens [0 ], tokens [1 ], int (tokens [2 ]))
18311891
1832- def _prepare_ref (self , ref : AnyStr ) -> bytes :
1892+ def _prepare_ref (self , ref : object ) -> bytes :
18331893 # Required for command to separate refs on stdin, as bytes.
18341894 if isinstance (ref , bytes ):
18351895 # Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text.
@@ -1856,15 +1916,15 @@ def _get_persistent_cmd(self, attr_name: str, cmd_name: str, *args: Any, **kwarg
18561916 cmd = cast ("Git.AutoInterrupt" , cmd )
18571917 return cmd
18581918
1859- def __get_object_header (self , cmd : "Git.AutoInterrupt" , ref : AnyStr ) -> Tuple [str , str , int ]:
1919+ def __get_object_header (self , cmd : "Git.AutoInterrupt" , ref : Union [ str , bytes ] ) -> Tuple [str , str , int ]:
18601920 if cmd .stdin and cmd .stdout :
18611921 cmd .stdin .write (self ._prepare_ref (ref ))
18621922 cmd .stdin .flush ()
18631923 return self ._parse_object_header (cmd .stdout .readline ())
18641924 else :
18651925 raise ValueError ("cmd stdin was empty" )
18661926
1867- def get_object_header (self , ref : str ) -> Tuple [str , str , int ]:
1927+ def get_object_header (self , ref : Union [ str , bytes ] ) -> Tuple [str , str , int ]:
18681928 """Use this method to quickly examine the type and size of the object behind the
18691929 given ref.
18701930
@@ -1878,7 +1938,7 @@ def get_object_header(self, ref: str) -> Tuple[str, str, int]:
18781938 cmd = self ._get_persistent_cmd ("cat_file_header" , "cat_file" , batch_check = True )
18791939 return self .__get_object_header (cmd , ref )
18801940
1881- def get_object_data (self , ref : str ) -> Tuple [str , str , int , bytes ]:
1941+ def get_object_data (self , ref : Union [ str , bytes ] ) -> Tuple [str , str , int , bytes ]:
18821942 """Similar to :meth:`get_object_header`, but returns object data as well.
18831943
18841944 :return:
@@ -1892,7 +1952,7 @@ def get_object_data(self, ref: str) -> Tuple[str, str, int, bytes]:
18921952 del stream
18931953 return (hexsha , typename , size , data )
18941954
1895- def stream_object_data (self , ref : str ) -> Tuple [str , str , int , "Git.CatFileContentStream" ]:
1955+ def stream_object_data (self , ref : Union [ str , bytes ] ) -> Tuple [str , str , int , "Git.CatFileContentStream" ]:
18961956 """Similar to :meth:`get_object_data`, but returns the data as a stream.
18971957
18981958 :return:
0 commit comments