diff options
-rw-r--r-- | b4/__init__.py | 13 | ||||
-rw-r--r-- | b4/ez.py | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index e2ed881..3b8b9f3 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -1903,10 +1903,21 @@ class LoreAttestorPatatt(LoreAttestor): self.have_key = True -def _run_command(cmdargs: List[str], stdin: Optional[bytes] = None) -> Tuple[int, bytes, bytes]: +def _run_command(cmdargs: List[str], stdin: Optional[bytes] = None, + rundir: Optional[str] = None) -> Tuple[int, bytes, bytes]: + if rundir: + logger.debug('Changing dir to %s', rundir) + curdir = os.getcwd() + os.chdir(rundir) + else: + curdir = None + logger.debug('Running %s' % ' '.join(cmdargs)) sp = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) (output, error) = sp.communicate(input=stdin) + if curdir: + logger.debug('Changing back into %s', curdir) + os.chdir(curdir) return sp.returncode, output, error @@ -678,7 +678,9 @@ def update_trailers(cmdargs: argparse.Namespace) -> None: def get_addresses_from_cmd(cmdargs: List[str], msgbytes: bytes) -> List[Tuple[str, str]]: - ecode, out, err = b4._run_command(cmdargs, stdin=msgbytes) # noqa + # Run this command from git toplevel + topdir = b4.git_get_toplevel() + ecode, out, err = b4._run_command(cmdargs, stdin=msgbytes, rundir=topdir) # noqa if ecode > 0: logger.critical('CRITICAL: Running %s failed:', ' '.join(cmdargs)) logger.critical(err.decode()) |