Download git_clone.py from Fred808/control1: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/Fred808/control1/resolve/main/git_clone.py
- Command line
-
hf download hf://spaces/Fred808/control1/git_clone.py
-
curl -L -o git_clone.py https://huggingface.co/spaces/Fred808/control1/resolve/main/git_clone.py
1.48 kB
| 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) |