Skip to content

Conversation

Copy link

Copilot AI commented Jan 11, 2026

Swift's URL(string:) fails to parse Git remote URLs like 192.1.1.1:3000/repo.git or forgejo.local:3000/repo.git, causing UnsupportedRemoteURL errors when pushing to self-hosted Git instances. These URLs work with libgit2 directly (terminal lg2 push succeeds) but fail in the credentials helper.

Changes

  • Added normalizeRemoteURL() static helper method to LocalGitCredentialsHelper to detect and fix bare IP:port or hostname:port patterns by prepending http:// scheme before URL parsing
  • Updated credentialsForRemote() to use normalizeRemoteURL before parsing remote URLs
  • Updated onClone() in SourceControlContainer to use normalizeRemoteURL for user-provided URLs during clone operations
  • Added comprehensive tests for URL normalization in CodeUITests covering all URL format scenarios
  • Preserves existing behavior for scp-like syntax (git@host:path) and fully-qualified URLs (https://host/path)

The fix is applied consistently across all Git URL parsing points to ensure IP:port URLs work for push, pull, fetch, and clone operations.

Example

// Before: URL(string: "192.1.1.1:3000/repo.git") → nil (throws UnsupportedRemoteURL)
// After:  normalizeRemoteURL("192.1.1.1:3000/repo.git") → "http://192.1.1.1:3000/repo.git"
//         URL(string: "http://192.1.1.1:3000/repo.git") → valid URL with host/port

Handles all URL formats:

  • Bare IP:port → adds http:// prefix
  • Hostname:port → adds http:// prefix
  • SCP-like (git@host:path) → preserved unchanged
  • Full URLs with schemes → preserved unchanged

Testing

  • ✅ Added unit tests for all URL normalization scenarios
  • ✅ Manual verification confirms IP:port URLs now parse correctly
  • ✅ Existing parseRemoteURL tests still pass
  • ✅ Code review passed with no issues
Original prompt

This section details on the original issue you should resolve

<issue_title>Code.LocalGitCredentialsHelper.HelperError error 0 - selfhosted forgejo</issue_title>
<issue_description>Hello, I've been troubleshooting for the past couple days and failing. I keep getting the error in the title when attempting to push to my private instance of forgejo.

I'm able to clone a repo via link. I've tried my password credentials and personal tokens.

I am able to push to github. And I'm able to push using a different git app once it prompts to remove SSL.

I do have local network active. I've tried making fresh repos to test, I've tried a complete fresh install of the docker running the instance, I've tried deleting config files.

( EDIT: I am able to run lg2 push and then entering my username and token and successfully push from the terminal. But via the gui I cannot)

I'm not really sure what else to do and so am hoping someone can point me in the right direction to fix the issue.

I was able to successfully push to my repo at first when using the app - but I broke it somehow and no amount of troubleshooting seems to be able to fix it sadly :(

Image</issue_description>

<agent_instructions>Analze the issue to see why LocalGitCredentialsHelper failed to parse IP style git addresses. Give suggestions to fix the issues in the issue thread. Do not touch the codebase yet</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@bummoblizard Hi. LocalGitCredentialsHelper.HelperError refers to UnsupportedRemoteURL. That means the git remote url is malformed. Please check the content of .git/config for any malformed urls. Alternatively, try re-cloning the repository and start fresh. @bummoblizard Yep, that seems to be the reason. Swift's URL(init: String) couldn't seem to parse "192.1.1.1:1000". Could you share your .git/config for me to verify? @bummoblizard Adding a git:// prefix to the local ip address in .git/config should work Image @bummoblizard Thanks for letting me know. I will take a look again and fix the problem soon

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix Code.LocalGitCredentialsHelper.HelperError for selfhosted forgejo Fix LocalGitCredentialsHelper parsing of IP:port Git remote URLs Jan 11, 2026
Copilot AI requested a review from bummoblizard January 11, 2026 16:05
@bummoblizard
Copy link
Member

@copilot Make the changes. Make sure normalizeRemoteURL is used consistently whenever git URL parsing is needed.

Co-authored-by: bummoblizard <38398443+bummoblizard@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 11, 2026

@copilot Make the changes. Make sure normalizeRemoteURL is used consistently whenever git URL parsing is needed.

Implemented in commit 41b07ee. The normalizeRemoteURL() method is now used consistently in:

  • credentialsForRemote() for remote operations (push/pull/fetch)
  • onClone() for repository cloning

This fixes IP:port URLs like 192.1.1.1:3000/repo.git and forgejo.local:3000/repo.git by adding http:// prefix before parsing, while preserving existing behavior for SCP-like syntax and fully-qualified URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code.LocalGitCredentialsHelper.HelperError error 0 - selfhosted forgejo

2 participants