control1 / git_clone.py
Fred808's picture
Upload git_clone.py
6b04d23 verified
import os
import subprocess
import argparse
def clone_repository(repo_url, target_dir=None):
"""
Clone a git repository to a specified directory.
Args:
repo_url (str): URL of the git repository to clone
target_dir (str, optional): Target directory for cloning. If None, will clone to current directory
"""
try:
# Prepare the command
cmd = ['git', 'clone', repo_url]
if target_dir:
cmd.append(target_dir)
# Create target directory if it doesn't exist
if target_dir and not os.path.exists(target_dir):
os.makedirs(target_dir)
# Execute the clone command
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f"Successfully cloned repository: {repo_url}")
return True
else:
print(f"Error cloning repository: {result.stderr}")
return False
except Exception as e:
print(f"An error occurred: {str(e)}")
return False
if __name__ == "__main__":
# Hardcoded repository URL and target directory
repo_url = "https://huggingface.co/facebook/opt-125m" # Replace with your repository URL
target_directory = None # Change this if you want a specific target directory
# Clone the repository
clone_repository(repo_url, target_directory)