fix(ui): nested repositories open diffs and report status from the selected repo
Opening a file from the Git panel while a nested repository was selected created the diff tab under the repository path, a key the context panel never displays. Tabs are keyed by the project root; the diff surface resolves the selected nested repository itself. The work-status Project section now reads branch, changes, and PR from the same resolved repository as the Git tab and names the nested folder under the branch so the reader knows which repository the readouts describe.
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { useGitStore } from '@/stores/useGitStore';
|
||||
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
|
||||
import { useNestedGitDirectory } from '@/hooks/useNestedGitDirectory';
|
||||
import { runBackgroundNetworkTask } from '@/lib/background-network';
|
||||
import { useFreshestPrVisualSummaryForBranch } from '@/stores/useGitHubPrStatusStore';
|
||||
import { useSessionMessages } from '@/sync/sync-context';
|
||||
@@ -51,37 +52,54 @@ export const WorkStatusPrimaryGroup: React.FC<Props> = ({ sessionId, directory,
|
||||
const fetchStatus = useGitStore((state) => state.fetchStatus);
|
||||
const clearDiffCache = useGitStore((state) => state.clearDiffCache);
|
||||
|
||||
// The repository the readouts describe. Same resolution as the Git tab: the
|
||||
// session directory itself when it is a repository, otherwise the nested
|
||||
// repository selected (or auto-selected) for it, so a session in a plain
|
||||
// folder of repositories still reports the branch and changes the Git tab
|
||||
// shows. Navigation below stays keyed on `directory` — context-panel tabs
|
||||
// are per project root.
|
||||
const { gitDirectory } = useNestedGitDirectory(directory, { enabled: showRepository });
|
||||
|
||||
const gitStatus = useGitStore(
|
||||
React.useCallback(
|
||||
(state) => (directory ? state.directories.get(directory)?.status ?? null : null),
|
||||
[directory],
|
||||
(state) => (gitDirectory ? state.directories.get(gitDirectory)?.status ?? null : null),
|
||||
[gitDirectory],
|
||||
),
|
||||
);
|
||||
|
||||
// Warm the shared git cache through the background-network gate so the panel
|
||||
// never competes with the chat's own bootstrap traffic for sockets.
|
||||
React.useEffect(() => {
|
||||
if (!showRepository || !directory || !git) return;
|
||||
void runBackgroundNetworkTask(() => ensureStatus(directory, git));
|
||||
}, [directory, git, ensureStatus, showRepository]);
|
||||
if (!showRepository || !gitDirectory || !git) return;
|
||||
void runBackgroundNetworkTask(() => ensureStatus(gitDirectory, git));
|
||||
}, [gitDirectory, git, ensureStatus, showRepository]);
|
||||
|
||||
// Own the live invalidation for the repository readout. The desktop
|
||||
// composer's changed-files row no longer renders, so this panel must not
|
||||
// depend on ChatInput (or an opened Git surface) to refresh the shared cache
|
||||
// on its behalf.
|
||||
React.useEffect(() => {
|
||||
if (!showRepository || !directory || !git) return;
|
||||
if (!showRepository || !gitDirectory || !git) return;
|
||||
return sessionEvents.onGitRefreshHint((hint) => {
|
||||
if (normalizePath(hint.directory) !== normalizePath(directory)) return;
|
||||
if (normalizePath(hint.directory) !== normalizePath(gitDirectory)) return;
|
||||
if (hint.paths?.length) {
|
||||
clearDiffCache(directory, hint.paths);
|
||||
clearDiffCache(gitDirectory, hint.paths);
|
||||
}
|
||||
void fetchStatus(directory, git, { silent: true });
|
||||
void fetchStatus(gitDirectory, git, { silent: true });
|
||||
});
|
||||
}, [clearDiffCache, directory, fetchStatus, git, showRepository]);
|
||||
}, [clearDiffCache, gitDirectory, fetchStatus, git, showRepository]);
|
||||
|
||||
const branch = gitStatus?.current?.trim() || null;
|
||||
|
||||
// Which repository under the project the branch belongs to. Only meaningful
|
||||
// when the readouts come from a nested repository; for a project that is a
|
||||
// repository itself the section header already names it.
|
||||
const nestedRepoLabel = React.useMemo(() => {
|
||||
if (!directory || !gitDirectory || gitDirectory === directory) return null;
|
||||
const rootPrefix = `${directory}/`;
|
||||
return gitDirectory.startsWith(rootPrefix) ? gitDirectory.slice(rootPrefix.length) : gitDirectory;
|
||||
}, [directory, gitDirectory]);
|
||||
|
||||
const availableWorktreesByProject = useSessionUIStore((state) => state.availableWorktreesByProject);
|
||||
// Worktrees normally sit beside rather than beneath their project directory,
|
||||
// so a prefix match alone cannot find their owning project. Reuse the shared
|
||||
@@ -103,7 +121,7 @@ export const WorkStatusPrimaryGroup: React.FC<Props> = ({ sessionId, directory,
|
||||
// Read-only: PR watching is owned by the background tracker. Starting a watch
|
||||
// here would multiply GitHub requests per open session, which is exactly the
|
||||
// fan-out the PR-status concurrency gate exists to prevent.
|
||||
const prSummary = useFreshestPrVisualSummaryForBranch(directory, branch);
|
||||
const prSummary = useFreshestPrVisualSummaryForBranch(gitDirectory, branch);
|
||||
|
||||
// `getCurrentModel` is an imperative getter: its reference never changes, so
|
||||
// calling it in render subscribes to nothing. Subscribe to the selected model
|
||||
@@ -274,6 +292,16 @@ export const WorkStatusPrimaryGroup: React.FC<Props> = ({ sessionId, directory,
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{nestedRepoLabel ? (
|
||||
<WorkStatusRow
|
||||
icon="folder"
|
||||
onClick={directory ? () => openSurface('git') : undefined}
|
||||
ariaLabel={t('chat.workStatus.action.openGit')}
|
||||
label={nestedRepoLabel}
|
||||
muted
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{changed ? (
|
||||
<WorkStatusRow
|
||||
icon="file-edit"
|
||||
|
||||
@@ -1799,13 +1799,17 @@ export const GitView: React.FC<GitViewProps> = ({ isActive }) => {
|
||||
[handleRevertPaths]
|
||||
);
|
||||
|
||||
// Context-panel tabs are keyed by the project root, not by the repository
|
||||
// being diffed: the diff surface resolves the selected nested repository on
|
||||
// its own, so opening the tab under `gitDirectory` would park it under a key
|
||||
// the panel never displays.
|
||||
const handleViewChangeDiff = React.useCallback((path: string, staged: boolean) => {
|
||||
if (gitDirectory && !isMobile) {
|
||||
openContextDiff(gitDirectory, path, staged);
|
||||
if (currentDirectory && !isMobile) {
|
||||
openContextDiff(currentDirectory, path, staged);
|
||||
return;
|
||||
}
|
||||
navigateToDiff(path, staged);
|
||||
}, [gitDirectory, isMobile, navigateToDiff, openContextDiff]);
|
||||
}, [currentDirectory, isMobile, navigateToDiff, openContextDiff]);
|
||||
|
||||
const openStashes = React.useCallback(() => setIsStashesDialogOpen(true), []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user