Fred808 commited on
Commit
6b04d23
·
verified ·
1 Parent(s): cf50506

Upload git_clone.py

Browse files
Files changed (1) hide show
  1. git_clone.py +43 -0
git_clone.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import argparse
4
+
5
+ def clone_repository(repo_url, target_dir=None):
6
+ """
7
+ Clone a git repository to a specified directory.
8
+
9
+ Args:
10
+ repo_url (str): URL of the git repository to clone
11
+ target_dir (str, optional): Target directory for cloning. If None, will clone to current directory
12
+ """
13
+ try:
14
+ # Prepare the command
15
+ cmd = ['git', 'clone', repo_url]
16
+ if target_dir:
17
+ cmd.append(target_dir)
18
+
19
+ # Create target directory if it doesn't exist
20
+ if target_dir and not os.path.exists(target_dir):
21
+ os.makedirs(target_dir)
22
+
23
+ # Execute the clone command
24
+ result = subprocess.run(cmd, capture_output=True, text=True)
25
+
26
+ if result.returncode == 0:
27
+ print(f"Successfully cloned repository: {repo_url}")
28
+ return True
29
+ else:
30
+ print(f"Error cloning repository: {result.stderr}")
31
+ return False
32
+
33
+ except Exception as e:
34
+ print(f"An error occurred: {str(e)}")
35
+ return False
36
+
37
+ if __name__ == "__main__":
38
+ # Hardcoded repository URL and target directory
39
+ repo_url = "https://huggingface.co/facebook/opt-125m" # Replace with your repository URL
40
+ target_directory = None # Change this if you want a specific target directory
41
+
42
+ # Clone the repository
43
+ clone_repository(repo_url, target_directory)