Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

sourceControl.ts

19 lines787 Bytes

1const SCP_SSH_REMOTE_PATTERN = /^[a-zA-Z0-9._-]+@([^:/]+):/;
2// Git reads `host:path` as SSH too, leaving the user to ssh config. A single letter is a Windows
3// drive and `::` names a remote helper.
4const USERLESS_SCP_SSH_REMOTE_PATTERN =
5 /^(\[[^\]@/\\\s]+\]|[^@:/\\\s[\]]{2,}):(?!:)\/?[^/\s]+(?:\/[^/\s]+)*\/?$/u;
6​
7/** Null unless the remote is `host:path`, with no user. */
8export function userlessScpRemoteHost(remoteUrl: string): string | null {
9 return USERLESS_SCP_SSH_REMOTE_PATTERN.exec(remoteUrl.trim())?.[1] ?? null;
11​
12export function isSshRemoteUrl(remoteUrl: string): boolean {
13 const trimmed = remoteUrl.trim();
14 return (
15 SCP_SSH_REMOTE_PATTERN.test(trimmed) ||
16 trimmed.toLowerCase().startsWith("ssh://") ||
17 userlessScpRemoteHost(trimmed) !== null
18 );