Skip to content

Commit c28c6ac

Browse files
fix(server): a rejected non-fast-forward push explains itself under a translated Git (pingdotgg#35386)
1 parent 56e58a9 commit c28c6ac

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,55 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
21892189
}),
21902190
);
21912191

2192+
it.effect("explains a non-fast-forward push from a host with a translated Git", () =>
2193+
Effect.gen(function* () {
2194+
const cwd = yield* makeTmpDir();
2195+
const { initialBranch } = yield* initRepoWithCommit(cwd);
2196+
const remote = yield* makeTmpDir("git-remote-");
2197+
const other = yield* makeTmpDir("git-other-");
2198+
yield* git(remote, ["init", "--bare"]);
2199+
yield* git(cwd, ["remote", "add", "origin", remote]);
2200+
yield* git(cwd, ["push", "--set-upstream", "origin", initialBranch]);
2201+
yield* git(other, ["clone", "--branch", initialBranch, remote, "."]);
2202+
yield* git(other, [
2203+
"-c",
2204+
"user.email=t@t",
2205+
"-c",
2206+
"user.name=T",
2207+
"commit",
2208+
"--allow-empty",
2209+
"-m",
2210+
"remote",
2211+
]);
2212+
yield* git(other, ["push", "origin", initialBranch]);
2213+
yield* git(cwd, ["commit", "--allow-empty", "-m", "local"]);
2214+
const locales: Array<CommandLine.Word | undefined> = [];
2215+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
2216+
const spawner = ChildProcessSpawner.make((command) => {
2217+
if (ChildProcess.isStandardCommand(command) && command.args.includes("push")) {
2218+
locales.push(command.options.env?.LANGUAGE);
2219+
}
2220+
return delegate.spawn(command);
2221+
});
2222+
const driver = yield* makeGitVcsDriverCore().pipe(
2223+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
2224+
Effect.provide(layerServerConfig),
2225+
);
2226+
const hostEnv = yield* HostProcess.Environment;
2227+
2228+
const error = yield* driver
2229+
.pushCurrentBranch(cwd, null)
2230+
.pipe(
2231+
Effect.provideService(HostProcess.Environment, { ...hostEnv, LANGUAGE: "de" }),
2232+
Effect.flip,
2233+
);
2234+
2235+
assert.equal(error.reason, "push_rejected_non_fast_forward");
2236+
assert.isNotEmpty(locales);
2237+
for (const locale of locales) assert.equal(locale, "C");
2238+
}),
2239+
);
2240+
21922241
it.effect("lets a slow remote branch checkout finish without blocking config writes", () =>
21932242
Effect.gen(function* () {
21942243
const cwd = yield* makeTmpDir();

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
29122912
const requestedRemoteName = options?.remoteName?.trim() || null;
29132913
if (requestedRemoteName) {
29142914
const publishBranch = yield* resolvePublishBranchName(cwd, branch);
2915-
yield* runGit(
2915+
yield* executeGitWithStableDiagnostics(
29162916
"GitVcsDriver.pushCurrentBranch.pushWithRequestedRemote",
29172917
cwd,
29182918
["push", "--", requestedRemoteName, `HEAD:refs/heads/${publishBranch}`],
@@ -3006,7 +3006,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30063006
});
30073007
}
30083008
}
3009-
yield* runGit(
3009+
yield* executeGitWithStableDiagnostics(
30103010
upstream
30113011
? "GitVcsDriver.pushCurrentBranch.pushOwnBranch"
30123012
: "GitVcsDriver.pushCurrentBranch.pushWithUpstream",
@@ -3023,7 +3023,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30233023
}
30243024

30253025
if (destination?.upstream) {
3026-
yield* runGit(
3026+
yield* executeGitWithStableDiagnostics(
30273027
"GitVcsDriver.pushCurrentBranch.pushUpstream",
30283028
cwd,
30293029
["push", "--", destination.remoteName, `HEAD:refs/heads/${destination.branchName}`],
@@ -3037,7 +3037,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30373037
};
30383038
}
30393039

3040-
yield* runGit("GitVcsDriver.pushCurrentBranch.push", cwd, ["push"], { timeoutMs: null });
3040+
yield* executeGitWithStableDiagnostics("GitVcsDriver.pushCurrentBranch.push", cwd, ["push"], {
3041+
timeoutMs: null,
3042+
});
30413043
return {
30423044
status: "pushed" as const,
30433045
branch,

0 commit comments

Comments
 (0)