Skip to content
TypeScript

fix(server): background git status fetches no longer fill the disk with failed repacks (#13812)

Theo Browne95030dc67488
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 47ca4e17870..85c4d1a59d1 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -1918,6 +1918,35 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
}),
);
+ it.effect("does not start Git auto-maintenance from background upstream fetches", () =>
+ Effect.gen(function* () {
+ const cwd = yield* makeTmpDir();
+ const remote = yield* makeTmpDir("git-vcs-driver-remote-");
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
+ yield* git(remote, ["init", "--bare"]);
+ yield* git(cwd, ["remote", "add", "origin", remote]);
+ yield* git(cwd, ["push", "-u", "origin", initialBranch]);
+ yield* git(cwd, ["repack", "-d"]);
+ yield* writeTextFile(cwd, "second.txt", "second\n");
+ yield* git(cwd, ["add", "second.txt"]);
+ yield* git(cwd, ["commit", "-m", "second commit"]);
+ yield* git(cwd, ["push"]);
+ yield* git(cwd, ["repack", "-d"]);
+ // Two packs make `git gc --auto` due, and without detaching it would run inside the fetch.
+ yield* git(cwd, ["config", "gc.autoPackLimit", "1"]);
+ yield* git(cwd, ["config", "gc.autoDetach", "false"]);
+ yield* git(cwd, ["config", "maintenance.autoDetach", "false"]);
+ const packCount = git(cwd, ["count-objects", "-v"]).pipe(
+ Effect.map((stdout) => stdout.match(/^packs: (\d+)$/m)?.[1]),
+ );
+ assert.equal(yield* packCount, "2");
+
+ yield* (yield* GitVcsDriver.GitVcsDriver).statusDetailsRemote(cwd);
+
+ assert.equal(yield* packCount, "2");
+ }),
+ );
+
it.effect("uses origin HEAD for default-branch detection with a non-origin upstream", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 1985a2d31ae..0dd73af687f 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -1127,10 +1127,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
): Effect.Effect<void, GitCommandError> => {
const fetchCwd =
path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
+ // `--no-auto-gc` (a synonym of `--no-auto-maintenance` that older Git also knows) keeps
+ // this poll from starting `git gc --auto`. When that gc fails, for example on a repository
+ // with missing objects, Git retries it on every fetch and leaves a full-size `tmp_pack_*`
+ // behind each time, so a background poll could fill the disk.
return executeGit(
"GitVcsDriver.fetchRemoteForStatus",
fetchCwd,
- ["--git-dir", gitCommonDir, "fetch", "--quiet", "--no-tags", remoteName],
+ ["--git-dir", gitCommonDir, "fetch", "--quiet", "--no-tags", "--no-auto-gc", remoteName],
{
env: STATUS_UPSTREAM_REFRESH_ENV,
fallbackErrorDetail: "Background Git fetch exited with a non-zero status.",