-
-
Save thecist/25c043c2130c07842a98471066206a53 to your computer and use it in GitHub Desktop.
Code for unarchiving thecist's repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| import subprocess | |
| # --- Configuration --- | |
| BASE_REPO_DIR = os.path.expanduser("~/thecist") | |
| REMOTE_NAME = "origin" | |
| BRANCH_PREFIX = "v" | |
| # --- Input --- | |
| if len(sys.argv) != 3: | |
| print("Usage: python create_push_delete_branch.py <repo-name> <branch-name>") | |
| sys.exit(1) | |
| repo_name = sys.argv[1] | |
| branch_name = sys.argv[2] | |
| repo_path = os.path.join(BASE_REPO_DIR, repo_name) | |
| if not os.path.isdir(repo_path): | |
| print(f"Repo '{repo_name}' not found in {BASE_REPO_DIR}") | |
| sys.exit(1) | |
| def run(cmd, cwd=None, capture_output=False): | |
| return subprocess.run( | |
| cmd, | |
| cwd=cwd, | |
| shell=True, | |
| check=True, | |
| stdout=subprocess.PIPE if capture_output else None, | |
| text=True, | |
| ) | |
| try: | |
| # Get a branch name that doesn't exist on origin | |
| print(f"Unarchiving: {branch_name}") | |
| # Deleting branch from remote - triggers hook | |
| run(f"git push {REMOTE_NAME} --delete {branch_name}", cwd=repo_path) | |
| print(f"Archive '{branch_name}' has been unarchived successfully.") | |
| except subprocess.CalledProcessError: | |
| print("An error occurred during git operations.") | |
| sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment