-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghclone_like_git.py
More file actions
79 lines (59 loc) · 3 KB
/
Copy pathghclone_like_git.py
File metadata and controls
79 lines (59 loc) · 3 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
'''
ghclone_like_git: Mimics git clone behavior using GitHub API.
What the code does:
- This script mimics the behavior of `git clone` by directly downloading a tarball of the specified GitHub repository.
- It uses the GitHub API to fetch the tarball, ensuring the repository is downloaded and extracted without using the traditional `git clone` command.
- This method is particularly useful in environments where standard Git operations may face network issues or other restrictions.
Note:
- This script uses HTTP to download the repository, as specified.
- The provided URL (even if it is HTTPS) is converted to the HTTP equivalent for compatibility.
- Or just use `git2 version 1.9.0` !
ManamaMa, Version 1.2
'''
import os
import re
import argparse
def parse_arguments():
parser = argparse.ArgumentParser(description='ghclone_like_git: Mimics git clone behavior.')
parser.add_argument('repository', type=str, help='URL of the repository to clone (e.g., https://github.com/qt/qtbase)')
return parser.parse_args()
def print_info(repo_url, alternative_method):
print('''\nghclone_like_git: Mimics git clone behavior using GitHub API.
What the code does:
- This script mimics the behavior of `git clone` by directly downloading a tarball of the specified GitHub repository.
- It uses the GitHub API to fetch the tarball, ensuring the repository is downloaded and extracted without using the traditional `git clone` command.
- This method is particularly useful in environments where standard Git operations may face network issues or other restrictions.
Note:
- This script uses HTTP to download the repository, as specified.
- The provided URL (even if it is HTTPS) is converted to the HTTP equivalent for compatibility.
''')
print(f"Original URL provided: {repo_url}")
print(f"\033[34mAlternative method:\033[0m git clone {alternative_method}")
def clone_repository(repo_url):
print_info(repo_url, repo_url.replace('https://', 'git://'))
# Convert HTTPS to HTTP
repo_url = repo_url.replace('https://', 'http://')
print(f"Converted URL to HTTP: {repo_url}")
# Regex to extract owner and repository from URL
match = re.match(r'http://github\.com/([^/]+)/([^/]+)', repo_url)
if not match:
print("Invalid GitHub URL. Please provide a valid repository URL.")
return
owner, repo = match.groups()
tarball_url = f'http://api.github.com/repos/{owner}/{repo}/tarball'
print(f"Cloning repository: {owner}/{repo}")
print(f"Downloading from: {tarball_url}")
# Download tarball
print("Downloading tarball...")
os.system(f'curl -L {tarball_url} -o {repo}.tar.gz')
# Extract tarball
print("Extracting tarball...")
os.system(f'tar -xzf {repo}.tar.gz')
print(f"Repository {owner}/{repo} has been cloned successfully.")
def main():
args = parse_arguments()
print(f"ghclone_like_git: Cloning repository {args.repository}")
clone_repository(args.repository)
if __name__ == '__main__':
main()