diff --git a/openhands-sdk/openhands/sdk/extensions/fetch.py b/openhands-sdk/openhands/sdk/extensions/fetch.py index 65589a836ff..eca4966b699 100644 --- a/openhands-sdk/openhands/sdk/extensions/fetch.py +++ b/openhands-sdk/openhands/sdk/extensions/fetch.py @@ -78,7 +78,9 @@ def parse_extension_source(source: str) -> tuple[SourceType, str]: # GitHub shorthand: github:owner/repo[/subpath] if source.startswith("github:"): repo, _ = _split_github_shorthand(source) - url = f"https://github.com/{repo}.git" + # The shorthand may already name the repository file; add the suffix + # only when it is missing. + url = f"https://github.com/{repo.removesuffix('.git')}.git" return (SourceType.GITHUB, url) # Git URLs: detect by protocol/scheme rather than enumerating providers diff --git a/openhands-sdk/openhands/sdk/git/utils.py b/openhands-sdk/openhands/sdk/git/utils.py index 246639132ac..38e697d5802 100644 --- a/openhands-sdk/openhands/sdk/git/utils.py +++ b/openhands-sdk/openhands/sdk/git/utils.py @@ -558,6 +558,10 @@ def is_git_url(source: str) -> bool: if re.match(r"^[\w.-]+@[\w.-]+:", source): return True + # SSH scheme, with or without a user and port + if source.startswith("ssh://"): + return True + # Git protocol if source.startswith("git://"): return True @@ -593,7 +597,12 @@ def normalize_git_url(url: str) -> str: "https://dev.azure.com/org/project/_git/repo" """ if url.startswith(("https://", "http://")) and not url.endswith(".git"): + # Strip the trailing slash before the suffix check, so a URL that + # already names a repository (``repo.git/``) does not gain a second + # suffix from the append below. url = url.rstrip("/") + if url.endswith(".git"): + return url # Azure DevOps resolves ``.git`` as a different, missing repo. if "/_git/" in urlparse(url).path: return url diff --git a/tests/sdk/extensions/test_fetch.py b/tests/sdk/extensions/test_fetch.py index 7c91a116912..03761e0f910 100644 --- a/tests/sdk/extensions/test_fetch.py +++ b/tests/sdk/extensions/test_fetch.py @@ -165,6 +165,25 @@ def test_parse_ssh_with_custom_user(): assert url == ssh_url +def test_parse_ssh_scheme_url(): + ssh_url = "ssh://git@git.example.com:2222/org/repo.git" + assert parse_extension_source(ssh_url) == (SourceType.GIT, ssh_url) + + +def test_parse_github_shorthand_with_git_suffix(): + assert parse_extension_source("github:owner/repo.git") == ( + SourceType.GITHUB, + "https://github.com/owner/repo.git", + ) + + +def test_parse_https_url_with_git_suffix_and_trailing_slash(): + assert parse_extension_source("https://github.com/owner/repo.git/") == ( + SourceType.GIT, + "https://github.com/owner/repo.git", + ) + + def test_parse_relative_path_with_slash(): source_type, url = parse_extension_source("extensions/my-ext") assert source_type == SourceType.LOCAL