From 8b8958f7c8d6782590ffaa73949d761acb7f5864 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Dec 2025 01:45:12 -0600 Subject: [PATCH] Refactor ProjectsManager.cloneProject to accept an options object --- src/components/RepositoryCard.tsx | 5 ++++- src/lib/ProjectsManager.test.ts | 10 ++++++++-- src/lib/ProjectsManager.ts | 12 ++++++++++-- src/pages/Clone.tsx | 5 ++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/RepositoryCard.tsx b/src/components/RepositoryCard.tsx index b55db679..867322fe 100644 --- a/src/components/RepositoryCard.tsx +++ b/src/components/RepositoryCard.tsx @@ -41,7 +41,10 @@ export function RepositoryCard({ repo }: RepositoryCardProps) { await projectsManager.init(); // Clone the repository using the Nostr URI - const project = await projectsManager.cloneProject(repo.name, nostrURI.toString()); + const project = await projectsManager.cloneProject({ + name: repo.name, + repoUrl: nostrURI.toString(), + }); toast({ title: t('nostrRepositoryImportedSuccessfully'), diff --git a/src/lib/ProjectsManager.test.ts b/src/lib/ProjectsManager.test.ts index 2f87d6a2..9c87d619 100644 --- a/src/lib/ProjectsManager.test.ts +++ b/src/lib/ProjectsManager.test.ts @@ -457,7 +457,10 @@ describe('ProjectsManager', () => { Object.assign(projectsManager, { git: mockGit }); // Attempt to clone a project - await expect(projectsManager.cloneProject('test-project', 'https://github.com/test/repo.git')) + await expect(projectsManager.cloneProject({ + name: 'test-project', + repoUrl: 'https://github.com/test/repo.git', + })) .rejects.toThrow('Clone failed'); // Verify that the project directory was cleaned up @@ -488,7 +491,10 @@ describe('ProjectsManager', () => { try { // Attempt to clone a project - await expect(projectsManager.cloneProject('test-project', 'https://github.com/test/repo.git')) + await expect(projectsManager.cloneProject({ + name: 'test-project', + repoUrl: 'https://github.com/test/repo.git', + })) .rejects.toThrow('Clone failed'); // Should have logged a cleanup warning diff --git a/src/lib/ProjectsManager.ts b/src/lib/ProjectsManager.ts index 2b9ce8b3..3eaf3038 100644 --- a/src/lib/ProjectsManager.ts +++ b/src/lib/ProjectsManager.ts @@ -494,7 +494,14 @@ export class ProjectsManager { } } - async cloneProject(name: string, repoUrl: string, customId?: string, options?: { depth?: number }): Promise { + async cloneProject(options: { + name: string; + repoUrl: string; + customId?: string; + depth?: number; + remote?: string; + }): Promise { + const { name, repoUrl, customId, depth, remote } = options; const id = customId || await this.generateUniqueProjectId(name); // Check if project with this ID already exists when using custom ID @@ -512,7 +519,8 @@ export class ProjectsManager { dir: projectPath, url: repoUrl, singleBranch: true, - depth: options?.depth, // Use depth if provided, otherwise clone full history + depth, // Use depth if provided, otherwise clone full history + remote, // Use remote if provided, otherwise defaults to 'origin' }); // Get filesystem stats for timestamps diff --git a/src/pages/Clone.tsx b/src/pages/Clone.tsx index 40da7076..542023a8 100644 --- a/src/pages/Clone.tsx +++ b/src/pages/Clone.tsx @@ -156,7 +156,10 @@ export default function Clone() { const repoName = await extractRepoName(targetUrl); // Clone the repository (Git class handles both regular Git URLs and Nostr URIs) - const project = await projectsManager.cloneProject(repoName, targetUrl.trim()); + const project = await projectsManager.cloneProject({ + name: repoName, + repoUrl: targetUrl.trim(), + }); // Determine success message based on URL type const isNostrUri = targetUrl.startsWith('nostr://');