- {/* Permission/Fork info */}
- {isCheckingPermissions && (
-
-
- Checking repository permissions...
-
- )}
-
- {forkInfo.needsFork && forkInfo.forkOwner && (
-
-
- You don't have push access. Your changes will be pushed to your fork at {forkInfo.forkOwner}/{forkInfo.forkRepo} .
-
-
- )}
-
- {/* Auto-branch creation notice */}
- {currentBranch && (currentBranch === 'main' || currentBranch === 'master') && (
-
-
- You're on the {currentBranch} branch. A feature branch will be automatically created from your PR title for this contribution.
-
-
- )}
-
- {/* Branch comparison */}
-
-
-
- {targetBranch}
-
-
-
- {currentBranch}
-
-
-
- Merge {currentBranch} into {targetBranch}
-
- {(currentBranch === 'main' || currentBranch === 'master') && (
-
- Note: A new branch will be created automatically
-
- )}
-
-
- {/* Error alert */}
- {error && (
-
-
- {error}
-
- )}
-
- {/* Target branch */}
-
- Target Branch
-
-
-
-
-
- {remoteBranches.map((branch) => (
-
- {branch}
-
- ))}
-
-
-
-
- {/* Title */}
-
- Title *
- setTitle(e.target.value)}
- disabled={isCreating}
- />
-
-
- {/* Description */}
-
- Description
-
-
- {/* Create button */}
-
- {isCreating ? (
- <>
-
- {forkInfo.needsFork ? 'Creating fork & PR...' : 'Creating...'}
- >
- ) : forkInfo.needsFork ? (
- <>
-
- Fork & Create PR
- >
- ) : (
- <>
-
- Create Pull Request
- >
- )}
-
-
- {/* Repository info */}
- {remoteInfo && (
-
-
-
- Repository:
-
- {remoteInfo.owner}/{remoteInfo.repo}
-
-
-
- Platform:
-
- {remoteInfo.platform}
-
-
-
-
- )}
-
- );
-}
diff --git a/src/components/git/index.ts b/src/components/git/index.ts
deleted file mode 100644
index f4b93fbe..00000000
--- a/src/components/git/index.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-export { AnnounceRepositoryDialog } from './AnnounceRepositoryDialog';
-export { BranchManager } from './BranchManager';
-export { CompareView } from './CompareView';
-export { DiffViewer } from './DiffViewer';
-export { GitManagementDialog } from './GitManagementDialog';
-export { MergeDialog } from './MergeDialog';
-export { PullRequestDialog } from './PullRequestDialog';
diff --git a/src/hooks/useGitFetch.test.tsx b/src/hooks/useGitFetch.test.tsx
deleted file mode 100644
index 38627b67..00000000
--- a/src/hooks/useGitFetch.test.tsx
+++ /dev/null
@@ -1,720 +0,0 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { renderHook, waitFor } from '@testing-library/react';
-import { useGitFetch } from './useGitFetch';
-import { TestApp } from '@/test/TestApp';
-
-// Create mocks that can be reconfigured per test
-const mockGit = {
- findRoot: vi.fn(),
- listRemotes: vi.fn(),
- currentBranch: vi.fn(),
- resolveRef: vi.fn(),
- fetch: vi.fn(),
-};
-
-const mockToast = vi.fn();
-const mockInvalidateQueries = vi.fn();
-
-// Mock the git operations
-vi.mock('./useGit', () => ({
- useGit: () => ({
- git: mockGit,
- }),
-}));
-
-vi.mock('./useGitSettings', () => ({
- useGitSettings: () => ({
- settings: {
- credentials: [],
- },
- }),
-}));
-
-vi.mock('./useFSPaths', () => ({
- useFSPaths: () => ({
- projectsPath: '/projects',
- }),
-}));
-
-vi.mock('./useToast', () => ({
- useToast: () => ({
- toast: mockToast,
- }),
-}));
-
-// Mock QueryClient to track invalidateQueries calls
-vi.mock('@tanstack/react-query', async () => {
- const actual = await vi.importActual('@tanstack/react-query');
- return {
- ...actual,
- useQueryClient: () => ({
- invalidateQueries: mockInvalidateQueries,
- }),
- };
-});
-
-describe('useGitFetch', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- mockToast.mockClear();
- mockInvalidateQueries.mockClear();
- });
-
- it('returns null state when projectId is null', async () => {
- const { result } = renderHook(() => useGitFetch(null), {
- wrapper: TestApp,
- });
-
- // When projectId is null, the query is disabled and won't fetch
- // So we just check the initial state
- expect(result.current.data).toBeUndefined();
- expect(result.current.isLoading).toBe(false);
- expect(result.current.isSuccess).toBe(false);
- });
-
- it('fetches remote updates successfully when default branch is checked out', async () => {
- // Setup mocks for default branch scenario
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef calls in order:
- // 1. Read symbolic ref for default branch (returns the ref path)
- // 2. Get default branch OID before fetch
- // 3. Get current branch OID before fetch
- // 4. Get default branch OID after fetch
- // 5. Get current branch OID after fetch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default
- .mockResolvedValueOnce('abc123') // before current (same as default)
- .mockResolvedValueOnce('abc123') // after default
- .mockResolvedValueOnce('abc123'); // after current (same as default)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'main',
- remoteUrl: 'https://github.com/test/repo.git',
- hasChanges: false,
- });
-
- // Verify fetch was called
- expect(mockGit.fetch).toHaveBeenCalledWith(
- expect.objectContaining({
- dir: '/projects/test-project',
- remote: 'origin',
- })
- );
- });
-
- it('fetches remote updates successfully when non-default branch is checked out', async () => {
- // Setup mocks for non-default branch scenario
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef calls in order:
- // 1. Read symbolic ref for default branch (returns the ref path)
- // 2. Get default branch OID before fetch
- // 3. Get current branch OID before fetch
- // 4. Get default branch OID after fetch
- // 5. Get current branch OID after fetch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default (main)
- .mockResolvedValueOnce('def456') // before current (feature-branch)
- .mockResolvedValueOnce('abc123') // after default (main)
- .mockResolvedValueOnce('def456'); // after current (feature-branch)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'feature-branch',
- remoteUrl: 'https://github.com/test/repo.git',
- hasChanges: false,
- });
-
- // Verify fetch was called
- expect(mockGit.fetch).toHaveBeenCalledWith(
- expect.objectContaining({
- dir: '/projects/test-project',
- remote: 'origin',
- })
- );
- });
-
- it('detects changes on default branch when checked out', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef to simulate changes on default branch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default
- .mockResolvedValueOnce('abc123') // before current (same as default)
- .mockResolvedValueOnce('xyz789') // after default (changed!)
- .mockResolvedValueOnce('xyz789'); // after current (changed!)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'main',
- hasChanges: true, // Changes detected on default branch
- });
- });
-
- it('detects changes on non-default branch when checked out', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef to simulate changes on non-default branch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default
- .mockResolvedValueOnce('def456') // before current
- .mockResolvedValueOnce('abc123') // after default (no change)
- .mockResolvedValueOnce('xyz789'); // after current (changed!)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'feature-branch',
- hasChanges: true, // Changes detected on current branch
- });
- });
-
- it('detects changes on both default and non-default branches', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef to simulate changes on both branches
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default
- .mockResolvedValueOnce('def456') // before current
- .mockResolvedValueOnce('new111') // after default (changed!)
- .mockResolvedValueOnce('new222'); // after current (changed!)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'feature-branch',
- hasChanges: true, // Changes detected on both branches
- });
- });
-
- it('detects changes on default branch when non-default branch is checked out', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef to simulate changes on default branch only
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main') // symbolic ref
- .mockResolvedValueOnce('abc123') // before default
- .mockResolvedValueOnce('def456') // before current
- .mockResolvedValueOnce('xyz789') // after default (changed!)
- .mockResolvedValueOnce('def456'); // after current (no change)
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- expect(result.current.data).toMatchObject({
- defaultBranch: 'main',
- currentBranch: 'feature-branch',
- hasChanges: true, // Changes detected on default branch
- });
- });
-
- it('can be manually refetched', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Mock resolveRef for initial fetch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- const firstFetchTime = result.current.data?.fetchedAt;
-
- // Setup mocks for refetch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- // Manually trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(result.current.data?.fetchedAt).toBeGreaterThanOrEqual(firstFetchTime || 0);
- });
-
- // Verify fetch was called twice (initial + refetch)
- expect(mockGit.fetch).toHaveBeenCalledTimes(2);
- });
-
- describe('Toast Notifications', () => {
- it('shows toast when default branch changes (on default branch)', async () => {
- // Setup mocks for initial fetch (no changes)
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // No toast on initial load
- expect(mockToast).not.toHaveBeenCalled();
-
- // Setup for refetch with changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('xyz789') // Changed!
- .mockResolvedValueOnce('xyz789');
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(mockToast).toHaveBeenCalledTimes(1);
- });
-
- // Verify toast message
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The main branch has new commits available.',
- variant: 'default',
- });
-
- // Verify git status was invalidated
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(1);
- expect(gitStatusCalls[0][0]).toEqual({
- queryKey: ['git-status', 'test-project'],
- });
- });
-
- it('shows toast when non-default branch changes (on non-default branch)', async () => {
- // Setup mocks for initial fetch (no changes)
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // No toast on initial load
- expect(mockToast).not.toHaveBeenCalled();
-
- // Setup for refetch with changes on feature branch
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('abc123') // main unchanged
- .mockResolvedValueOnce('xyz789'); // feature-branch changed!
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(mockToast).toHaveBeenCalledTimes(1);
- });
-
- // Verify toast message for feature branch
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The feature-branch branch has new commits available.',
- variant: 'default',
- });
-
- // Verify git status was invalidated
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(1);
- expect(gitStatusCalls[0][0]).toEqual({
- queryKey: ['git-status', 'test-project'],
- });
- });
-
- it('shows toast when default branch changes (on non-default branch)', async () => {
- // Setup mocks for initial fetch (no changes)
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // No toast on initial load
- expect(mockToast).not.toHaveBeenCalled();
-
- // Setup for refetch with changes on main branch only
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('xyz789') // main changed!
- .mockResolvedValueOnce('def456'); // feature-branch unchanged
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(mockToast).toHaveBeenCalledTimes(1);
- });
-
- // Verify toast message for main branch
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The main branch has new commits available.',
- variant: 'default',
- });
-
- // Verify git status was invalidated
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(1);
- expect(gitStatusCalls[0][0]).toEqual({
- queryKey: ['git-status', 'test-project'],
- });
- });
-
- it('shows two toasts when both branches change (on non-default branch)', async () => {
- // Setup mocks for initial fetch (no changes)
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('feature-branch');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // No toast on initial load
- expect(mockToast).not.toHaveBeenCalled();
-
- // Setup for refetch with changes on both branches
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('def456')
- .mockResolvedValueOnce('new111') // main changed!
- .mockResolvedValueOnce('new222'); // feature-branch changed!
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(mockToast).toHaveBeenCalledTimes(2);
- });
-
- // Verify both toast messages
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The main branch has new commits available.',
- variant: 'default',
- });
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The feature-branch branch has new commits available.',
- variant: 'default',
- });
-
- // Verify git status was invalidated twice (once per toast)
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(2);
- });
-
- it('does not show toast on initial load', async () => {
- // Setup mocks
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch with changes detected in the fetch itself
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('xyz789') // Changed from before to after fetch
- .mockResolvedValueOnce('xyz789');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // Should report changes in data
- expect(result.current.data?.hasChanges).toBe(true);
-
- // But no toast on initial load
- expect(mockToast).not.toHaveBeenCalled();
- });
-
- it('does not show toast when no changes detected', async () => {
- // Setup mocks for initial fetch
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // Setup for refetch with no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // No toast should be shown
- expect(mockToast).not.toHaveBeenCalled();
-
- // Verify git status was not invalidated (filter out other queries like 'nostr')
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(0);
- });
-
- it('does not show duplicate toast for same branch when default equals current', async () => {
- // Setup mocks for initial fetch
- mockGit.findRoot.mockResolvedValue('/projects/test-project');
- mockGit.listRemotes.mockResolvedValue([
- { remote: 'origin', url: 'https://github.com/test/repo.git' }
- ]);
- mockGit.currentBranch.mockResolvedValue('main');
- mockGit.fetch.mockResolvedValue(undefined);
-
- // Initial fetch - no changes
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123');
-
- const { result } = renderHook(() => useGitFetch('test-project'), {
- wrapper: TestApp,
- });
-
- await waitFor(() => {
- expect(result.current.isSuccess).toBe(true);
- });
-
- // Setup for refetch with changes (both default and current are 'main')
- mockGit.resolveRef
- .mockResolvedValueOnce('ref: refs/remotes/origin/main')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('abc123')
- .mockResolvedValueOnce('xyz789')
- .mockResolvedValueOnce('xyz789');
-
- // Trigger refetch
- await result.current.refetch();
-
- await waitFor(() => {
- expect(mockToast).toHaveBeenCalledTimes(1);
- });
-
- // Should only show one toast (for default branch), not two
- expect(mockToast).toHaveBeenCalledWith({
- title: 'Remote changes detected',
- description: 'The main branch has new commits available.',
- variant: 'default',
- });
-
- // Should only invalidate once
- const gitStatusCalls = mockInvalidateQueries.mock.calls.filter(
- (call) => call[0]?.queryKey?.[0] === 'git-status'
- );
- expect(gitStatusCalls).toHaveLength(1);
- });
- });
-});
diff --git a/src/hooks/useGitFetch.ts b/src/hooks/useGitFetch.ts
deleted file mode 100644
index 32ebcc5e..00000000
--- a/src/hooks/useGitFetch.ts
+++ /dev/null
@@ -1,357 +0,0 @@
-import { useQuery, useQueryClient } from '@tanstack/react-query';
-import { useGit } from './useGit';
-import { useFSPaths } from './useFSPaths';
-import { useGitSettings } from './useGitSettings';
-import { useToast } from './useToast';
-import { findCredentialsForRepo } from '@/lib/gitCredentials';
-import { useEffect, useRef } from 'react';
-
-interface FetchResult {
- defaultBranch: string | null;
- defaultBranchOid: string | null;
- defaultBranchChanged: boolean;
- currentBranch: string | null;
- currentBranchOid: string | null;
- currentBranchChanged: boolean;
- fetchedAt: number;
- hasChanges: boolean;
- remoteUrl: string | null;
-}
-
-/**
- * Hook to fetch updates from remote repository and detect changes.
- * Polls every 60 seconds and shows toast notifications when changes are detected.
- *
- * @param projectId - The project ID to fetch for
- * @returns Query result with manual refetch capability
- */
-export function useGitFetch(projectId: string | null) {
- const { git } = useGit();
- const { projectsPath } = useFSPaths();
- const { settings } = useGitSettings();
- const { toast } = useToast();
- const queryClient = useQueryClient();
-
- // Track which branches we've already notified about to avoid duplicate toasts
- const notifiedBranchesRef = useRef