-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_git_repos.py
More file actions
56 lines (49 loc) · 1.74 KB
/
scan_git_repos.py
File metadata and controls
56 lines (49 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import subprocess
import argparse
def is_git_repo(path):
return os.path.isdir(os.path.join(path, ".git"))
def get_git_info(path):
try:
# Aktueller Branch
branch = subprocess.check_output(
["git", "-C", path, "rev-parse", "--abbrev-ref", "HEAD"],
text=True
).strip()
# Remote-URLs
remotes = subprocess.check_output(
["git", "-C", path, "remote", "-v"],
text=True
).strip().splitlines()
remote_urls = set()
for line in remotes:
parts = line.split()
if len(parts) >= 2:
remote_urls.add(parts[1])
return branch, list(remote_urls)
except subprocess.CalledProcessError:
return None, []
def scan_git_repos(base_dir):
print(f"\n🔍 Scanning Git repositories in: {os.path.abspath(base_dir)}\n")
for folder in os.listdir(base_dir):
full_path = os.path.join(base_dir, folder)
if os.path.isdir(full_path) and is_git_repo(full_path):
branch, remotes = get_git_info(full_path)
print(f"📁 {folder}")
print(f" 🌿 Branch: {branch if branch else 'Unbekannt'}")
if remotes:
for url in remotes:
print(f" 🔗 Remote: {url}")
else:
print(" 🔗 Kein Remote konfiguriert")
print()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Scannt Git-Repositories in einem Verzeichnis.")
parser.add_argument(
"path",
nargs="?",
default=os.path.expanduser("~"),
help="Pfad zum Verzeichnis (optional, Standard: Home-Verzeichnis)"
)
args = parser.parse_args()
scan_git_repos(args.path)