From e4960d8bf9b0442289de5aec4bdd985cd2040675 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Wed, 19 Aug 2026 09:48:00 +0200 Subject: [PATCH] agentHost: Avoid warning for missing remote HEAD Probe the optional origin/HEAD symbolic ref in quiet mode so repositories without it do not produce recurring agent host warnings. Add an integration test covering the expected missing-ref case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../agentHost/node/agentHostGitService.ts | 2 +- .../agentHostGitService.integrationTest.ts | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/vs/platform/agentHost/node/agentHostGitService.ts b/src/vs/platform/agentHost/node/agentHostGitService.ts index cfaeb27d56b..31b502b3995 100644 --- a/src/vs/platform/agentHost/node/agentHostGitService.ts +++ b/src/vs/platform/agentHost/node/agentHostGitService.ts @@ -59,7 +59,7 @@ export class AgentHostGitService implements IAgentHostGitService { async getDefaultBranch(workingDirectory: URI): Promise { // Try to read the default branch from the remote HEAD reference - const remoteRef = (await this._runGit(workingDirectory, ['symbolic-ref', 'refs/remotes/origin/HEAD']))?.trim(); + const remoteRef = (await this._runGit(workingDirectory, ['symbolic-ref', '--quiet', 'refs/remotes/origin/HEAD']))?.trim(); if (remoteRef) { if (!remoteRef.startsWith('refs/remotes/origin/')) { return { name: remoteRef, startPoint: remoteRef }; diff --git a/src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts b/src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts index 00adf4eb4fd..58d13f18673 100644 --- a/src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts +++ b/src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts @@ -29,8 +29,15 @@ import { DiskFileSystemProvider } from '../../../files/node/diskFileSystemProvid import { DisposableStore } from '../../../../base/common/lifecycle.js'; import { AgentHostGitService } from '../../node/agentHostGitService.js'; -function createGitService(disposables: Pick): AgentHostGitService { - const logService = new NullLogService(); +class TestLogService extends NullLogService { + readonly warnings: string[] = []; + + override warn(message: string): void { + this.warnings.push(message); + } +} + +function createGitService(disposables: Pick, logService: NullLogService = new NullLogService()): AgentHostGitService { const fileService = disposables.add(new FileService(logService)); disposables.add(fileService.registerProvider(Schemas.file, disposables.add(new DiskFileSystemProvider(logService)))); const env: Partial = { tmpDir: URI.file(tmpdir()) }; @@ -54,10 +61,12 @@ suite('AgentHostGitService - getSessionGitState (real git)', () => { let tmpRoot: string | undefined; let svc: AgentHostGitService | undefined; + let logService: TestLogService; setup(() => { tmpRoot = undefined; - svc = createGitService(disposables); + logService = new TestLogService(); + svc = createGitService(disposables, logService); }); teardown(() => { @@ -150,6 +159,18 @@ suite('AgentHostGitService - getSessionGitState (real git)', () => { }); }); + (hasGit ? test : test.skip)('does not warn when the default remote-tracking ref is missing', async () => { + const dir = initRepo(); + + assert.deepStrictEqual({ + defaultBranch: await svc!.getDefaultBranch(URI.file(dir)), + warnings: logService.warnings, + }, { + defaultBranch: undefined, + warnings: [], + }); + }); + (hasGit ? test : test.skip)('falls back to the local branch when the default remote-tracking ref is missing', async () => { const dir = initRepo(); cp.execFileSync('git', ['symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/main'], { cwd: dir, stdio: 'pipe' });