Skip to content

Commit bb485ef

Browse files
Ali-Al1claude
andcommitted
fix(server): treat git 2.56 broken-gitfile stderr as non-repository
Git 2.56 reports a worktree whose `.git` gitfile points at a missing directory as "gitfile does not point to a valid repository" instead of "not a git repository". isNonRepositoryGitStderr only matched the old phrase, and StorageCleanup.branchChanged and GitManager each kept their own copy of the same check, so with git 2.56 storage cleanup reported such worktrees as `failed` rather than keeping them as changed. Export isNonRepositoryGitStderr, match both phrases, and reuse it in storageCleanup and GitManager so the checks cannot drift again. Co-Authored-By: Claude Code <[email protected]>
1 parent b8c2cfa commit bb485ef

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎apps/server/src/git/GitManager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { detachStackFrame } from "./detachStackFrame.ts";
8686
import * as ServerSettings from "../serverSettings.ts";
8787
import type { GitManagerServiceError } from "@t3tools/contracts";
8888
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
89+
import { isNonRepositoryGitStderr } from "../vcs/GitVcsDriverCore.ts";
8990
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
9091
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
9192
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
@@ -191,7 +192,7 @@ type GitActionProgressPayload = StripProgressContext<GitActionProgressEvent>;
191192
type GitActionProgressEmitter = (event: GitActionProgressPayload) => Effect.Effect<void, never>;
192193

193194
function isNotGitRepositoryError(error: GitCommandError): boolean {
194-
return error.message.toLowerCase().includes("not a git repository");
195+
return isNonRepositoryGitStderr(error.message);
195196
}
196197

197198
interface OpenPrInfo {

‎apps/server/src/storageCleanup.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import * as Settings from "./serverSettings.ts";
4747
import * as TerminalManager from "./terminal/Manager.ts";
4848
import { isFilesystemRoot, managedWorktreesDirectories } from "./worktreesDirectory.ts";
4949
import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";
50+
import { isNonRepositoryGitStderr } from "./vcs/GitVcsDriverCore.ts";
5051
import { removeLinkedWorktree } from "./vcs/worktreeRemoval.ts";
5152
import { withWorkspaceLease } from "./workspace/workspaceLease.ts";
5253
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -618,7 +619,7 @@ const make = Effect.gen(function* () {
618619
);
619620
if (result === null) return null;
620621
if (result.exitCode === 0 || result.exitCode === allowedExitCode) return result;
621-
if (result.stderr.toLowerCase().includes("not a git repository")) return null;
622+
if (isNonRepositoryGitStderr(result.stderr)) return null;
622623
return yield* failure(
623624
result.stderr.trim().split(/\r?\n/)[0]?.slice(0, 1000) || "command failed",
624625
);

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
3838
import * as ServerConfig from "../config.ts";
3939
import {
40+
isNonRepositoryGitStderr,
4041
makeGitVcsDriverCore,
4142
parseGitCheckoutProgressLine,
4243
splitNullSeparatedGitStdoutPaths,
@@ -130,6 +131,27 @@ const makeDriverReleasingLock = (
130131
return { driver, failures };
131132
});
132133

134+
describe("isNonRepositoryGitStderr", () => {
135+
it.each([
136+
"fatal: not a git repository (or any of the parent directories): .git",
137+
"fatal: not a git repository: /missing-git-directory",
138+
// Git 2.56+ wording for a `.git` gitfile that points at a missing directory.
139+
"fatal: gitfile does not point to a valid repository: /tmp/worktrees/feature/.git",
140+
"FATAL: GITFILE DOES NOT POINT TO A VALID REPOSITORY: /tmp/x/.git",
141+
])("classifies %j as a non-repository", (stderr) => {
142+
assert.isTrue(isNonRepositoryGitStderr(stderr));
143+
});
144+
145+
it.each([
146+
"",
147+
"fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.",
148+
"fatal: Unable to create '/repo/.git/index.lock': File exists.",
149+
"fatal: invalid gitfile format: /repo/.git",
150+
])("does not classify %j as a non-repository", (stderr) => {
151+
assert.isFalse(isNonRepositoryGitStderr(stderr));
152+
});
153+
});
154+
133155
it.effect("runs background Git in its own lane so user commands never queue behind it", () =>
134156
Effect.gen(function* () {
135157
const gate = yield* Deferred.make<void>();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,16 @@ function isMissingGitCwdError(error: GitCommandError): boolean {
562562
);
563563
}
564564

565-
function isNonRepositoryGitStderr(stderr: string): boolean {
566-
return stderr.toLowerCase().includes("not a git repository");
565+
// Git 2.56+ reports a `.git` gitfile pointing nowhere as "gitfile does not point to a valid
566+
// repository"; older releases said "not a git repository". Both mean the cwd is not a repository.
567+
const NON_REPOSITORY_STDERR_PHRASES = [
568+
"not a git repository",
569+
"gitfile does not point to a valid repository",
570+
] as const;
571+
572+
export function isNonRepositoryGitStderr(stderr: string): boolean {
573+
const normalized = stderr.toLowerCase();
574+
return NON_REPOSITORY_STDERR_PHRASES.some((phrase) => normalized.includes(phrase));
567575
}
568576
function isUnbornHeadStderr(stderr: string): boolean {
569577
const normalized = stderr.toLowerCase();

0 commit comments

Comments
 (0)