|
1 | 1 | # Register this as a proper app using the classic ctypes.windll workaround |
2 | 2 | import ctypes |
3 | 3 | import sys |
| 4 | +from urllib.parse import urlparse |
4 | 5 |
|
5 | 6 | if sys.platform == "win32": |
6 | 7 | ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( |
@@ -6063,13 +6064,35 @@ def _clone(self): |
6063 | 6064 | if not url: |
6064 | 6065 | return |
6065 | 6066 | try: |
6066 | | - if "github.com" in url: |
6067 | | - idx = url.find("github.com") + len("github.com/") |
6068 | | - rest = url[idx:].rstrip("/").replace(".git", "").split("/") |
6069 | | - dev_name, repo_name = rest[0], rest[1] |
| 6067 | + # Support HTTPS/HTTP GitHub URLs and SSH-style GitHub URLs. |
| 6068 | + dev_name = None |
| 6069 | + repo_name = None |
| 6070 | + |
| 6071 | + # SSH-style: git@github.com:user/repo.git |
| 6072 | + if url.startswith("git@github.com:"): |
| 6073 | + path_part = url[len("git@github.com:") :].rstrip("/") |
| 6074 | + parts = path_part.split("/") |
| 6075 | + if len(parts) >= 2: |
| 6076 | + dev_name = parts[0] |
| 6077 | + repo_name = parts[1] |
| 6078 | + else: |
| 6079 | + raise ValueError("Incomplete SSH GitHub URL") |
6070 | 6080 | else: |
6071 | | - parts = url.rstrip("/").split("/") |
6072 | | - dev_name, repo_name = parts[-2], parts[-1].replace(".git", "") |
| 6081 | + parsed = urlparse(url) |
| 6082 | + # Require a proper HTTP(S) URL with github.com as hostname |
| 6083 | + if parsed.scheme not in ("http", "https") or parsed.hostname != "github.com": |
| 6084 | + raise ValueError("Not a GitHub HTTPS/HTTP URL") |
| 6085 | + path = parsed.path.lstrip("/").rstrip("/") |
| 6086 | + parts = path.split("/") |
| 6087 | + if len(parts) < 2: |
| 6088 | + raise ValueError("Incomplete GitHub repository path") |
| 6089 | + dev_name = parts[0] |
| 6090 | + repo_name = parts[1] |
| 6091 | + |
| 6092 | + # Normalize repository name (strip optional .git suffix) |
| 6093 | + if repo_name.endswith(".git"): |
| 6094 | + repo_name = repo_name[: -len(".git")] |
| 6095 | + |
6073 | 6096 | except Exception: |
6074 | 6097 | self.status_lbl.setText("❌ Invalid GitHub URL") |
6075 | 6098 | return |
|
0 commit comments