make git idempotent

This commit is contained in:
Jörg Thalheim
2023-09-22 16:38:46 +02:00
parent d9fd0e2a65
commit b482dcd466
2 changed files with 12 additions and 0 deletions

View File

@@ -54,6 +54,16 @@ def _commit_file_to_git(repo_dir: Path, file_path: Path, commit_message: str) ->
f"Failed to add {file_path} to git repository {repo_dir}:\n{shlex.join(cmd)}\n exited with {e.returncode}"
) from e
# check if there is a diff
cmd = nix_shell(
["git"],
["git", "-C", str(repo_dir), "diff", "--cached", "--exit-code"],
)
result = subprocess.run(cmd, cwd=repo_dir)
# if there is no diff, return
if result.returncode == 0:
return
# commit only that file
cmd = nix_shell(
["git"],