Quellcode durchsuchen

git_common: raise CalledProcessError with the given cwd, if set

For example, SCM.Capture() calls git_common.run() with `cwd=value`,
which then gets passed to subprocess.Popen2().
: https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:scm.py;l=705-710;drc=e0c47c138ad4b0e6224a29e597dba5ca53e63ee0

Change-Id: I4b7e14e9f3fb10c1e779fc53d82aa7922194bd36
Bug: 412904761
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6484452
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Auto-Submit: Scott Lee <ddoman@chromium.org>
Scott Lee vor 3 Monaten
Ursprung
Commit
a7460c638b
1 geänderte Dateien mit 18 neuen und 4 gelöschten Zeilen
  1. 18 4
      git_common.py

+ 18 - 4
git_common.py

@@ -962,8 +962,15 @@ def run_stream_with_retcode(*cmd, **kwargs):
     finally:
         retcode = proc.wait()
         if retcode != 0:
-            raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), b'',
-                                                 b'')
+            cwd = kwargs.get('cwd', os.getcwd())
+            raise subprocess2.CalledProcessError(
+                retcode,
+                cmd,
+                # cwd could be either str or os.PathLike.
+                f'{cwd}',
+                b'',
+                b'',
+            )
 
 
 def run_with_stderr(*cmd, **kwargs) -> Tuple[str, str] | Tuple[bytes, bytes]:
@@ -1022,8 +1029,15 @@ def _run_with_stderr(*cmd, **kwargs) -> Tuple[str, str] | Tuple[bytes, bytes]:
     stdout, stderr = proc.communicate(indata)
     retcode = proc.wait()
     if retcode not in accepted_retcodes:
-        raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), stdout,
-                                             stderr)
+        cwd = kwargs.get('cwd', os.getcwd())
+        raise subprocess2.CalledProcessError(
+            retcode,
+            cmd,
+            # cwd could be either str or os.PathLike.
+            f'{cwd}',
+            stdout,
+            stderr,
+        )
 
     if autostrip:
         stdout = (stdout or b'').strip()