Skip to content

gitlens.remotes Custom throws TypeError crash when Regex fails to match (Monorepo/SSH Environment) #4852

@bedge

Description

@bedge

Description

I have encountered a hard crash in GitLens when configuring a type: "Custom" remote in a complex environment (Monorepo + SSH + Detached HEAD).

When the user-provided regex in gitlens.remotes fails to match the remote string (e.g., because the regex is too strict or GitLens strips the protocol before matching), the extension throws an unhandled TypeError instead of failing gracefully or logging a warning.

This crashes the integration for the workspace, preventing any remote URL generation.

Environment
GitLens Version: 17.8.1

VS Code Version: 1.107.1

Remote Type: SSH (e.g., [email protected]:group/project.git)

Workspace Context: Monorepo (Root is a sub-folder of the open workspace) / Detached HEAD

Steps to Reproduce
Open a Workspace: Open a folder where the Git repository is nested in a subdirectory.

Configure Settings: Add a type: "Custom" remote configuration with a strict regex that expects the full SSH protocol prefix.

"gitlens.remotes": [
  {
    "domain": "ssh.git.company.internal",
    "type": "Custom",
    "regex": "^ssh\\.git\\.company\\.internal[:/](?<repo>.+)$",
    "urls": {
        "repository": "https://git.company.internal/${repo}"
    }
  }
]

Trigger Action: Reload the window and run the command "GitLens: Copy Remote File URL".

Observe Crash: Because GitLens likely normalizes the remote string (potentially stripping the domain/protocol) before passing it to the regex, the strict regex fails to match.

Expected: GitLens ignores the custom provider and falls back to default behavior or logs a warning.

Actual: GitLens crashes with the following error in the Output channel:

Error Log


[info] OpenOnRemoteCommand
TypeError: Cannot read properties of undefined (reading 'indexOf')
    at CustomRemote.splitPath ...
(Analysis: It appears CustomRemote.splitPath attempts to access the regex match result array without checking if it is null.)

Workaround & Side Effects
The only way to prevent the crash is to use a "Catch-All" regex that matches anything (even an empty string prefix): "regex": "(?.+?)(?:\.git)?$"

However, because this regex is so greedy, it unintentionally matches other remotes (like github.com) if they are not explicitly defined in the gitlens.remotes array. This causes GitHub remotes to generate broken URLs pointing to the custom domain.

Required Workaround Config: To stabilize the environment, users must explicitly define github.com (to protect it) and use the greedy regex for the custom remote (to prevent the crash):

"gitlens.remotes": [
  {
    "domain": "github.com",
    "type": "GitHub"
  },
  {
    "domain": "ssh.git.company.internal",
    "type": "Custom",
    "regex": "(?<repo>.+?)(?:\\.git)?$",
    "urls": { ... }
  }
]

GitLens Version

17.8.1

VS Code Version

Version: 1.107.1
Commit: 994fd12f8d3a5aa16f17d42c041e5809167e845a
Date: 2025-12-17T14:15:14.850Z
Electron: 39.2.3
ElectronBuildId: 12895514
Chromium: 142.0.7444.175
Node.js: 22.21.1
V8: 14.2.231.21-electron.0
OS: Linux x64 6.14.0-37-generic

Git Version

git version 2.43.0

Logs, Screenshots, Screen Captures, etc

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNeeds to be looked at

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions