-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_cloner.py
More file actions
32 lines (25 loc) · 990 Bytes
/
Copy pathgit_cloner.py
File metadata and controls
32 lines (25 loc) · 990 Bytes
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
import os
import subprocess
file_path = "github_links.txt"
clone_dir = "git_clone/"
if not os.path.exists(clone_dir):
os.makedirs(clone_dir)
with open(file_path, "r") as file:
repo_links = file.readlines()
for link in repo_links:
link = link.strip()
if link:
repo_name = link.split("/")[-1].replace(".git", "")
repo_path = os.path.join(clone_dir, repo_name)
if os.path.exists(repo_path):
print(f"Repository '{repo_name}' already exists. Skipping clone.")
else:
print(f"Cloning repository: {link}")
try:
subprocess.run(["git", "clone", link], cwd=clone_dir, check=True)
print(f"Successfully cloned {link}")
except subprocess.CalledProcessError as e:
print(f"Failed to clone {link}: {e}")
except Exception as e:
print(f"An error occurred while cloning {link}: {e}")
print("All repositories have been processed.")