Remove git.renameBranch RPC and harden branch rename args

- remove `git.renameBranch` from WS/contracts/native API surface and update server/web tests
- use `git branch -m -- ...` in GitCore to safely separate branch rename arguments
This commit is contained in:
Julius Marminge committed 2026-02-28 22:35:09 -08:00
1 parent 61e1babcc7
commit 0df68cc73e
9 files changed
+48 -73

No files matched your search

@@ -744,6 +744,41 @@ it.layer(TestLayer)("git integration", (it) => {
expect(renamed.branch).toBe("t3code/feat/session-2");
}),
);
it.effect("uses '--' separator for branch rename arguments", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* createGitBranch({ cwd: tmp, branch: "feature/old-name" });
yield* checkoutGitBranch({ cwd: tmp, branch: "feature/old-name" });
const realGitService = yield* GitService;
let renameArgs: ReadonlyArray<string> | null = null;
const core = yield* makeIsolatedGitCore({
execute: (input) => {
if (input.args[0] === "branch" && input.args[1] === "-m") {
renameArgs = [...input.args];
}
return realGitService.execute(input);
},
});
const renamed = yield* core.renameBranch({
cwd: tmp,
oldBranch: "feature/old-name",
newBranch: "feature/new-name",
});
expect(renamed.branch).toBe("feature/new-name");
expect(renameArgs).toEqual([
"branch",
"-m",
"--",
"feature/old-name",
"feature/new-name",
]);
}),
);
});
// ── createGitWorktree + removeGitWorktree ──
+2 -2
View File
@@ -190,7 +190,7 @@ const makeGitCore = Effect.gen(function* () {
return yield* createGitCommandError(
"GitCore.renameBranch",
cwd,
["branch", "-m", desiredBranch],
["branch", "-m", "--", desiredBranch],
`Could not find an available branch name for '${desiredBranch}'.`,
);
});
@@ -758,7 +758,7 @@ const makeGitCore = Effect.gen(function* () {
yield* executeGit(
"GitCore.renameBranch",
input.cwd,
["branch", "-m", input.oldBranch, targetBranch],
["branch", "-m", "--", input.oldBranch, targetBranch],
{
timeoutMs: 10_000,
fallbackErrorMessage: "git branch rename failed",
+10 -2
View File
@@ -17,8 +17,6 @@ import type {
GitListBranchesInput,
GitListBranchesResult,
GitPullResult,
GitRenameBranchInput,
GitRenameBranchResult,
GitRemoveWorktreeInput,
GitStatusInput,
GitStatusResult,
@@ -48,6 +46,16 @@ export interface GitRangeContext {
diffPatch: string;
}
export interface GitRenameBranchInput {
cwd: string;
oldBranch: string;
newBranch: string;
}
export interface GitRenameBranchResult {
branch: string;
}
/**
* GitCoreShape - Service API for low-level Git repository interactions.
*/
+1 -15
View File
@@ -371,7 +371,7 @@ describe("WebSocket Server", () => {
gitManager?: GitManagerShape;
gitCore?: Pick<
GitCoreShape,
"listBranches" | "initRepo" | "pullCurrentBranch" | "renameBranch"
"listBranches" | "initRepo" | "pullCurrentBranch"
>;
terminalManager?: TerminalManagerShape;
} = {},
@@ -1471,7 +1471,6 @@ describe("WebSocket Server", () => {
}),
);
const initRepo = vi.fn(() => Effect.void);
const renameBranch = vi.fn(() => Effect.succeed({ branch: "t3code/new-name" }));
const pullCurrentBranch = vi.fn(() =>
Effect.fail(
new GitCommandError({
@@ -1488,7 +1487,6 @@ describe("WebSocket Server", () => {
gitCore: {
listBranches,
initRepo,
renameBranch,
pullCurrentBranch,
},
});
@@ -1513,18 +1511,6 @@ describe("WebSocket Server", () => {
expect(pullResponse.error?.message).toContain("No upstream configured");
expect(pullCurrentBranch).toHaveBeenCalledWith("/repo/path");
const renameResponse = await sendRequest(ws, WS_METHODS.gitRenameBranch, {
cwd: "/repo/path",
oldBranch: "t3code/tmp-456",
newBranch: "t3code/new-name",
});
expect(renameResponse.error).toBeUndefined();
expect(renameResponse.result).toEqual({ branch: "t3code/new-name" });
expect(renameBranch).toHaveBeenCalledWith({
cwd: "/repo/path",
oldBranch: "t3code/tmp-456",
newBranch: "t3code/new-name",
});
});
it("supports git.status over websocket", async () => {
-5
View File
@@ -572,11 +572,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
return yield* git.createWorktree(body);
}
case WS_METHODS.gitRenameBranch: {
const body = stripRequestTag(request.body);
return yield* git.renameBranch(body);
}
case WS_METHODS.gitRemoveWorktree: {
const body = stripRequestTag(request.body);
return yield* git.removeWorktree(body);
-1
View File
@@ -165,7 +165,6 @@ export function createWsNativeApi(): NativeApi {
runStackedAction: (input) => transport.request(WS_METHODS.gitRunStackedAction, input),
listBranches: (input) => transport.request(WS_METHODS.gitListBranches, input),
createWorktree: (input) => transport.request(WS_METHODS.gitCreateWorktree, input),
renameBranch: (input) => transport.request(WS_METHODS.gitRenameBranch, input),
removeWorktree: (input) => transport.request(WS_METHODS.gitRemoveWorktree, input),
createBranch: (input) => transport.request(WS_METHODS.gitCreateBranch, input),
checkout: (input) => transport.request(WS_METHODS.gitCheckout, input),
-42
View File
@@ -1,6 +1,5 @@
import { Schema } from "effect";
import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas";
import { ChatAttachment, PROVIDER_SEND_TURN_MAX_ATTACHMENTS } from "./orchestration";
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
@@ -68,32 +67,6 @@ export const GitCreateWorktreeInput = Schema.Struct({
});
export type GitCreateWorktreeInput = typeof GitCreateWorktreeInput.Type;
export const GitGenerateBranchNameInput = Schema.Struct({
cwd: TrimmedNonEmptyStringSchema,
message: TrimmedNonEmptyStringSchema,
attachments: Schema.optional(
Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
),
});
export type GitGenerateBranchNameInput = typeof GitGenerateBranchNameInput.Type;
export const GitGenerateAndRenameBranchInput = Schema.Struct({
cwd: TrimmedNonEmptyStringSchema,
oldBranch: TrimmedNonEmptyStringSchema,
message: TrimmedNonEmptyStringSchema,
attachments: Schema.optional(
Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
),
});
export type GitGenerateAndRenameBranchInput = typeof GitGenerateAndRenameBranchInput.Type;
export const GitRenameBranchInput = Schema.Struct({
cwd: TrimmedNonEmptyStringSchema,
oldBranch: TrimmedNonEmptyStringSchema,
newBranch: TrimmedNonEmptyStringSchema,
});
export type GitRenameBranchInput = typeof GitRenameBranchInput.Type;
export const GitRemoveWorktreeInput = Schema.Struct({
cwd: TrimmedNonEmptyStringSchema,
path: TrimmedNonEmptyStringSchema,
@@ -162,21 +135,6 @@ export const GitCreateWorktreeResult = Schema.Struct({
});
export type GitCreateWorktreeResult = typeof GitCreateWorktreeResult.Type;
export const GitGenerateBranchNameResult = Schema.Struct({
branch: Schema.NullOr(TrimmedNonEmptyStringSchema),
});
export type GitGenerateBranchNameResult = typeof GitGenerateBranchNameResult.Type;
export const GitGenerateAndRenameBranchResult = Schema.Struct({
branch: Schema.NullOr(TrimmedNonEmptyStringSchema),
});
export type GitGenerateAndRenameBranchResult = typeof GitGenerateAndRenameBranchResult.Type;
export const GitRenameBranchResult = Schema.Struct({
branch: TrimmedNonEmptyStringSchema,
});
export type GitRenameBranchResult = typeof GitRenameBranchResult.Type;
export const GitRunStackedActionResult = Schema.Struct({
action: GitStackedAction,
commit: Schema.Struct({
-3
View File
@@ -1,8 +1,6 @@
import type {
GitCheckoutInput,
GitCreateBranchInput,
GitRenameBranchInput,
GitRenameBranchResult,
GitCreateWorktreeInput,
GitCreateWorktreeResult,
GitInitInput,
@@ -76,7 +74,6 @@ export interface NativeApi {
// Existing branch/worktree API
listBranches: (input: GitListBranchesInput) => Promise<GitListBranchesResult>;
createWorktree: (input: GitCreateWorktreeInput) => Promise<GitCreateWorktreeResult>;
renameBranch: (input: GitRenameBranchInput) => Promise<GitRenameBranchResult>;
removeWorktree: (input: GitRemoveWorktreeInput) => Promise<void>;
createBranch: (input: GitCreateBranchInput) => Promise<void>;
checkout: (input: GitCheckoutInput) => Promise<void>;
-3
View File
@@ -16,7 +16,6 @@ import {
GitInitInput,
GitListBranchesInput,
GitPullInput,
GitRenameBranchInput,
GitRemoveWorktreeInput,
GitRunStackedActionInput,
GitStatusInput,
@@ -51,7 +50,6 @@ export const WS_METHODS = {
gitRunStackedAction: "git.runStackedAction",
gitListBranches: "git.listBranches",
gitCreateWorktree: "git.createWorktree",
gitRenameBranch: "git.renameBranch",
gitRemoveWorktree: "git.removeWorktree",
gitCreateBranch: "git.createBranch",
gitCheckout: "git.checkout",
@@ -113,7 +111,6 @@ export const WebSocketRequestBody = Schema.Union([
tagRequestBody(WS_METHODS.gitRunStackedAction, GitRunStackedActionInput),
tagRequestBody(WS_METHODS.gitListBranches, GitListBranchesInput),
tagRequestBody(WS_METHODS.gitCreateWorktree, GitCreateWorktreeInput),
tagRequestBody(WS_METHODS.gitRenameBranch, GitRenameBranchInput),
tagRequestBody(WS_METHODS.gitRemoveWorktree, GitRemoveWorktreeInput),
tagRequestBody(WS_METHODS.gitCreateBranch, GitCreateBranchInput),
tagRequestBody(WS_METHODS.gitCheckout, GitCheckoutInput),