diff --git a/codearchiver/modules/git.py b/codearchiver/modules/git.py index 6ce3a35..2035e2a 100644 --- a/codearchiver/modules/git.py +++ b/codearchiver/modules/git.py @@ -50,17 +50,17 @@ class Git(codearchiver.core.Module): if self._extraBranches: for branch, commit in self._extraBranches.items(): _logger.info(f'Fetching commit {commit} as {branch}') - r, _ = codearchiver.subprocess.run_with_log(['git', 'fetch', '--verbose', '--progress', 'origin', commit], cwd = directory, check = False) + r, _, _ = codearchiver.subprocess.run_with_log(['git', 'fetch', '--verbose', '--progress', 'origin', commit], cwd = directory, check = False) if r == 0: - r2, _ = codearchiver.subprocess.run_with_log(['git', 'update-ref', f'refs/codearchiver/{branch}', commit, ''], cwd = directory, check = False) + r2, _, _ = codearchiver.subprocess.run_with_log(['git', 'update-ref', f'refs/codearchiver/{branch}', commit, ''], cwd = directory, check = False) if r2 != 0: _logger.error(f'Failed to update-ref refs/codearchiver/{branch} to {commit}') else: _logger.error(f'Failed to fetch {commit}') _logger.info(f'Collecting repository metadata for index') - _, refs = codearchiver.subprocess.run_with_log(['git', 'show-ref'], cwd = directory) - _, commits = codearchiver.subprocess.run_with_log(['git', 'log', '--reflog', '--all', '--format=format:%H% P'], cwd = directory) + _, refs, _ = codearchiver.subprocess.run_with_log(['git', 'show-ref'], cwd = directory) + _, commits, _ = codearchiver.subprocess.run_with_log(['git', 'log', '--reflog', '--all', '--format=format:%H% P'], cwd = directory) commits = list(map(functools.partial(str.split, sep = ' '), commits.splitlines())) rootCommits = [c[0] for c in commits if len(c) == 1] diff --git a/codearchiver/subprocess.py b/codearchiver/subprocess.py index 453f7fc..5422851 100644 --- a/codearchiver/subprocess.py +++ b/codearchiver/subprocess.py @@ -14,7 +14,7 @@ def run_with_log(args, *, check = True, input = None, **kwargs): `check` has the same semantics as on `subprocess.run`, i.e. raises an exception if the process exits non-zero. `input`, if specified, is a `bytes` object that is fed to the subprocess via stdin. `stdin`, `stdout`, and `stderr` kwargs must not be used. - Returns a tuple with the process's exit status and its stdout output. + Returns a tuple with the process's exit status, its stdout output, and its stderr output. ''' badKwargs = {'stdin', 'stdout', 'stderr'}.intersection(set(kwargs)) if badKwargs: @@ -29,6 +29,7 @@ def run_with_log(args, *, check = True, input = None, **kwargs): sel.register(p.stdout, selectors.EVENT_READ) sel.register(p.stderr, selectors.EVENT_READ) stdout = [] + stderr = [] stderrBuf = b'' if input is not None: stdinView = memoryview(input) @@ -53,6 +54,7 @@ def run_with_log(args, *, check = True, input = None, **kwargs): key.fileobj.close() continue if key.fileobj is p.stderr: + stderr.append(data) stderrBuf += data *lines, stderrBuf = stderrBuf.replace(b'\r', b'\n').rsplit(b'\n', 1) if not lines: @@ -70,4 +72,4 @@ def run_with_log(args, *, check = True, input = None, **kwargs): _logger.info(f'Process exited with status {p.returncode}') if check and p.returncode != 0: raise subprocess.CalledProcessError(returncode = p.returncode, cmd = args) - return (p.returncode, b''.join(stdout).decode('utf-8')) + return (p.returncode, b''.join(stdout).decode('utf-8'), b''.join(stderr).decode('utf-8'))