From d33e96a5cc56b08c66cb02aa29b3066c4a48f7fb Mon Sep 17 00:00:00 2001 From: Rin Date: Sun, 3 May 2026 19:40:03 +0700 Subject: [PATCH] refactor: use parseRepoNameFromUrl in git-clone.ts and remove duplicated logic --- gitnexus/src/server/git-clone.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/gitnexus/src/server/git-clone.ts b/gitnexus/src/server/git-clone.ts index e34c6f84b..7dad84085 100644 --- a/gitnexus/src/server/git-clone.ts +++ b/gitnexus/src/server/git-clone.ts @@ -10,28 +10,11 @@ import path from 'path'; import os from 'os'; import fs from 'fs/promises'; import { isIP } from 'net'; +import { parseRepoNameFromUrl } from '../storage/git'; /** Extract the repository name from a git URL (HTTPS or SSH). */ export function extractRepoName(url: string): string { - const cleaned = url.replace(/\/+$/, ''); - - // For SSH URLs like git@github.com:user/repo.git, we need to handle the colon. - // For HTTPS URLs, the only colon should be in the protocol. - let lastSegment: string; - if (cleaned.includes('@') && cleaned.includes(':') && !cleaned.startsWith('http')) { - // Likely an SSH URL - lastSegment = cleaned.split(/[:/]/).pop() || 'unknown'; - } else { - // Likely an HTTPS URL or local path - lastSegment = cleaned.split('/').pop() || 'unknown'; - } - - const name = lastSegment.replace(/\.git$/, ''); - - // Sanitize the name: - // 1. Prevent argument injection by stripping leading dashes. - // 2. Remove characters that are unsafe for directory names across platforms. - return name.replace(/^-+/, '').replace(/[<>:"/\\|?*]/g, '_') || 'unknown'; + return parseRepoNameFromUrl(url) || 'unknown'; } /** Get the clone target directory for a repo name. */