make git idempotent
This commit is contained in:
@@ -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}"
|
f"Failed to add {file_path} to git repository {repo_dir}:\n{shlex.join(cmd)}\n exited with {e.returncode}"
|
||||||
) from e
|
) 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
|
# commit only that file
|
||||||
cmd = nix_shell(
|
cmd = nix_shell(
|
||||||
["git"],
|
["git"],
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ def test_commit_file_outside_git_raises_error(git_repo: Path) -> None:
|
|||||||
# commit the file
|
# commit the file
|
||||||
with pytest.raises(ClanError):
|
with pytest.raises(ClanError):
|
||||||
git.commit_file(Path(tmp.name), git_repo, "test commit")
|
git.commit_file(Path(tmp.name), git_repo, "test commit")
|
||||||
|
# this should not fail but skip the commit
|
||||||
|
git.commit_file(Path(tmp.name), git_repo, "test commit")
|
||||||
|
|
||||||
|
|
||||||
def test_commit_file_not_existing_raises_error(git_repo: Path) -> None:
|
def test_commit_file_not_existing_raises_error(git_repo: Path) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user