Skip to content

Commit 8561233

Browse files
authored
Merge pull request #3426 from OpenNeuroOrg/large-file-commit-fix
Prevent git index from being updated twice during commits
2 parents 8d9127f + cef4636 commit 8561233

File tree

1 file changed

+19
-3
lines changed
  • services/datalad/datalad_service/common

1 file changed

+19
-3
lines changed

services/datalad/datalad_service/common/git.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pathlib
22
import re
33
import subprocess
4+
import logging
5+
import sentry_sdk
46

57
import pygit2
68
from charset_normalizer import from_bytes
@@ -10,6 +12,7 @@
1012
COMMITTER_NAME = 'Git Worker'
1113
COMMITTER_EMAIL = '[email protected]'
1214

15+
logger = logging.getLogger(__name__)
1316

1417
class OpenNeuroGitError(Exception):
1518
"""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
7881
'HEAD points at invalid branch name ({}) and commit was aborted'.format(repo.references['HEAD'].target))
7982
# Refresh index with git-annex specific handling
8083
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
84100
return git_commit_index(repo, author, message, parents)
85101

86102

0 commit comments

Comments
 (0)