| 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:
|
|
|
| cmd = ['git', 'clone', repo_url]
|
| if target_dir:
|
| cmd.append(target_dir)
|
|
|
|
|
| if target_dir and not os.path.exists(target_dir):
|
| os.makedirs(target_dir)
|
|
|
|
|
| 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__":
|
|
|
| repo_url = "https://huggingface.co/facebook/opt-125m"
|
| target_directory = None
|
|
|
|
|
| clone_repository(repo_url, target_directory) |