diff --git a/src/components/RepositoryCard.tsx b/src/components/RepositoryCard.tsx index 867322fe..8c6dc3de 100644 --- a/src/components/RepositoryCard.tsx +++ b/src/components/RepositoryCard.tsx @@ -12,6 +12,7 @@ import { NostrURI } from '@/lib/NostrURI'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; import { useTranslation } from 'react-i18next'; +import { useCurrentUser } from '@/hooks/useCurrentUser'; interface RepositoryCardProps { repo: Repository; @@ -19,6 +20,7 @@ interface RepositoryCardProps { export function RepositoryCard({ repo }: RepositoryCardProps) { const { data: authorData } = useAuthor(repo.pubkey); + const { user } = useCurrentUser(); const navigate = useNavigate(); const projectsManager = useProjectsManager(); const { toast } = useToast(); @@ -44,6 +46,7 @@ export function RepositoryCard({ repo }: RepositoryCardProps) { const project = await projectsManager.cloneProject({ name: repo.name, repoUrl: nostrURI.toString(), + fork: user?.pubkey !== repo.pubkey, }); toast({ diff --git a/src/lib/ProjectsManager.ts b/src/lib/ProjectsManager.ts index 3eaf3038..0267b5e2 100644 --- a/src/lib/ProjectsManager.ts +++ b/src/lib/ProjectsManager.ts @@ -499,9 +499,9 @@ export class ProjectsManager { repoUrl: string; customId?: string; depth?: number; - remote?: string; + fork?: boolean; }): Promise { - const { name, repoUrl, customId, depth, remote } = options; + const { name, repoUrl, customId, depth, fork = false } = options; const id = customId || await this.generateUniqueProjectId(name); // Check if project with this ID already exists when using custom ID @@ -515,12 +515,13 @@ export class ProjectsManager { try { // Clone the repository (Git class now handles Nostr URIs automatically) + // When forking, use 'upstream' as the remote name instead of 'origin' await this.git.clone({ dir: projectPath, url: repoUrl, singleBranch: true, depth, // Use depth if provided, otherwise clone full history - remote, // Use remote if provided, otherwise defaults to 'origin' + remote: fork ? 'upstream' : undefined, // Use 'upstream' for forks, otherwise defaults to 'origin' }); // Get filesystem stats for timestamps diff --git a/src/lib/git.ts b/src/lib/git.ts index bb8b1778..0ec523c1 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -1288,9 +1288,9 @@ export class Git { throw lastError || new Error('All clone attempts failed'); } - // After successful clone, update the origin remote to point to the Nostr URI + // After successful clone, update the remote to point to the Nostr URI await this.setRemoteURL({ - remote: 'origin', + remote: options.remote || 'origin', dir: options.dir, url: options.url, });