about summary refs log tree commit diff
path: root/packages/git-broom
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-07-22 17:46:36 -0700
committerFranck Cuny <franck@fcuny.net>2024-07-22 17:46:36 -0700
commitd4b6d2b2053e335e5457e34c128ec8a1a156671d (patch)
tree95dc405071eed3c61142754249b9de9326f4285d /packages/git-broom
parentdelete github actions (diff)
downloadworld-d4b6d2b2053e335e5457e34c128ec8a1a156671d.tar.gz
add lint as a target and reformat
Diffstat (limited to 'packages/git-broom')
-rwxr-xr-xpackages/git-broom/git-broom.py79
1 files changed, 21 insertions, 58 deletions
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,