Skip to content

Commit 8bc43c1

Browse files
committed
fix: Avoid creating empty commits
1 parent 4c3e663 commit 8bc43c1

File tree

1 file changed

+9
-4
lines changed
  • services/datalad/datalad_service/common

1 file changed

+9
-4
lines changed

services/datalad/datalad_service/common/git.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async def git_commit(
145145
repo.references['HEAD'].target
146146
)
147147
)
148+
148149
# Refresh index with git-annex specific handling
149150
annex_command = ['git-annex', 'add'] + file_paths
150151
try:
@@ -176,10 +177,14 @@ async def git_commit_index(
176177
committer = pygit2.Signature(COMMITTER_NAME, COMMITTER_EMAIL)
177178
if not author:
178179
author = committer
179-
if parents is None:
180-
parent_commits = [str(repo.head.target)]
181-
else:
182-
parent_commits = parents
180+
181+
parent_commits = [repo.head.target] if parents is None else parents
182+
if len(parent_commits) == 1 and not any(
183+
repo.index.diff_to_tree(repo.get(parent_commits[0]).tree)
184+
):
185+
# No changes to commit
186+
return
187+
183188
tree = repo.index.write_tree()
184189
commit = repo.create_commit(
185190
'refs/heads/main', author, committer, message, tree, parent_commits

0 commit comments

Comments
 (0)