|
1 | 1 | import pathlib |
2 | 2 | import re |
3 | 3 | import subprocess |
| 4 | +import logging |
| 5 | +import sentry_sdk |
4 | 6 |
|
5 | 7 | import pygit2 |
6 | 8 | from charset_normalizer import from_bytes |
|
10 | 12 | COMMITTER_NAME = 'Git Worker' |
11 | 13 | COMMITTER_EMAIL = '[email protected]' |
12 | 14 |
|
| 15 | +logger = logging.getLogger(__name__) |
13 | 16 |
|
14 | 17 | class OpenNeuroGitError(Exception): |
15 | 18 | """OpenNeuro git repo states that should not arise under normal use but may be a valid git operation in other contexts.""" |
@@ -78,9 +81,22 @@ def git_commit(repo, file_paths, author=None, message="[OpenNeuro] Recorded chan |
78 | 81 | 'HEAD points at invalid branch name ({}) and commit was aborted'.format(repo.references['HEAD'].target)) |
79 | 82 | # Refresh index with git-annex specific handling |
80 | 83 | annex_command = ["git-annex", "add"] + file_paths |
81 | | - subprocess.run(annex_command, check=True, cwd=repo.workdir) |
82 | | - repo.index.add_all(file_paths) |
83 | | - repo.index.write() |
| 84 | + try: |
| 85 | + subprocess.run(annex_command, check=True, capture_output=True, cwd=repo.workdir) |
| 86 | + except subprocess.CalledProcessError as e: |
| 87 | + sentry_sdk.capture_exception(e) |
| 88 | + logger.error(f"Error running git-annex add for paths {file_paths}: {e}") |
| 89 | + logger.error(f"Stderr: {e.stderr}") |
| 90 | + logger.error(f"Stdout: {e.stdout}") |
| 91 | + raise OpenNeuroGitError(f"git-annex add failed: {e.stderr}") from e |
| 92 | + # git-annex add updates the index, make sure we reload it |
| 93 | + try: |
| 94 | + repo.index.read(force=True) |
| 95 | + logger.debug("Reloaded index after git-annex add.") |
| 96 | + except Exception as e: |
| 97 | + sentry_sdk.capture_exception(e) |
| 98 | + logger.error(f"Failed to read index after git-annex add: {e}") |
| 99 | + raise OpenNeuroGitError(f"Failed to read index: {e}") from e |
84 | 100 | return git_commit_index(repo, author, message, parents) |
85 | 101 |
|
86 | 102 |
|
|
0 commit comments