Skip to content

Commit 301999c

Browse files
Ali-Al1claude
andauthored
fix(server): git 2.56 broken-gitfile worktrees count as non-repositories again (pingdotgg#33423)
Co-authored-by: Claude Code <[email protected]>
1 parent 2b6eb63 commit 301999c

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";
@@ -198,7 +199,7 @@ type GitActionProgressPayload = StripProgressContext<GitActionProgressEvent>;
198199
type GitActionProgressEmitter = (event: GitActionProgressPayload) => Effect.Effect<void, never>;
199200

200201
function isNotGitRepositoryError(error: GitCommandError): boolean {
201-
return error.message.toLowerCase().includes("not a git repository");
202+
return isNonRepositoryGitStderr(error.message);
202203
}
203204

204205
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
@@ -39,6 +39,7 @@ import {
3939
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
4040
import * as ServerConfig from "../config.ts";
4141
import {
42+
isNonRepositoryGitStderr,
4243
makeGitVcsDriverCore,
4344
parseGitCheckoutProgressLine,
4445
splitNullSeparatedGitStdoutPaths,
@@ -132,6 +133,27 @@ const makeDriverReleasingLock = (
132133
return { driver, failures };
133134
});
134135

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

571-
function isNonRepositoryGitStderr(stderr: string): boolean {
572-
return stderr.toLowerCase().includes("not a git repository");
571+
// Git 2.56+ reports a `.git` gitfile pointing nowhere as "gitfile does not point to a valid
572+
// repository"; older releases said "not a git repository". Both mean the cwd is not a repository.
573+
const NON_REPOSITORY_STDERR_PHRASES = [
574+
"not a git repository",
575+
"gitfile does not point to a valid repository",
576+
] as const;
577+
578+
export function isNonRepositoryGitStderr(stderr: string): boolean {
579+
const normalized = stderr.toLowerCase();
580+
return NON_REPOSITORY_STDERR_PHRASES.some((phrase) => normalized.includes(phrase));
573581
}
574582
function isUnbornHeadStderr(stderr: string): boolean {
575583
const normalized = stderr.toLowerCase();

0 commit comments

Comments
 (0)