diff --git a/services/datalad/datalad_service/common/git.py b/services/datalad/datalad_service/common/git.py index 48118b1aa..12c997b57 100644 --- a/services/datalad/datalad_service/common/git.py +++ b/services/datalad/datalad_service/common/git.py @@ -163,6 +163,9 @@ async def git_commit( sentry_sdk.capture_exception(e) logger.error(f'Failed to read index after git-annex add: {e}') raise OpenNeuroGitError(f'Failed to read index: {e}') from e + # Ensure non-annexed files are smudged, e.g., update end-of-lines + # but do not "fix" unrelated paths + repo.index.add_all(file_paths) return await git_commit_index(repo, author, message, parents) @@ -173,10 +176,14 @@ async def git_commit_index( committer = pygit2.Signature(COMMITTER_NAME, COMMITTER_EMAIL) if not author: author = committer - if parents is None: - parent_commits = [str(repo.head.target)] - else: - parent_commits = parents + + parent_commits = [repo.head.target] if parents is None else parents + if len(parent_commits) == 1 and not any( + repo.index.diff_to_tree(repo.get(parent_commits[0]).tree) + ): + # No changes to commit + return + tree = repo.index.write_tree() commit = repo.create_commit( 'refs/heads/main', author, committer, message, tree, parent_commits