diff --git a/src/components/git-sync/steps/SyncStep.tsx b/src/components/git-sync/steps/SyncStep.tsx
index bee5d5e2..08d58e1b 100644
--- a/src/components/git-sync/steps/SyncStep.tsx
+++ b/src/components/git-sync/steps/SyncStep.tsx
@@ -1,5 +1,6 @@
+import { Errors as GitErrors } from 'isomorphic-git';
import { useState, useCallback } from 'react';
-import { Zap, Copy, Check, RefreshCw, EllipsisVertical, CloudOff, ExternalLink, ChevronDown, ArrowDown, ArrowUp, X } from 'lucide-react';
+import { Zap, Copy, Check, RefreshCw, EllipsisVertical, CloudOff, ExternalLink, ChevronDown, ArrowDown, ArrowUp, X, AlertTriangle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
@@ -10,6 +11,16 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@/components/ui/alert-dialog';
import { ExternalFavicon } from '@/components/ExternalFavicon';
import { useGitStatus } from '@/hooks/useGitStatus';
import { useGitSettings } from '@/hooks/useGitSettings';
@@ -22,7 +33,7 @@ import { NostrURI } from '@/lib/NostrURI';
import { ngitWebUrl } from '@/lib/ngitWebUrl';
import { useQueryClient } from '@tanstack/react-query';
-type GitOperation = 'sync' | 'pull' | 'push';
+type GitOperation = 'sync' | 'pull' | 'push' | 'force-pull';
export function SyncStep({ projectId }: StepProps) {
const queryClient = useQueryClient();
@@ -33,6 +44,7 @@ export function SyncStep({ projectId }: StepProps) {
const [copiedUrl, setCopiedUrl] = useState(false);
const [syncSuccess, setSyncSuccess] = useState(false);
const [dropdownOpen, setDropdownOpen] = useState(false);
+ const [showForcePullDialog, setShowForcePullDialog] = useState(false);
const { data: gitStatus } = useGitStatus(projectId);
const { settings } = useGitSettings();
@@ -99,6 +111,40 @@ export function SyncStep({ projectId }: StepProps) {
});
};
+ const handleForcePull = async () => {
+ await executeGitOperation('force-pull', async () => {
+ // Step 1: Fetch latest changes from remote
+ await git.fetch({
+ dir,
+ remote: 'origin',
+ ref,
+ singleBranch: true,
+ });
+
+ // Step 2: Get the remote commit SHA
+ const remoteRef = `refs/remotes/origin/${ref}`;
+ const remoteSha = await git.resolveRef({ dir, ref: remoteRef });
+
+ // Step 3: Force update the current branch to point to remote
+ await git.writeRef({
+ dir,
+ ref: `refs/heads/${ref}`,
+ value: remoteSha,
+ force: true,
+ });
+
+ // Step 4: Force checkout all files (overwrite local changes)
+ await git.checkout({
+ dir,
+ ref,
+ force: true,
+ });
+
+ // Invalidate git status to refresh UI
+ queryClient.invalidateQueries({ queryKey: ['git-status', projectId] });
+ });
+ };
+
// Temporary feedback state helper
const showTemporaryFeedback = useCallback((
setter: (value: boolean) => void,
@@ -196,6 +242,196 @@ export function SyncStep({ projectId }: StepProps) {
const providerInfo = getProviderInfo();
+ // Get the button label based on current operation
+ const getButtonLabel = (): string => {
+ if (!isSyncing) return 'Sync';
+
+ switch (currentOperation) {
+ case 'pull':
+ return 'Pull';
+ case 'push':
+ return 'Push';
+ case 'force-pull':
+ return 'Force Pull';
+ case 'sync':
+ return 'Sync';
+ default:
+ return 'Sync';
+ }
+ };
+
+ const renderForcePullButton = () => (
+
+ );
+
+ // Render special error UI based on error type
+ const renderError = () => {
+ if (!error) return null;
+
+ // MergeNotSupportedError - offer force pull
+ if (error instanceof GitErrors.MergeNotSupportedError) {
+ return (
+
+ This will permanently discard all local changes and reset your repository to match the remote. +
++ This action cannot be undone. Any uncommitted work will be lost. +
+What will happen:
+