diff --git a/src/components/git-sync/steps/ConfigureRepoStep.tsx b/src/components/git-sync/steps/ConfigureRepoStep.tsx index 88443e57..ca6e4f6e 100644 --- a/src/components/git-sync/steps/ConfigureRepoStep.tsx +++ b/src/components/git-sync/steps/ConfigureRepoStep.tsx @@ -2,7 +2,6 @@ import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Alert, AlertDescription } from '@/components/ui/alert'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useGit } from '@/hooks/useGit'; import { useGitStatus } from '@/hooks/useGitStatus'; @@ -20,6 +19,8 @@ import type { NostrEvent } from '@nostrify/nostrify'; import { NostrURI } from '@/lib/NostrURI'; import { useGitAutosync } from '@/hooks/useGitAutosync'; import { ArrowUp } from 'lucide-react'; +import { ForcePushDialog } from './ForcePushDialog'; +import { SyncStepError } from './SyncStepError'; // Helper function to convert kebab-case to Title Case function kebabToTitleCase(str: string): string { @@ -41,7 +42,8 @@ export function ConfigureRepoStep({ const [repoName, setRepoName] = useState(kebabToTitleCase(projectId)); const [isRepoNameManuallyEdited, setIsRepoNameManuallyEdited] = useState(false); const [isPushing, setIsPushing] = useState(false); - const [error, setError] = useState(null); + const [error, setError] = useState(null); + const [showForcePushDialog, setShowForcePushDialog] = useState(false); const { user } = useCurrentUser(); const { git } = useGit(); @@ -74,9 +76,10 @@ export function ConfigureRepoStep({ setIsRepoNameManuallyEdited(true); }; - const handlePushInitial = async () => { - setIsPushing(true); - setError(null); + // Shared push logic for both initial push and force push + const executePush = async (force: boolean = false) => { + // Store the URL we're trying to add so we can remove it on error + let remoteAdded = false; try { if (selectedProvider.id === 'nostr') { @@ -196,12 +199,14 @@ export function ConfigureRepoStep({ url: nostrURI.toString(), force: true, }); + remoteAdded = true; // Push to Nostr (the rest of the Nostr logic is handled internally by git.push) await git.push({ dir, remote: 'origin', ref: gitStatus?.currentBranch || 'main', + force, }); } else { // Validate repository URL @@ -216,12 +221,14 @@ export function ConfigureRepoStep({ url: repositoryUrl, force: true, // Override if exists }); + remoteAdded = true; // Push to remote await git.push({ dir, remote: 'origin', ref: gitStatus?.currentBranch || 'main', + force, }); } @@ -238,8 +245,45 @@ export function ConfigureRepoStep({ // Show success state onSuccess(); } catch (err) { - const message = err instanceof Error ? err.message : 'Failed to push'; - setError(message); + const error = err instanceof Error ? err : new Error(force ? 'Failed to force push' : 'Failed to push'); + + // If we added the remote but push failed, remove it + if (remoteAdded) { + try { + await git.deleteRemote({ dir, remote: 'origin' }); + } catch { + // Ignore errors when cleaning up remote + } + } + + throw error; // Re-throw so caller can handle + } + }; + + const handlePushInitial = async () => { + setIsPushing(true); + setError(null); + + try { + await executePush(false); + } catch (err) { + const error = err instanceof Error ? err : new Error('Failed to push'); + setError(error); + } finally { + setIsPushing(false); + } + }; + + const handleForcePush = async () => { + setIsPushing(true); + setError(null); + setShowForcePushDialog(false); + + try { + await executePush(true); + } catch (err) { + const error = err instanceof Error ? err : new Error('Failed to force push'); + setError(error); } finally { setIsPushing(false); } @@ -343,9 +387,13 @@ export function ConfigureRepoStep({ {error && ( - - {error} - + setError(null)} + onForcePush={() => setShowForcePushDialog(true)} + remoteName={selectedProvider.name} + context="configure" + /> )}
@@ -360,6 +408,13 @@ export function ConfigureRepoStep({ {isPushing ? 'Pushing...' : 'Push'}
+ + ); } @@ -386,9 +441,13 @@ export function ConfigureRepoStep({ {error && ( - - {error} - + setError(null)} + onForcePush={() => setShowForcePushDialog(true)} + remoteName={selectedProvider.name} + context="configure" + /> )}
@@ -407,6 +466,13 @@ export function ConfigureRepoStep({ )}
+ + ); } diff --git a/src/components/git-sync/steps/SyncStepError.tsx b/src/components/git-sync/steps/SyncStepError.tsx index 539ce3c6..be261b13 100644 --- a/src/components/git-sync/steps/SyncStepError.tsx +++ b/src/components/git-sync/steps/SyncStepError.tsx @@ -8,14 +8,16 @@ import { getSentryInstance } from '@/lib/sentry'; interface SyncStepErrorProps { error: Error; onDismiss: () => void; - onForcePull: () => void; + onForcePull?: () => void; onForcePush: () => void; - onPull: () => void; - remoteUrl: URL; + onPull?: () => void; + remoteUrl?: URL; remoteName: string; + /** Context for error messages - 'sync' for existing remotes, 'configure' for initial setup */ + context?: 'sync' | 'configure'; } -export function SyncStepError({ error, onDismiss, onForcePull, onForcePush, onPull, remoteName, remoteUrl }: SyncStepErrorProps) { +export function SyncStepError({ error, onDismiss, onForcePull, onForcePush, onPull, remoteName, remoteUrl, context = 'sync' }: SyncStepErrorProps) { const renderForcePullButton = () => (