()
| 90 | |
| 91 | |
| 92 | def main(): |
| 93 | parser = argparse.ArgumentParser( |
| 94 | description="Archive Django branches into tags and optionally delete them." |
| 95 | ) |
| 96 | parser.add_argument( |
| 97 | "--checkout-dir", required=True, help="Path to Django git checkout" |
| 98 | ) |
| 99 | parser.add_argument( |
| 100 | "--dry-run", |
| 101 | action="store_true", |
| 102 | help="Print commands instead of executing them", |
| 103 | ) |
| 104 | parser.add_argument( |
| 105 | "--branches", nargs="*", help="Specific remote branches to include (optional)" |
| 106 | ) |
| 107 | args = parser.parse_args() |
| 108 | |
| 109 | validate_env(args.checkout_dir) |
| 110 | dry_run = args.dry_run |
| 111 | checkout_dir = args.checkout_dir |
| 112 | |
| 113 | if args.branches: |
| 114 | wanted = set(f"origin/{b}" for b in args.branches) |
| 115 | else: |
| 116 | wanted = set() |
| 117 | |
| 118 | branches = get_remote_branches(checkout_dir, include_fn=lambda b: b in wanted) |
| 119 | if not branches: |
| 120 | print("No branches matched inclusion criteria.") |
| 121 | return |
| 122 | |
| 123 | print("\nMatched branches:") |
| 124 | print("\n".join(branches)) |
| 125 | print() |
| 126 | |
| 127 | branch_updates = {b: get_branch_info(checkout_dir, b) for b in branches} |
| 128 | print("\nLast updates:") |
| 129 | for b, (h, d) in branch_updates.items(): |
| 130 | print(f"{b}\t{h}\t{d}") |
| 131 | |
| 132 | if ( |
| 133 | input("\nDelete remote branches and create tags? [y/N]: ").strip().lower() |
| 134 | == "y" |
| 135 | ): |
| 136 | for b, (commit_hash, last_update_date) in branch_updates.items(): |
| 137 | print(f"Creating tag for {b} at {commit_hash=} with {last_update_date=}") |
| 138 | create_tag(checkout_dir, b, commit_hash, last_update_date, dry_run=dry_run) |
| 139 | print(f"Deleting remote branch {b}") |
| 140 | delete_remote_and_local_branch(checkout_dir, b, dry_run=dry_run) |
| 141 | run( |
| 142 | ["git", "push", "--tags"], |
| 143 | cwd=checkout_dir, |
| 144 | dry_run=dry_run, |
| 145 | ) |
| 146 | |
| 147 | print("Done.") |
| 148 | |
| 149 |
no test coverage detected