Changeset View
Changeset View
Standalone View
Standalone View
bin/change-all-repos
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
import os.path | import os.path | ||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
from typing import List | from typing import List | ||||
BIN_DIR = os.path.dirname(__file__) | BIN_DIR = os.path.dirname(__file__) | ||||
SWH_ENV_DIR = os.path.join(BIN_DIR, "..") | SWH_ENV_DIR = os.path.join(BIN_DIR, "..") | ||||
def list_repos() -> List[str]: | def list_repos() -> List[str]: | ||||
proc = subprocess.run([os.path.join(BIN_DIR, "ls-all-repos")], capture_output=True) | proc = subprocess.run([os.path.join(BIN_DIR, "ls-all-repos")], capture_output=True) | ||||
return proc.stdout.decode().split() | return proc.stdout.decode().split() | ||||
def change_repo(repo: str, command: str, commit_message: str): | def change_repo(repo: str, command: str, commit_message: str): | ||||
path = os.path.join(SWH_ENV_DIR, repo) | path = os.path.join(SWH_ENV_DIR, repo) | ||||
print() | print() | ||||
print("="*50) | print("=" * 50) | ||||
print(f"In {repo}") | print(f"In {repo}") | ||||
# Check the repo doesn't have any uncommitted changes to tracked files | # Check the repo doesn't have any uncommitted changes to tracked files | ||||
proc = subprocess.run( | proc = subprocess.run( | ||||
["git", "-C", path, "status", "--porcelain"], | ["git", "-C", path, "status", "--porcelain"], | ||||
capture_output=True, | capture_output=True, | ||||
encoding="utf8", | encoding="utf8", | ||||
check=True, | check=True, | ||||
Show All 27 Lines | if proc.returncode != 0: | ||||
print(f"Command for {repo} failed.") | print(f"Command for {repo} failed.") | ||||
response = input("Ignore and continue? [Y/n] ") | response = input("Ignore and continue? [Y/n] ") | ||||
if response.lower() in ("", "y"): | if response.lower() in ("", "y"): | ||||
print(f"Skipping {repo}") | print(f"Skipping {repo}") | ||||
return | return | ||||
else: | else: | ||||
exit(1) | exit(1) | ||||
# Show the changes | # Show the changes | ||||
proc = subprocess.run( | proc = subprocess.run( | ||||
["git", "-C", path, "diff", "--color=always"], | ["git", "-C", path, "diff", "--color=always"], | ||||
capture_output=True, | capture_output=True, | ||||
encoding="utf8", | encoding="utf8", | ||||
check=True, | check=True, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |