fix: treat name-only git remotes as local-only
This commit is contained in:
@@ -549,6 +549,40 @@ describe('useAutoSync', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('pullAndPush skips push for local-only vaults with no remote', async () => {
|
||||
const { result } = renderSync()
|
||||
await waitFor(() => {
|
||||
expect(result.current.syncStatus).toBe('idle')
|
||||
})
|
||||
|
||||
mockInvokeFn.mockClear()
|
||||
mockInvokeFn.mockImplementation((cmd: string) => {
|
||||
if (cmd === 'get_conflict_files') return Promise.resolve([])
|
||||
if (cmd === 'get_last_commit_info') return Promise.resolve(MOCK_COMMIT_INFO)
|
||||
if (cmd === 'git_remote_status') return Promise.resolve({ branch: 'main', ahead: 0, behind: 0, hasRemote: false })
|
||||
if (cmd === 'git_pull') {
|
||||
return Promise.resolve({
|
||||
status: 'no_remote',
|
||||
message: 'No remote configured',
|
||||
updatedFiles: [],
|
||||
conflictFiles: [],
|
||||
})
|
||||
}
|
||||
if (cmd === 'git_push') return Promise.resolve({ status: 'ok', message: 'Pushed successfully' })
|
||||
return Promise.resolve(upToDate())
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
result.current.pullAndPush()
|
||||
})
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('git_pull', { vaultPath: '/Users/luca/Laputa' })
|
||||
expect(mockInvokeFn).not.toHaveBeenCalledWith('git_push', { vaultPath: '/Users/luca/Laputa' })
|
||||
expect(result.current.syncStatus).toBe('idle')
|
||||
})
|
||||
})
|
||||
|
||||
it('surfaces pull conflicts and pull errors during recovery pushes', async () => {
|
||||
let mode: 'conflict' | 'error' = 'conflict'
|
||||
|
||||
|
||||
@@ -521,7 +521,17 @@ export function useAutoSync({
|
||||
})
|
||||
}
|
||||
|
||||
const pushOutcomes = await Promise.all(pullVaultPaths.map(async (path) => ({
|
||||
const pushVaultPaths = pullOutcomes
|
||||
.filter((outcome) => outcome.result.status !== 'no_remote')
|
||||
.map((outcome) => outcome.vaultPath)
|
||||
|
||||
if (pushVaultPaths.length === 0) {
|
||||
clearConflictState(setSyncStatus, setConflictFiles, setConflictVaultPath)
|
||||
void refreshRemoteStatus(pullVaultPaths)
|
||||
return
|
||||
}
|
||||
|
||||
const pushOutcomes = await Promise.all(pushVaultPaths.map(async (path) => ({
|
||||
result: await tauriCall<GitPushResult>('git_push', { vaultPath: path }),
|
||||
vaultPath: path,
|
||||
})))
|
||||
|
||||
@@ -141,7 +141,7 @@ export interface GitPullResult {
|
||||
}
|
||||
|
||||
export interface GitPushResult {
|
||||
status: 'ok' | 'rejected' | 'auth_error' | 'network_error' | 'error'
|
||||
status: 'ok' | 'rejected' | 'auth_error' | 'network_error' | 'no_remote' | 'error'
|
||||
message: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user