azure-cli.extensions-tool: workaround for commit authorship bug in gitpython

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer
2024-11-02 12:57:33 +01:00
parent 9d4aedff01
commit 5139634ead
+9 -5
View File
@@ -113,11 +113,11 @@ def _convert_hash_digest_from_hex_to_b64_sri(s: str) -> str:
return f"sha256-{base64.b64encode(b).decode('utf-8')}"
def _commit(repo: git.Repo, message: str, files: List[Path]) -> None:
def _commit(repo: git.Repo, message: str, files: List[Path], actor: git.Actor) -> None:
repo.index.add([str(f.resolve()) for f in files])
if repo.index.diff("HEAD"):
logger.info(f'committing to nixpkgs "{message}"')
repo.index.commit(message)
repo.index.commit(message, author=actor, committer=actor)
else:
logger.warning("no changes in working tree to commit")
@@ -248,6 +248,10 @@ def main() -> None:
args = parser.parse_args()
repo = git.Repo(Path(".").resolve(), search_parent_directories=True)
# Workaround for https://github.com/gitpython-developers/GitPython/issues/1923
author = repo.config_reader().get_value("user", "name").lstrip('"').rstrip('"')
email = repo.config_reader().get_value("user", "email").lstrip('"').rstrip('"')
actor = git.Actor(author, email)
index = get_extension_index(args.cache_dir)
assert index["formatVersion"] == "1" # only support formatVersion 1
@@ -293,7 +297,7 @@ def main() -> None:
commit_msg = f"azure-cli-extensions.{ext.pname}: init at {ext.version}"
_write_extension_set(extension_file, extensions_local)
if args.commit:
_commit(repo, commit_msg, [extension_file])
_commit(repo, commit_msg, [extension_file], actor)
for prev, new in updated:
extensions_local.remove(prev)
@@ -303,7 +307,7 @@ def main() -> None:
)
_write_extension_set(extension_file, extensions_local)
if args.commit:
_commit(repo, commit_msg, [extension_file])
_commit(repo, commit_msg, [extension_file], actor)
for ext in removed:
extensions_local.remove(ext)
@@ -312,7 +316,7 @@ def main() -> None:
commit_msg = f"azure-cli-extensions.{ext.pname}: remove"
_write_extension_set(extension_file, extensions_local)
if args.commit:
_commit(repo, commit_msg, [extension_file])
_commit(repo, commit_msg, [extension_file], actor)
if __name__ == "__main__":