Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Stop reporting a branch for folders that are not git repositories (#4878)

sarah1e9e8ec0e13e
diff --git a/.changeset/no-branch-for-non-git-projects.md b/.changeset/no-branch-for-non-git-projects.md
new file mode 100644
index 000000000..9ae4d8614
--- /dev/null
+++ b/.changeset/no-branch-for-non-git-projects.md
@@ -0,0 +1,5 @@
+---
+'@inkeep/open-knowledge-server': patch
+---
+
+A project folder that is not a git repository no longer reports a branch named "main". The editor footer and the project switcher now show no branch for such projects.
diff --git a/knip.config.ts b/knip.config.ts
index 8b615429f..6a38348d8 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -143,15 +143,11 @@ export default {
'packages/server': {
entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],
project: 'src/**',
- ignoreDependencies: [
- '@types/shell-quote',
- ],
+ ignoreDependencies: ['@types/shell-quote'],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],
- ignoreDependencies: [
- 'yjs',
- ],
+ ignoreDependencies: ['yjs'],
},
'packages/desktop': {
entry: [
diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
index a28cc2b18..8a60e5826 100644
--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
index 4fc2c11f9..6fcdc23f2 100644
--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { normalizeBridge } from '@inkeep/open-knowledge-core';
import { updateYFragment } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.ts
index 9f2f6feb6..40b5cdfd6 100644
--- a/packages/app/tests/integration/interior-edit-freshness.test.ts
+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
index 2a085742b..93666af70 100644
--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.ts
index 878d5196b..867598d34 100644
--- a/packages/app/tests/integration/producer-guard-wiring.test.ts
+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
index 4ada3cf26..0970ac12f 100644
--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
@@ -1,4 +1,3 @@
-
import { randomUUID } from 'node:crypto';
import { afterEach, describe, expect, test } from 'vitest';
import { agentWriteMd, createTestServer, type TestServer } from './test-harness';
diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
index cbe2b705f..b632185e1 100644
--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
@@ -1,4 +1,3 @@
-
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
index 89bc9b4d9..c530ce4ba 100644
--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
@@ -1,4 +1,3 @@
-
import { randomUUID } from 'node:crypto';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import type * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.ts
index a78aeb0e4..d3767adc9 100644
--- a/packages/app/tests/integration/undo-after-rollback.test.ts
+++ b/packages/app/tests/integration/undo-after-rollback.test.ts
@@ -1,4 +1,3 @@
-
import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.ts
index e7cc69c3f..b076f955c 100644
--- a/packages/app/tests/integration/undo-recycle-reset.test.ts
+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.ts
index 9ddcd0730..7935e35f8 100644
--- a/packages/app/tests/integration/undo-rederive-survival.test.ts
+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts
@@ -1,4 +1,3 @@
-
import { prependFrontmatter } from '@inkeep/open-knowledge-core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.ts
index 2a597ec3d..f4cc8a286 100644
--- a/packages/core/src/bridge/compose.ts
+++ b/packages/core/src/bridge/compose.ts
@@ -1,4 +1,3 @@
-
import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';
export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index 01ef76a9f..8fb428b90 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index fb0ba5a7c..fc267cbea 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index fa3cfcd86..bfd7e3109 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/server/src/api-config-system-composition.test.ts b/packages/server/src/api-config-system-composition.test.ts
index ed8c9f408..8d9c21d41 100644
--- a/packages/server/src/api-config-system-composition.test.ts
+++ b/packages/server/src/api-config-system-composition.test.ts
@@ -1,3 +1,4 @@
+import { execFileSync } from 'node:child_process';
import {
existsSync,
mkdirSync,
@@ -11,19 +12,23 @@ import {
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { resolve } from 'node:path';
+import { resolveShadowDir } from '@inkeep/open-knowledge-core/shadow-repo-layout';
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest';
import type { BootedServer } from './boot.ts';
+import { CC1Broadcaster } from './cc1-broadcast.ts';
import {
bootCompositionRig,
makeCaptureRes,
makeSyntheticReq,
} from './composition-rig.test-helper.ts';
+import * as headWatcherModule from './head-watcher.ts';
import {
type ConfigSystemRouteDeps,
createConfigSystemRoutes,
} from './http/config-system-routes.ts';
import { checkLocalOpSecurity } from './local-op-security.ts';
import type { PinoLogger } from './logger.ts';
+import { saveInMemoryCheckpoint } from './shadow-repo.ts';
const statSyncFaults = vi.hoisted(() => new Map<string, NodeJS.ErrnoException>());
const statSyncOverrides = vi.hoisted(() => new Map<string, unknown>());
@@ -76,7 +81,6 @@ function buildConfigSystemRoutes(overrides: Partial<ConfigSystemRouteDeps> = {})
ephemeral: false,
log: noopLog,
ready: undefined,
- durabilityState: { getActiveBranch: () => 'main' },
serverInstanceId: 'test-instance',
getDiskAckSVs: undefined,
getCollabClientCount: undefined,
@@ -94,6 +98,7 @@ function buildConfigSystemRoutes(overrides: Partial<ConfigSystemRouteDeps> = {})
getFileIndex: () => new Map(),
shadowRef: undefined,
getCurrentBranch: undefined,
+ getReportedBranch: undefined,
installedAgentsCache: {
probeAll: (async () => ({})) as ConfigSystemRouteDeps['installedAgentsCache']['probeAll'],
},
@@ -465,3 +470,140 @@ describe('flat rescue-buffer listing — nested documents', () => {
expect(warns).toContain('[rescue] skipping uninspectable rescue entry');
});
});
+
+describe('server-info branch reporting', () => {
+ async function serverInfoBody(
+ overrides: Partial<ConfigSystemRouteDeps>,
+ ): Promise<{ currentBranch?: string }> {
+ const out = await dispatch(buildConfigSystemRoutes(overrides), '/api/server-info', {
+ host: '127.0.0.1',
+ });
+ expect(out.status).toBe(200);
+ return out.body as { currentBranch?: string };
+ }
+
+ test('reports the checked-out branch when the project is a git repository', async () => {
+ const body = await serverInfoBody({ getReportedBranch: () => 'feat/app-header' });
+
+ expect(body.currentBranch).toBe('feat/app-header');
+ });
+
+ test('reports the git branch when the storage accessor returns no branch', async () => {
+ const body = await serverInfoBody({
+ getCurrentBranch: () => null,
+ getReportedBranch: () => 'feat/app-header',
+ });
+
+ expect(body.currentBranch).toBe('feat/app-header');
+ });
+
+ test('omits the branch when the project has no readable git HEAD', async () => {
+ const body = await serverInfoBody({ getReportedBranch: () => null });
+
+ expect(body).not.toHaveProperty('currentBranch');
+ });
+
+ test('omits the branch when no branch accessor is wired', async () => {
+ const body = await serverInfoBody({ getReportedBranch: undefined });
+
+ expect(body).not.toHaveProperty('currentBranch');
+ });
+});
+
+describe('server-info branch reporting over the composed listener', () => {
+ let branchTmpRoot: string;
+ const booted: BootedServer[] = [];
+
+ async function bootOn(dirPrefix: string, init?: (dir: string) => void): Promise<BootedServer> {
+ const contentDir = mkdtempSync(resolve(branchTmpRoot, dirPrefix));
+ init?.(contentDir);
+ const server = await bootCompositionRig(contentDir);
+ booted.push(server);
+ await server.ready;
+ return server;
+ }
+
+ async function currentBranchOf(server: BootedServer): Promise<string | undefined> {
+ const res = await fetch(`http://127.0.0.1:${server.port}/api/server-info`);
+ expect(res.status).toBe(200);
+ return ((await res.json()) as { currentBranch?: string }).currentBranch;
+ }
+
+ beforeAll(async () => {
+ branchTmpRoot = await mkdtemp(resolve(tmpdir(), 'ok-config-system-branch-'));
+ }, 60_000);
+
+ afterAll(async () => {
+ for (const server of booted) await server.destroy('test-cleanup');
+ await rm(branchTmpRoot, { recursive: true, force: true });
+ });
+
+ test('a git project reports its checked-out branch', async () => {
+ const emitServerInfo = vi.spyOn(CC1Broadcaster.prototype, 'emitServerInfo');
+ try {
+ const server = await bootOn('repo-', (dir) => {
+ execFileSync('git', ['init', '-q', '-b', 'feat/probe'], { cwd: dir });
+ });
+
+ expect(await currentBranchOf(server)).toBe('feat/probe');
+ expect(emitServerInfo).toHaveBeenCalledWith(expect.any(String), 'feat/probe');
+ } finally {
+ emitServerInfo.mockRestore();
+ }
+ }, 60_000);
+
+ test('a failed HEAD watcher reports the git branch while rescue uses the storage branch', async () => {
+ const startHeadWatcher = vi
+ .spyOn(headWatcherModule, 'startHeadWatcher')
+ .mockRejectedValueOnce(new Error('watcher unavailable'));
+ try {
+ const server = await bootOn('watcher-failed-', (dir) => {
+ execFileSync('git', ['init', '-q', '-b', 'feat/probe'], { cwd: dir });
+ });
+
+ expect(server.degraded).toContain('head-watcher');
+ expect(await currentBranchOf(server)).toBe('feat/probe');
+
+ const shadow = {
+ gitDir: resolveShadowDir(server.contentDir),
+ workTree: server.contentDir,
+ };
+ await saveInMemoryCheckpoint(shadow, '', {
+ kind: 'external-change-rescue',
+ docName: 'storage-branch.md',
+ contents: '# Storage branch\n',
+ label: 'Storage branch rescue',
+ branch: 'main',
+ metadata: { incomingDiskSha: '' },
+ });
+ await saveInMemoryCheckpoint(shadow, '', {
+ kind: 'external-change-rescue',
+ docName: 'reported-branch.md',
+ contents: '# Reported branch\n',
+ label: 'Reported branch rescue',
+ branch: 'feat/probe',
+ metadata: { incomingDiskSha: '' },
+ });
+
+ const rescue = await fetch(`http://127.0.0.1:${server.port}/api/rescue`);
+ expect(rescue.status).toBe(200);
+ const entries = (await rescue.json()) as Array<{ docName: string }>;
+ expect(entries.map((entry) => entry.docName)).toContain('storage-branch.md');
+ expect(entries.map((entry) => entry.docName)).not.toContain('reported-branch.md');
+ } finally {
+ startHeadWatcher.mockRestore();
+ }
+ }, 60_000);
+
+ test('a plain folder reports no branch rather than a fabricated "main"', async () => {
+ const emitServerInfo = vi.spyOn(CC1Broadcaster.prototype, 'emitServerInfo');
+ try {
+ const server = await bootOn('plain-');
+
+ expect(await currentBranchOf(server)).toBeUndefined();
+ expect(emitServerInfo).toHaveBeenCalledWith(expect.any(String), undefined);
+ } finally {
+ emitServerInfo.mockRestore();
+ }
+ }, 60_000);
+});
diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.ts
index 47648f52c..5885a4faf 100644
--- a/packages/server/src/api-extension.ts
+++ b/packages/server/src/api-extension.ts
@@ -1268,6 +1268,7 @@ export interface ApiExtensionOptions {
flushGitCommit?: () => Promise<void>;
flushContributors?: () => Promise<void>;
getCurrentBranch?: () => string | null;
+ getReportedBranch?: () => string | null;
getDiskAckSVs?: () => Record<string, string>;
getCollabClientCount?: () => number;
contentRoot?: string;
@@ -1443,6 +1444,7 @@ export function createApiExtension(
flushGitCommit,
flushContributors,
getCurrentBranch,
+ getReportedBranch,
getDiskAckSVs,
getCollabClientCount,
contentRoot,
@@ -4731,7 +4733,6 @@ export function createApiExtension(
ephemeral,
log,
ready,
- durabilityState,
serverInstanceId,
getDiskAckSVs,
getCollabClientCount,
@@ -4749,6 +4750,7 @@ export function createApiExtension(
getFileIndex,
shadowRef,
getCurrentBranch,
+ getReportedBranch,
installedAgentsCache,
});
const lintRoutes = createLintRoutes({
diff --git a/packages/server/src/cc1-broadcast.test.ts b/packages/server/src/cc1-broadcast.test.ts
index 63ca4846e..463d9d147 100644
--- a/packages/server/src/cc1-broadcast.test.ts
+++ b/packages/server/src/cc1-broadcast.test.ts
@@ -11,6 +11,7 @@ import {
CC1ConfigValidationRejectedPayloadSchema,
CC1DerivedViewPayloadSchema,
CC1DiskAckPayloadSchema,
+ CC1ServerInfoPayloadSchema,
CONFIG_DOC_NAME_OKIGNORE,
CONFIG_DOC_NAME_PROJECT,
CONFIG_DOC_NAME_PROJECT_LOCAL,
@@ -238,6 +239,18 @@ describe('CC1Broadcaster', () => {
expect(CC1_CHANNEL_BRANCH_SWITCHED).toBe('branch-switched');
});
+ test('emitServerInfo omits the branch when none was supplied', () => {
+ broadcaster.emitServerInfo('server-instance');
+ const payload = CC1ServerInfoPayloadSchema.parse(JSON.parse(broadcasts[0]));
+ expect(payload).not.toHaveProperty('currentBranch');
+ });
+
+ test('emitServerInfo includes a real branch when supplied', () => {
+ broadcaster.emitServerInfo('server-instance', 'feat/probe');
+ const payload = CC1ServerInfoPayloadSchema.parse(JSON.parse(broadcasts[0]));
+ expect(payload.currentBranch).toBe('feat/probe');
+ });
+
test('emitBranchSwitched publishes payload with branch + seq=1 on first call', () => {
broadcaster.emitBranchSwitched('main');
expect(broadcasts).toHaveLength(1);
diff --git a/packages/server/src/http/config-system-routes.ts b/packages/server/src/http/config-system-routes.ts
index 0bf2ec157..00f2ded88 100644
--- a/packages/server/src/http/config-system-routes.ts
+++ b/packages/server/src/http/config-system-routes.ts
@@ -40,7 +40,6 @@ import { isConfigDoc, isSystemDoc } from '../cc1-broadcast.ts';
import { collabUrlFromRequestHeaders } from '../collab-bootstrap-url.ts';
import { getLocalDir } from '../config/paths.ts';
import { isSupportedDocFile, stripDocExtension } from '../doc-extensions.ts';
-import type { DocumentDurabilityState } from '../document-durability-state.ts';
import { deriveDetection, embedProbeRing } from '../embed-probe.ts';
import {
FileEmbeddingsBackend,
@@ -68,7 +67,6 @@ export interface ConfigSystemRouteDeps {
ephemeral: boolean;
log: PinoLogger;
ready: Promise<void> | undefined;
- durabilityState: Pick<DocumentDurabilityState, 'getActiveBranch'>;
serverInstanceId: string;
getDiskAckSVs: (() => Record<string, string>) | undefined;
getCollabClientCount: (() => number) | undefined;
@@ -90,6 +88,7 @@ export interface ConfigSystemRouteDeps {
getFileIndex: () => ReadonlyMap<string, FileIndexEntry>;
shadowRef: ShadowRef | undefined;
getCurrentBranch: (() => string | null) | undefined;
+ getReportedBranch: (() => string | null) | undefined;
installedAgentsCache: Pick<ReturnType<typeof createInstalledAgentsProbe>, 'probeAll'>;
}
@@ -105,7 +104,6 @@ export function createConfigSystemRoutes(deps: ConfigSystemRouteDeps): ConfigSys
ephemeral,
log,
ready,
- durabilityState,
serverInstanceId,
getDiskAckSVs,
getCollabClientCount,
@@ -123,6 +121,7 @@ export function createConfigSystemRoutes(deps: ConfigSystemRouteDeps): ConfigSys
getFileIndex,
shadowRef,
getCurrentBranch,
+ getReportedBranch,
installedAgentsCache,
} = deps;
@@ -138,7 +137,7 @@ export function createConfigSystemRoutes(deps: ConfigSystemRouteDeps): ConfigSys
);
});
}
- const currentBranch = durabilityState.getActiveBranch();
+ const currentBranch = getReportedBranch?.() ?? undefined;
const currentDiskAckSVs = getDiskAckSVs?.();
const boot = getBootTimings();
const collabClients = getCollabClientCount?.();
@@ -148,7 +147,7 @@ export function createConfigSystemRoutes(deps: ConfigSystemRouteDeps): ConfigSys
ServerInfoSuccessSchema,
{
serverInstanceId,
- currentBranch,
+ ...(currentBranch !== undefined ? { currentBranch } : {}),
...(currentDiskAckSVs !== undefined ? { currentDiskAckSVs } : {}),
...(boot !== undefined ? { boot } : {}),
...(collabClients !== undefined ? { collabClients } : {}),
diff --git a/packages/server/src/server-factory.ts b/packages/server/src/server-factory.ts
index 0898354d1..ce8be6c63 100644
--- a/packages/server/src/server-factory.ts
+++ b/packages/server/src/server-factory.ts
@@ -489,6 +489,10 @@ export function createServer(options: ServerOptions): ServerInstance {
} = options;
const log = getLogger('server');
+ let headWatcher: HeadWatcherHandle | null = null;
+ const getStorageBranch = () => headWatcher?.getLastKnownBranch() ?? null;
+ const getReportedBranch = () =>
+ headWatcher ? headWatcher.getLastKnownBranch() : readProjectHeadState(projectDir).branch;
const generatedIndexWarningScope = createGeneratedIndexWarningScope(resolve(contentDir));
let cc1Broadcaster: CC1Broadcaster | null = null;
const initialBranch = readProjectHeadState(projectDir).branch ?? 'main';
@@ -1729,7 +1733,7 @@ export function createServer(options: ServerOptions): ServerInstance {
maintenanceCoordinator = gitEnabled
? createMaintenanceCoordinator({
getShadow: () => shadowRef.current ?? null,
- getCurrentBranch: () => headWatcher?.getLastKnownBranch() ?? null,
+ getCurrentBranch: getStorageBranch,
contentRoot: contentRoot ?? '',
projectGitDir: resolveGitDir(projectDir) ?? undefined,
isWriterLive: (writerId) => {
@@ -1766,7 +1770,7 @@ export function createServer(options: ServerOptions): ServerInstance {
contentRoot,
derivedDocumentIndex,
configHomedirOverride,
- getCurrentBranch: () => headWatcher?.getLastKnownBranch() ?? null,
+ getCurrentBranch: getStorageBranch,
resolveEmbed,
resolveSize,
getPrincipal: () => loadedPrincipal,
@@ -2139,7 +2143,8 @@ export function createServer(options: ServerOptions): ServerInstance {
shadowRef,
flushGitCommit: () => persistence.flushPendingGitCommit(),
flushContributors: () => persistence.flushContributors(),
- getCurrentBranch: () => headWatcher?.getLastKnownBranch() ?? null,
+ getCurrentBranch: getStorageBranch,
+ getReportedBranch,
getDiskAckSVs: () => cc1Broadcaster?.getLatestDiskAckSVsAsBase64() ?? {},
getCollabClientCount: options.getCollabClientCount,
contentRoot,
@@ -2206,7 +2211,7 @@ export function createServer(options: ServerOptions): ServerInstance {
bridgeLossReporter = createBridgeDeriveLossReporter({
shadow: () => shadowRef.current,
ring: lossRing,
- getBranch: () => headWatcher?.getLastKnownBranch() ?? 'main',
+ getBranch: () => getStorageBranch() ?? 'main',
contentRoot: contentRoot ?? '',
});
sessionManager.attachBridgeLossReporter(bridgeLossReporter);
@@ -2218,7 +2223,7 @@ export function createServer(options: ServerOptions): ServerInstance {
schema,
shadowRef,
contentRoot,
- getCurrentBranch: () => headWatcher?.getLastKnownBranch() ?? null,
+ getCurrentBranch: getStorageBranch,
resolveEmbed,
resolveSize,
deferGuardEnabled,
@@ -2455,7 +2460,7 @@ export function createServer(options: ServerOptions): ServerInstance {
): Promise<void> => {
incrementDiskAuthoritativeIngest();
const ours = serializeDoc(docName) ?? '';
- const branch = headWatcher?.getLastKnownBranch() ?? 'main';
+ const branch = getStorageBranch() ?? 'main';
const theirsH = contentHash(theirs).slice(0, 6);
const liveOnlyContentAtRisk = ours !== '' && ours !== theirs;
const rescue: 'not-needed' | 'rescued' | 'lost' = !liveOnlyContentAtRisk
@@ -2722,7 +2727,7 @@ export function createServer(options: ServerOptions): ServerInstance {
const isDirty = rescueUnflushedEditsBeforeTeardown(
docName,
- headWatcher?.getLastKnownBranch() ?? 'main',
+ getStorageBranch() ?? 'main',
'delete',
true,
);
@@ -2763,11 +2768,7 @@ export function createServer(options: ServerOptions): ServerInstance {
};
const loadedBeforeIndex = hocuspocus.documents.get(oldDocName);
const isDirty = loadedBeforeIndex
- ? rescueUnflushedEditsBeforeTeardown(
- oldDocName,
- headWatcher?.getLastKnownBranch() ?? 'main',
- 'rename',
- )
+ ? rescueUnflushedEditsBeforeTeardown(oldDocName, getStorageBranch() ?? 'main', 'rename')
: false;
if (loadedBeforeIndex) freezeAsRenamed(loadedBeforeIndex);
@@ -2922,7 +2923,6 @@ export function createServer(options: ServerOptions): ServerInstance {
}
let watcher: WatcherHandle | null = null;
- let headWatcher: HeadWatcherHandle | null = null;
let syncEngine: SyncEngine | null = null;
let inflightDestroy: Promise<void> | null = null;
@@ -3620,7 +3620,7 @@ export function createServer(options: ServerOptions): ServerInstance {
try {
systemDocConnection = await hocuspocus.openDirectConnection(SYSTEM_DOC_NAME);
- cc1Broadcaster?.emitServerInfo(serverInstanceId, getActiveBranch());
+ cc1Broadcaster?.emitServerInfo(serverInstanceId, getReportedBranch() ?? undefined);
} catch (err) {
log.error(
{ err },