Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Honor the Git default branch for new projects (PRD-8184) (#7442)
Andrew Mikofalvyff5cc8cb05da
diff --git a/.changeset/honor-git-default-branch.md b/.changeset/honor-git-default-branch.mdnew file mode 100644index 000000000..ad59226d3--- /dev/null+++ b/.changeset/honor-git-default-branch.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Honor the configured Git default branch when creating a project repository.diff --git a/knip.config.ts b/knip.config.tsindex 1342c6bf1..0cdeeb401 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -157,7 +157,9 @@ export default {'src/shadow-fixture-launch.test-helper.mjs',],project: 'src/**',- ignoreDependencies: ['@types/shell-quote'],+ ignoreDependencies: [+ '@types/shell-quote',+ ],},'packages/cli': {entry: [@@ -167,7 +169,9 @@ export default {'src/parse-worker.ts','src/bin.ts',],- ignoreDependencies: ['yjs'],+ ignoreDependencies: [+ 'yjs',+ ],},'packages/desktop': {entry: [diff --git a/packages/app/tests/integration/branch-switch-agent-write.test.ts b/packages/app/tests/integration/branch-switch-agent-write.test.tsindex c95a5456d..d648d5e8a 100644--- a/packages/app/tests/integration/branch-switch-agent-write.test.ts+++ b/packages/app/tests/integration/branch-switch-agent-write.test.ts@@ -50,6 +50,7 @@ async function bootOnMainWithFeatureBranch(): Promise<{}> {const contentDir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-branch-switch-agent-write-')));cleanups.push(() => rmSync(contentDir, { recursive: true, force: true }));+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);git(contentDir, 'config user.name test');diff --git a/packages/app/tests/integration/branch-switch-batch.test.ts b/packages/app/tests/integration/branch-switch-batch.test.tsindex 7649673d0..972229a55 100644--- a/packages/app/tests/integration/branch-switch-batch.test.ts+++ b/packages/app/tests/integration/branch-switch-batch.test.ts@@ -48,6 +48,7 @@ function git(cwd: string, args: string): void {async function openNotesTypedOnMain() {const contentDir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-branch-switch-batch-')));cleanups.push(() => rmSync(contentDir, { recursive: true, force: true }));+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);const notes = join(contentDir, 'notes.md');diff --git a/packages/app/tests/integration/branch-switch-live-client.test.ts b/packages/app/tests/integration/branch-switch-live-client.test.tsindex 819b7171b..b6b480475 100644--- a/packages/app/tests/integration/branch-switch-live-client.test.ts+++ b/packages/app/tests/integration/branch-switch-live-client.test.ts@@ -63,6 +63,7 @@ async function setupGitRepoWithBranches(contentA: string,contentB: string,): Promise<void> {+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);git(contentDir, 'config user.name test');diff --git a/packages/app/tests/integration/branch-switch-private-state-link.test.ts b/packages/app/tests/integration/branch-switch-private-state-link.test.tsindex 8360ce32c..c700f3e58 100644--- a/packages/app/tests/integration/branch-switch-private-state-link.test.ts+++ b/packages/app/tests/integration/branch-switch-private-state-link.test.ts@@ -38,6 +38,7 @@ describe('branch switch with a document that became a link into private state',async () => {const contentDir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-branch-switch-private-')));cleanups.push(() => rmSync(contentDir, { recursive: true, force: true }));+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);git(contentDir, 'config user.name test');diff --git a/packages/app/tests/integration/branch-switched-with-stale-embed-resolution.test.ts b/packages/app/tests/integration/branch-switched-with-stale-embed-resolution.test.tsindex 0bb35623e..216f3e7ae 100644--- a/packages/app/tests/integration/branch-switched-with-stale-embed-resolution.test.ts+++ b/packages/app/tests/integration/branch-switched-with-stale-embed-resolution.test.ts@@ -66,6 +66,7 @@ describe('T17: branch switch with `![[photo.png]]` doc — reseed-before-reset',writeRel(contentDir, 'test-doc.md', DOC_BODY);writeRel(contentDir, 'photo.png', PNG_BYTES);+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);git(contentDir, 'config user.name test');diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.tsindex a50b00123..4549c74b3 100644--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts@@ -1,3 +1,4 @@+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.tsindex 6fcdc23f2..4fc2c11f9 100644--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts@@ -1,3 +1,4 @@+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.tsindex 40b5cdfd6..9f2f6feb6 100644--- a/packages/app/tests/integration/interior-edit-freshness.test.ts+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts@@ -1,3 +1,4 @@+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.tsindex 93666af70..2a085742b 100644--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts@@ -1,3 +1,4 @@+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.tsindex 867598d34..878d5196b 100644--- a/packages/app/tests/integration/producer-guard-wiring.test.ts+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts@@ -1,3 +1,4 @@+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.tsindex 0970ac12f..4ada3cf26 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,3 +1,4 @@+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.tsindex b632185e1..cbe2b705f 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,3 +1,4 @@+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.tsindex c530ce4ba..89bc9b4d9 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,3 +1,4 @@+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/reoccupied-doc-name-persistence.test.ts b/packages/app/tests/integration/reoccupied-doc-name-persistence.test.tsindex 3a2a1685f..e92b21611 100644--- a/packages/app/tests/integration/reoccupied-doc-name-persistence.test.ts+++ b/packages/app/tests/integration/reoccupied-doc-name-persistence.test.ts@@ -214,6 +214,7 @@ describe('switching back to a branch that has a tombstoned document', () => {async () => {const contentDir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-branch-switch-revive-')));cleanups.push(() => rmSync(contentDir, { recursive: true, force: true }));+ git(contentDir, 'init --initial-branch=main');await ensureProjectGit(contentDir);configureTestGitRepository(contentDir);mkdirSync(join(contentDir, '.ok', 'local'), { recursive: true });diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.tsindex d3767adc9..a78aeb0e4 100644--- a/packages/app/tests/integration/undo-after-rollback.test.ts+++ b/packages/app/tests/integration/undo-after-rollback.test.ts@@ -1,3 +1,4 @@+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.tsindex b076f955c..e7cc69c3f 100644--- a/packages/app/tests/integration/undo-recycle-reset.test.ts+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts@@ -1,3 +1,4 @@+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.tsindex 7935e35f8..9ddcd0730 100644--- a/packages/app/tests/integration/undo-rederive-survival.test.ts+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts@@ -1,3 +1,4 @@+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/cli/src/commands/init.test.ts b/packages/cli/src/commands/init.test.tsindex 8c1faeb6c..c0825f8ed 100644--- a/packages/cli/src/commands/init.test.ts+++ b/packages/cli/src/commands/init.test.ts@@ -1473,17 +1473,26 @@ describe('runInit', () => {});describe('ensureProjectGit wiring (US-005)', () => {- it('fresh tmpdir (no .git/) → runInit creates .git/ and reports didGitInit=true', async () => {- const result = await runInitForTest({ editors: ['claude'] });+ it.each(['main', 'trunk'])(+ 'initializes the configured %s branch without a misleading label',+ async (branch) => {+ const gitConfig = join(fakeHome, 'gitconfig');+ writeFileSync(gitConfig, `[init]\n\tdefaultBranch = ${branch}\n`);+ vi.stubEnv('GIT_CONFIG_GLOBAL', gitConfig);+ vi.stubEnv('GIT_CONFIG_NOSYSTEM', '1');- expect(result.didGitInit).toBe(true);- expect(existsSync(join(testDir, '.git/HEAD'))).toBe(true);- const head = readFileSync(join(testDir, '.git/HEAD'), 'utf-8');- expect(head).toBe('ref: refs/heads/main\n');+ const result = await runInitForTest({ editors: ['claude'] });- const output = formatInitResult(result, testDir);- expect(output).toContain(`Initialized git repo at ${testDir}/.git/ (default branch: main)`);- });+ expect(result.didGitInit).toBe(true);+ const head = readFileSync(join(testDir, '.git/HEAD'), 'utf-8');+ expect(head).toBe(`ref: refs/heads/${branch}\n`);++ const output = formatInitResult(result, testDir);+ expect(output.split('\n').find((line) => line.startsWith('Initialized git repo at'))).toBe(+ `Initialized git repo at ${testDir}/.git/`,+ );+ },+ );it('pre-existing .git/HEAD → runInit does not re-init and reports didGitInit=false', async () => {mkdirSync(join(testDir, '.git'));diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.tsindex 909e4cf8d..ba60f8783 100644--- a/packages/cli/src/commands/init.ts+++ b/packages/cli/src/commands/init.ts@@ -1598,7 +1598,7 @@ export function formatInitResult(result: InitCommandResult, cwd: string): stringconst allSkippedMissing =result.editors.length > 0 && result.editors.every((e) => e.action === 'skipped-missing');if (result.didGitInit) {- lines.push(`Initialized git repo at ${cwd}/.git/ (default branch: main)`);+ lines.push(`Initialized git repo at ${cwd}/.git/`);}if (result.rootGitignoreCreated) {lines.push(`Seeded .gitignore at ${cwd}/.gitignore (.DS_Store)`);diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex f4cc8a286..2a597ec3d 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,3 +1,4 @@+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.tsindex e7e63f43d..ffd8fce06 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,3 +1,4 @@+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.tsindex fc267cbea..fb0ba5a7c 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,3 +1,4 @@+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.tsindex 861003fb4..ae8cb390b 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,3 +1,4 @@+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.tsindex 4d3250d3a..8be632ba4 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,3 +1,4 @@+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/desktop/src/main/create-new-project.test.ts b/packages/desktop/src/main/create-new-project.test.tsindex 894212a79..9a76a4b47 100644--- a/packages/desktop/src/main/create-new-project.test.ts+++ b/packages/desktop/src/main/create-new-project.test.ts@@ -194,6 +194,11 @@ describe('runCreateNew — happy paths', () => {editors: [...ALL_EDITOR_IDS],});+ const branch = execFileSync('git', ['symbolic-ref', '--short', 'HEAD'], {+ cwd: result.projectDir,+ encoding: 'utf-8',+ }).trim();+expect(() =>execFileSync('git', ['rev-parse', '--verify', 'HEAD'], { cwd: result.projectDir }),).not.toThrow();@@ -207,7 +212,7 @@ describe('runCreateNew — happy paths', () => {'wt-1',join(result.projectDir, '.ok/worktrees/wt-1'),'--',- 'main',+ branch,],{ cwd: result.projectDir },),diff --git a/packages/server/src/project-git.test.ts b/packages/server/src/project-git.test.tsindex 252571715..324fc9b37 100644--- a/packages/server/src/project-git.test.ts+++ b/packages/server/src/project-git.test.ts@@ -4,12 +4,13 @@ import { mkdtemp, rm } from 'node:fs/promises';import { tmpdir } from 'node:os';import { resolve } from 'node:path';import { promisify } from 'node:util';-import { afterEach, beforeEach, describe, expect, test } from 'vitest';+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';import { configureTestGitRepository } from '../../../test-support/configure-git-fixture.test-helper.ts';import {__resetResolveOnPathCacheForTests,__seedResolveOnPathCacheForTests,} from './git-preflight.ts';+import { readProjectHeadState } from './head-watcher.ts';import { ensureProjectGit, ProjectGitInitError } from './project-git.ts';const execFileAsync = promisify(execFile);@@ -18,9 +19,14 @@ let tmpDir: string;beforeEach(async () => {tmpDir = await mkdtemp(resolve(tmpdir(), 'ok-project-git-test-'));+ const gitConfig = resolve(tmpDir, 'gitconfig');+ writeFileSync(gitConfig, '[init]\n\tdefaultBranch = main\n');+ vi.stubEnv('GIT_CONFIG_GLOBAL', gitConfig);+ vi.stubEnv('GIT_CONFIG_NOSYSTEM', '1');});afterEach(async () => {+ vi.unstubAllEnvs();await rm(tmpDir, { recursive: true, force: true });});@@ -38,6 +44,7 @@ describe('ensureProjectGit', () => {});test('auto-repairs partial .git/ (directory without HEAD) preserving .git/ok/ subtree', async () => {+ writeFileSync(resolve(tmpDir, 'gitconfig'), '[init]\n\tdefaultBranch = trunk\n');const projectRoot = resolve(tmpDir, 'shell-git');mkdirSync(projectRoot, { recursive: true });mkdirSync(resolve(projectRoot, '.git/ok/refs'), { recursive: true });@@ -57,6 +64,7 @@ describe('ensureProjectGit', () => {expect(result.didInit).toBe(true);expect(result.repaired).toBe(true);+ expect(readProjectHeadState(projectRoot).branch).toBe('trunk');expect(existsSync(resolve(projectRoot, '.git/HEAD'))).toBe(true);expect(readFileSync(resolve(projectRoot, '.git/ok/HEAD'), 'utf-8')).toBe(@@ -95,18 +103,31 @@ describe('ensureProjectGit', () => {expect(existsSync(resolve(subFolder, '.git'))).toBe(false);});- test('runs git init --initial-branch=main when .git/ is missing', async () => {- const projectRoot = resolve(tmpDir, 'fresh');- mkdirSync(projectRoot, { recursive: true });+ test.each(['main', 'trunk', 'team/default'])(+ 'honors init.defaultBranch=%s when .git/ is missing',+ async (branch) => {+ writeFileSync(resolve(tmpDir, 'gitconfig'), `[init]\n\tdefaultBranch = ${branch}\n`);+ const projectRoot = resolve(tmpDir, 'fresh');+ mkdirSync(projectRoot, { recursive: true });- const result = await ensureProjectGit(projectRoot);- configureTestGitRepository(projectRoot);+ const result = await ensureProjectGit(projectRoot);- expect(result.didInit).toBe(true);- expect(existsSync(resolve(projectRoot, '.git/HEAD'))).toBe(true);+ expect(result.didInit).toBe(true);+ const { stdout: oid } = await execFileAsync('git', ['rev-parse', 'HEAD'], {+ cwd: projectRoot,+ });+ expect(readProjectHeadState(projectRoot)).toEqual({ branch, oid: oid.trim() });+ },+ );++ test('keeps main when init.defaultBranch is not configured', async () => {+ writeFileSync(resolve(tmpDir, 'gitconfig'), '');+ const projectRoot = resolve(tmpDir, 'unconfigured');+ mkdirSync(projectRoot);- const head = readFileSync(resolve(projectRoot, '.git/HEAD'), 'utf-8');- expect(head).toBe('ref: refs/heads/main\n');+ await ensureProjectGit(projectRoot);++ expect(readProjectHeadState(projectRoot).branch).toBe('main');});test('falls back to a usable git when bare git is unavailable on PATH', async () => {@@ -135,7 +156,7 @@ describe('ensureProjectGit', () => {const fakeGit = resolve(fakeBin, 'git');writeFileSync(fakeGit,- `#!/bin/sh\ncase "$1" in\n --version) echo "git version 2.45.0"; exit 0 ;;\n init)\n # args: init --initial-branch=main <path>\n mkdir -p "$3/.git"\n # intentionally do not create HEAD\n exit 0 ;;\n *) exit 0 ;;\nesac\n`,+ `#!/bin/sh\ncase "$1" in\n --version) echo "git version 2.45.0"; exit 0 ;;\n init)\n mkdir -p "$3/.git"\n exit 0 ;;\n *) exit 0 ;;\nesac\n`,'utf-8',);await execFileAsync('chmod', ['+x', fakeGit]);@@ -174,7 +195,8 @@ describe('ensureProjectGit — initial commit', () => {await expect(headResolves(projectRoot)).resolves.toBe(true);});- test('leaves `main` resolvable, so `git worktree add ... -- main` succeeds', async () => {+ test('leaves the configured default branch resolvable for git worktree add', async () => {+ writeFileSync(resolve(tmpDir, 'gitconfig'), '[init]\n\tdefaultBranch = trunk\n');const projectRoot = resolve(tmpDir, 'worktree-base');mkdirSync(projectRoot, { recursive: true });@@ -183,7 +205,7 @@ describe('ensureProjectGit — initial commit', () => {const worktreePath = resolve(projectRoot, '.ok/worktrees/wt-1');await expect(- execFileAsync('git', ['worktree', 'add', '-b', 'wt-1', worktreePath, '--', 'main'], {+ execFileAsync('git', ['worktree', 'add', '-b', 'wt-1', worktreePath, '--', 'trunk'], {cwd: projectRoot,}),).resolves.toBeDefined();@@ -192,13 +214,14 @@ describe('ensureProjectGit — initial commit', () => {test('backfills a root commit on a repo already stranded with an unborn HEAD', async () => {const projectRoot = resolve(tmpDir, 'stranded');mkdirSync(projectRoot, { recursive: true });- await execFileAsync('git', ['init', '--initial-branch=main', projectRoot]);+ await execFileAsync('git', ['init', '--initial-branch=existing', projectRoot]);configureTestGitRepository(projectRoot);await expect(headResolves(projectRoot)).resolves.toBe(false);const result = await ensureProjectGit(projectRoot);expect(result.didInit).toBe(false);+ expect(readProjectHeadState(projectRoot).branch).toBe('existing');await expect(headResolves(projectRoot)).resolves.toBe(true);});diff --git a/packages/server/src/project-git.ts b/packages/server/src/project-git.tsindex e98d48602..80d9c841b 100644--- a/packages/server/src/project-git.ts+++ b/packages/server/src/project-git.ts@@ -209,9 +209,14 @@ export async function ensureProjectGit(projectRoot: string): Promise<EnsureProjelet stderr = '';try {+ const { stdout: defaultBranch } = await execFileAsync(+ gitBin,+ ['config', '--default', 'main', '--get', 'init.defaultBranch'],+ withHiddenWindowsConsole({ cwd: abs, encoding: 'utf-8' }),+ );const result = await execFileAsync(gitBin,- ['init', '--initial-branch=main', abs],+ ['init', `--initial-branch=${defaultBranch.trim()}`, abs],withHiddenWindowsConsole({ encoding: 'utf-8' }),);stderr = result.stderr ?? '';@@ -240,7 +245,7 @@ export async function ensureProjectGit(projectRoot: string): Promise<EnsureProjereturn { didInit: true, repaired: true };}- log.info({ path: abs, branch: 'main' }, 'initialized .git/');+ log.info({ path: abs }, 'initialized .git/');return { didInit: true };}