From 46affcbdcc82aafa468ce0b023bca8a7e6a9f393 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Dec 2025 17:44:13 -0600 Subject: [PATCH] Add "Force Push" functionality --- .../git-sync/steps/ForcePushDialog.tsx | 71 +++++++++++++++++++ src/components/git-sync/steps/SyncStep.tsx | 20 +++++- .../git-sync/steps/SyncStepError.tsx | 50 ++++++++++--- 3 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 src/components/git-sync/steps/ForcePushDialog.tsx diff --git a/src/components/git-sync/steps/ForcePushDialog.tsx b/src/components/git-sync/steps/ForcePushDialog.tsx new file mode 100644 index 00000000..aee0e1d5 --- /dev/null +++ b/src/components/git-sync/steps/ForcePushDialog.tsx @@ -0,0 +1,71 @@ +import { AlertTriangle } from 'lucide-react'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; + +interface ForcePushDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + onConfirm: () => void; + remoteName?: string; +} + +export function ForcePushDialog({ + open, + onOpenChange, + onConfirm, + remoteName = 'the remote' +}: ForcePushDialogProps) { + const handleConfirm = () => { + onOpenChange(false); + onConfirm(); + }; + + return ( + + + + + + Force Push - Overwrite Remote History? + + +

+ This will completely overwrite the remote repository on {remoteName} with your local version, permanently deleting any commits and changes on {remoteName} that don't exist locally. +

+
+

What will be deleted from {remoteName}:

+
    +
  • All commits on {remoteName} that aren't in your local repository
  • +
  • Any work by other contributors not in your local copy
  • +
  • The entire commit history will be replaced with your local history
  • +
+
+

+ Warning: This operation cannot be undone and may affect other collaborators. Only use this if you're certain your local version is correct. +

+
+
+ + + + +
+
+ ); +} diff --git a/src/components/git-sync/steps/SyncStep.tsx b/src/components/git-sync/steps/SyncStep.tsx index 7dc1d531..7ba11aae 100644 --- a/src/components/git-sync/steps/SyncStep.tsx +++ b/src/components/git-sync/steps/SyncStep.tsx @@ -12,6 +12,7 @@ import { import { ExternalFavicon } from '@/components/ExternalFavicon'; import { SyncStepError } from './SyncStepError'; import { ForcePullDialog } from './ForcePullDialog'; +import { ForcePushDialog } from './ForcePushDialog'; import { useGitStatus } from '@/hooks/useGitStatus'; import { useGitSettings } from '@/hooks/useGitSettings'; import { useGit } from '@/hooks/useGit'; @@ -23,7 +24,7 @@ import { NostrURI } from '@/lib/NostrURI'; import { ngitWebUrl } from '@/lib/ngitWebUrl'; import { useQueryClient } from '@tanstack/react-query'; -type GitOperation = 'sync' | 'pull' | 'push' | 'force-pull'; +type GitOperation = 'sync' | 'pull' | 'push' | 'force-pull' | 'force-push'; export function SyncStep({ projectId }: StepProps) { const queryClient = useQueryClient(); @@ -35,6 +36,7 @@ export function SyncStep({ projectId }: StepProps) { const [syncSuccess, setSyncSuccess] = useState(false); const [dropdownOpen, setDropdownOpen] = useState(false); const [showForcePullDialog, setShowForcePullDialog] = useState(false); + const [showForcePushDialog, setShowForcePushDialog] = useState(false); const { data: gitStatus } = useGitStatus(projectId); const { settings } = useGitSettings(); @@ -135,6 +137,12 @@ export function SyncStep({ projectId }: StepProps) { }); }; + const handleForcePush = async () => { + await executeGitOperation('force-push', async () => { + await git.push({ dir, remote: 'origin', ref, force: true }); + }); + }; + // Temporary feedback state helper const showTemporaryFeedback = useCallback(( setter: (value: boolean) => void, @@ -244,6 +252,8 @@ export function SyncStep({ projectId }: StepProps) { return 'Push'; case 'force-pull': return 'Force Pull'; + case 'force-push': + return 'Force Push'; case 'sync': return 'Sync'; default: @@ -315,6 +325,7 @@ export function SyncStep({ projectId }: StepProps) { error={error} onDismiss={() => setError(null)} onForcePull={() => setShowForcePullDialog(true)} + onForcePush={() => setShowForcePushDialog(true)} onPull={handlePull} /> )} @@ -373,6 +384,13 @@ export function SyncStep({ projectId }: StepProps) { onConfirm={handleForcePull} remoteName={providerInfo?.name} /> + + ); } diff --git a/src/components/git-sync/steps/SyncStepError.tsx b/src/components/git-sync/steps/SyncStepError.tsx index 6978a11b..ca0fad98 100644 --- a/src/components/git-sync/steps/SyncStepError.tsx +++ b/src/components/git-sync/steps/SyncStepError.tsx @@ -1,5 +1,5 @@ import { Errors as GitErrors } from 'isomorphic-git'; -import { AlertTriangle, X, ArrowDown } from 'lucide-react'; +import { AlertTriangle, X, ArrowDown, ArrowUp } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; @@ -7,10 +7,11 @@ interface SyncStepErrorProps { error: Error; onDismiss: () => void; onForcePull: () => void; + onForcePush: () => void; onPull: () => void; } -export function SyncStepError({ error, onDismiss, onForcePull, onPull }: SyncStepErrorProps) { +export function SyncStepError({ error, onDismiss, onForcePull, onForcePush, onPull }: SyncStepErrorProps) { const renderForcePullButton = () => ( + ); + const renderDismissButton = () => ( - {renderForcePullButton()} +