Clone non-owned Nostr repos to "upstream" remote

This commit is contained in:
Alex Gleason committed 2025-12-23 02:01:28 -06:00
1 parent 8b8958f7c8
commit 956dfb5099
3 files changed
+9 -5

No files matched your search

+3
View File
@@ -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({
+4 -3
View File
@@ -499,9 +499,9 @@ export class ProjectsManager {
repoUrl: string;
customId?: string;
depth?: number;
remote?: string;
fork?: boolean;
}): Promise<Project> {
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
+2 -2
View File
@@ -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,
});