diff options
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/git-blame-stats/git-blame-stats.py | 9 | ||||
-rwxr-xr-x | packages/git-broom/git-broom.py | 79 |
2 files changed, 23 insertions, 65 deletions
diff --git a/packages/git-blame-stats/git-blame-stats.py b/packages/git-blame-stats/git-blame-stats.py index 3cc4f4a..5f2a43f 100755 --- a/packages/git-blame-stats/git-blame-stats.py +++ b/packages/git-blame-stats/git-blame-stats.py @@ -4,11 +4,8 @@ import argparse import subprocess from typing import Any - parser = argparse.ArgumentParser() -parser.add_argument( - "rev", metavar="revision", type=str, help="the revision", default="HEAD", nargs="?" -) +parser.add_argument("rev", metavar="revision", type=str, help="the revision", default="HEAD", nargs="?") args = parser.parse_args() authors: dict[str, Any] = dict() @@ -90,6 +87,4 @@ for author, stats in authors.items(): lines = stats["lines"] commits = len(stats["commits"]) files = len(stats["files"]) - print( - f"{author:{max_lenght_author}} {email:{max_lenght_email}} {lines:6} {commits:6} {files:6}" - ) + print(f"{author:{max_lenght_author}} {email:{max_lenght_email}} {lines:6} {commits:6} {files:6}") diff --git a/packages/git-broom/git-broom.py b/packages/git-broom/git-broom.py index b508357..27b97c6 100755 --- a/packages/git-broom/git-broom.py +++ b/packages/git-broom/git-broom.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 -import argparse import os import re -import subprocess import sys -from typing import List, Dict - import logging +import argparse +import subprocess +from typing import Dict, List logging.basicConfig(format="[%(asctime)s]%(levelname)s:%(message)s", level=logging.INFO) @@ -83,18 +82,14 @@ class GitConfig(object): self.primary_branch = m.group("branch") return - raise ValueError( - f"can't find the name of the remote branch for {self.remote_name}" - ) + raise ValueError(f"can't find the name of the remote branch for {self.remote_name}") def is_git_repository() -> bool: """Check if we are inside a git repository. Return True if we are, false otherwise.""" - res = subprocess.run( - ["git", "rev-parse", "--show-toplevel"], check=False, capture_output=True - ) + res = subprocess.run(["git", "rev-parse", "--show-toplevel"], check=False, capture_output=True) return not res.returncode @@ -105,9 +100,7 @@ def fetch(remote: str): def ref_sha(ref: str) -> str: """Get the sha from a ref.""" - res = subprocess.run( - ["git", "show-ref", ref], capture_output=True, check=True, encoding="utf-8" - ) + res = subprocess.run(["git", "show-ref", ref], capture_output=True, check=True, encoding="utf-8") return res.stdout.rstrip() @@ -137,9 +130,7 @@ def rebase_local_branches(config: GitConfig, local_rebase_tree_id: dict) -> None _rebase_local_branch(branch, config, local_rebase_tree_id) -def _rebase_local_branch( - branch: str, config: GitConfig, local_rebase_tree_id: dict -) -> None: +def _rebase_local_branch(branch: str, config: GitConfig, local_rebase_tree_id: dict) -> None: res = subprocess.run( [ "git", @@ -152,43 +143,29 @@ def _rebase_local_branch( capture_output=True, ) if res.returncode == 0: - logging.info( - f"local branch {branch} is already a descendant of {config.remote_ref}." - ) + logging.info(f"local branch {branch} is already a descendant of {config.remote_ref}.") local_rebase_tree_id[branch] = ref_tree(branch) return logging.info(f"local branch {branch} will be rebased on {config.remote_ref}.") - subprocess.run( - ["git", "checkout", "--force", branch], check=True, capture_output=True - ) - res = subprocess.run( - ["git", "rebase", config.remote_ref], check=True, capture_output=True - ) + subprocess.run(["git", "checkout", "--force", branch], check=True, capture_output=True) + res = subprocess.run(["git", "rebase", config.remote_ref], check=True, capture_output=True) if res.returncode == 0: logging.info(f"local branch {branch} has been rebased") local_rebase_tree_id[branch] = ref_tree(branch) else: logging.error(f"failed to rebase local branch {branch}.") subprocess.run(["git", "rebase", "--abort"], check=True) - subprocess.run( - ["git", "checkout", "--force", config.primary_branch], check=True - ) + subprocess.run(["git", "checkout", "--force", config.primary_branch], check=True) subprocess.run(["git", "reset", "--hard"], check=True) -def rebase_remote_branches( - config: GitConfig, local_rebase_tree_id: dict, main_sha: str -) -> None: - for branch in get_branches( - ["--list", "-r", f"{config.me}/*", "--no-merged", config.remote_ref] - ): +def rebase_remote_branches(config: GitConfig, local_rebase_tree_id: dict, main_sha: str) -> None: + for branch in get_branches(["--list", "-r", f"{config.me}/*", "--no-merged", config.remote_ref]): _rebase_remote_branches(branch, config, local_rebase_tree_id, main_sha) -def _rebase_remote_branches( - branch: str, config: GitConfig, local_rebase_tree_id: dict, main_sha: str -) -> None: +def _rebase_remote_branches(branch: str, config: GitConfig, local_rebase_tree_id: dict, main_sha: str) -> None: remote, head = branch.split("/") if head in immortal_ref: return @@ -199,9 +176,7 @@ def _rebase_remote_branches( capture_output=True, ) if res.returncode == 0: - logging.info( - f"local branch {branch} is already a descendant of {config.remote_ref}." - ) + logging.info(f"local branch {branch} is already a descendant of {config.remote_ref}.") return logging.info(f"remote branch {branch} will be rebased on {config.remote_ref}.") @@ -226,26 +201,18 @@ def _rebase_remote_branches( logging.info(f"remote branch {branch}, when rebased, same as local branch!") logging.info(f"would run `git push --force-with-lease {remote} {head}'") else: - logging.info( - f"remote branch {branch} has been rebased to create {short_sha}!" - ) - logging.info( - f"would run `git push --force-with-lease {remote} {new_sha}:{head}'" - ) + logging.info(f"remote branch {branch} has been rebased to create {short_sha}!") + logging.info(f"would run `git push --force-with-lease {remote} {new_sha}:{head}'") else: logging.error(f"failed to rebase remote branch {branch}.") subprocess.run(["git", "rebase", "--abort"], check=True) - subprocess.run( - ["git", "checkout", "--force", config.primary_branch], check=True - ) + subprocess.run(["git", "checkout", "--force", config.primary_branch], check=True) subprocess.run(["git", "reset", "--hard"], check=True) def destroy_remote_merged_branches(config: GitConfig, dry_run: bool) -> None: """Destroy remote branches that have been merged.""" - for branch in get_branches( - ["--list", "-r", f"{config.me}/*", "--merged", config.remote_ref] - ): + for branch in get_branches(["--list", "-r", f"{config.me}/*", "--merged", config.remote_ref]): remote, head = branch.split("/") if head in immortal_ref: continue @@ -253,9 +220,7 @@ def destroy_remote_merged_branches(config: GitConfig, dry_run: bool) -> None: if dry_run: logging.info(f"would have run git push {remote} :{head}") else: - subprocess.run( - ["git", "push", remote, f":{head}"], check=True, encoding="utf-8" - ) + subprocess.run(["git", "push", remote, f":{head}"], check=True, encoding="utf-8") def destroy_local_merged_branches(config: GitConfig, dry_run: bool) -> None: @@ -335,9 +300,7 @@ def main(dry_run: bool) -> bool: if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="delete local and remote branches that have been merged." - ) + parser = argparse.ArgumentParser(description="delete local and remote branches that have been merged.") parser.add_argument( "--dry-run", action=argparse.BooleanOptionalAction, |