When push is rejected due to remote having newer commits, the bottom bar now shows "Pull required" (orange). Clicking it pulls then auto-pushes. Conflicted notes show an inline banner with "Keep mine" / "Keep theirs" buttons. A new "Pull from Remote" command is available in Cmd+K and the Vault menu. Clicking the sync badge opens a popup showing branch name, ahead/behind counts, and a Pull button. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { useCallback, useState } from 'react'
|
|
import type { GitPushResult } from '../types'
|
|
|
|
interface CommitFlowConfig {
|
|
savePending: () => Promise<void | boolean>
|
|
loadModifiedFiles: () => Promise<void>
|
|
commitAndPush: (message: string) => Promise<GitPushResult>
|
|
setToastMessage: (msg: string | null) => void
|
|
onPushRejected?: () => void
|
|
}
|
|
|
|
/** Manages the Commit & Push dialog state and the save→commit→push flow. */
|
|
export function useCommitFlow({ savePending, loadModifiedFiles, commitAndPush, setToastMessage, onPushRejected }: CommitFlowConfig) {
|
|
const [showCommitDialog, setShowCommitDialog] = useState(false)
|
|
|
|
const openCommitDialog = useCallback(async () => {
|
|
await savePending()
|
|
await loadModifiedFiles()
|
|
setShowCommitDialog(true)
|
|
}, [savePending, loadModifiedFiles])
|
|
|
|
const handleCommitPush = useCallback(async (message: string) => {
|
|
setShowCommitDialog(false)
|
|
try {
|
|
await savePending()
|
|
const result = await commitAndPush(message)
|
|
if (result.status === 'ok') {
|
|
setToastMessage('Committed and pushed')
|
|
} else if (result.status === 'rejected') {
|
|
setToastMessage('Committed, but push rejected — remote has new commits. Pull first.')
|
|
onPushRejected?.()
|
|
} else {
|
|
setToastMessage(result.message)
|
|
}
|
|
loadModifiedFiles()
|
|
} catch (err) {
|
|
console.error('Commit failed:', err)
|
|
setToastMessage(`Commit failed: ${err}`)
|
|
}
|
|
}, [savePending, commitAndPush, loadModifiedFiles, setToastMessage, onPushRejected])
|
|
|
|
const closeCommitDialog = useCallback(() => setShowCommitDialog(false), [])
|
|
|
|
return { showCommitDialog, openCommitDialog, handleCommitPush, closeCommitDialog }
|
|
}
|