mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(frontend): resolve the deepest owning remote project and refresh VCS info after branch changes
findRemoteProjectForDirectory now returns the longest matching canonical path, so nested linked-server projects attribute sessions to the innermost project. Switching, creating and renaming a local branch invalidate that directory's VCS info query, so branch labels refresh immediately.
This commit is contained in:
1 parent
4b7652451b
commit
adb251081f
8 files changed
+128
-15
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { BranchesTab } from './BranchesTab'
|
||||
@@ -39,7 +39,8 @@ vi.mock('@/components/repo/CreateWorktreeDialog', () => ({
|
||||
CreateWorktreeDialog: () => null,
|
||||
}))
|
||||
|
||||
import { listBranches, getRepo } from '@/api/repos'
|
||||
import { listBranches, getRepo, switchBranch } from '@/api/repos'
|
||||
import { fetchGitStatus } from '@/api/git'
|
||||
|
||||
const createWrapper = () => {
|
||||
const queryClient = new QueryClient({
|
||||
@@ -89,4 +90,35 @@ describe('BranchesTab', () => {
|
||||
|
||||
expect(await screen.findByText('origin/feature')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('invalidates the vcs info of the switched repository', async () => {
|
||||
vi.mocked(switchBranch).mockResolvedValue({
|
||||
id: 1,
|
||||
fullPath: '/abs/repos/my-repo',
|
||||
currentBranch: 'feature',
|
||||
} as never)
|
||||
vi.mocked(fetchGitStatus).mockResolvedValue({
|
||||
branch: 'feature',
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
files: [],
|
||||
hasChanges: false,
|
||||
operation: null,
|
||||
})
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
})
|
||||
const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries')
|
||||
const user = userEvent.setup()
|
||||
render(<BranchesTab repoId={1} currentBranch="main" />, {
|
||||
wrapper: ({ children }) => <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>,
|
||||
})
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: /^feature/ }))
|
||||
|
||||
await waitFor(() => expect(invalidateSpy).toHaveBeenCalledWith({
|
||||
queryKey: ['opencode', 'vcs', '/abs/repos/my-repo', 'info'],
|
||||
exact: true,
|
||||
}))
|
||||
})
|
||||
})
|
||||
@@ -14,7 +14,7 @@ import { useGit } from '@/hooks/useGit'
|
||||
import { GIT_UI_COLORS } from '@/lib/git-status-styles'
|
||||
import { CreateWorktreeDialog } from '@/components/repo/CreateWorktreeDialog'
|
||||
import { IntegrateBranchDialog } from '@/components/source-control/IntegrateBranchDialog'
|
||||
import { invalidateRepoGitCaches, setRepoGitStatusCaches } from '@/lib/queryInvalidation'
|
||||
import { invalidateRepoGitCaches, invalidateVcsInfoCache, setRepoGitStatusCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
interface BranchesTabProps {
|
||||
repoId: number
|
||||
@@ -72,6 +72,7 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
|
||||
queryClient.setQueryData(['repo', repoId], updatedRepo)
|
||||
setRepoGitStatusCaches(queryClient, repoId, status)
|
||||
invalidateRepoGitCaches(queryClient, repoId, { invalidateStatus: false })
|
||||
invalidateVcsInfoCache(queryClient, updatedRepo.fullPath)
|
||||
refetch()
|
||||
showToast.success(`Switched to branch: ${updatedRepo.currentBranch}`)
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user