Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
243e8a44a9 | ||
|
|
77a64493bb | ||
|
|
c3af56e177 | ||
|
|
22cf222e20 | ||
|
|
d2c62488b2 | ||
|
|
5a57ada95b |
No files matched your search
@@ -12,6 +12,7 @@ import { GitCoreLive } from "./GitCore.ts";
|
|||||||
import { GitCore, type GitCoreShape } from "../Services/GitCore.ts";
|
import { GitCore, type GitCoreShape } from "../Services/GitCore.ts";
|
||||||
import { GitCommandError } from "../Errors.ts";
|
import { GitCommandError } from "../Errors.ts";
|
||||||
import { type ProcessRunResult, runProcess } from "../../processRunner.ts";
|
import { type ProcessRunResult, runProcess } from "../../processRunner.ts";
|
||||||
|
import { tokenizeCommitFlags } from "./GitManager.ts";
|
||||||
|
|
||||||
// ── Helpers ──
|
// ── Helpers ──
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ const makeIsolatedGitCore = (gitService: GitServiceShape) =>
|
|||||||
status: (input) => core.status(input),
|
status: (input) => core.status(input),
|
||||||
statusDetails: (cwd) => core.statusDetails(cwd),
|
statusDetails: (cwd) => core.statusDetails(cwd),
|
||||||
prepareCommitContext: (cwd, filePaths?) => core.prepareCommitContext(cwd, filePaths),
|
prepareCommitContext: (cwd, filePaths?) => core.prepareCommitContext(cwd, filePaths),
|
||||||
commit: (cwd, subject, body) => core.commit(cwd, subject, body),
|
commit: (cwd, subject, body, extraArgs?) => core.commit(cwd, subject, body, extraArgs),
|
||||||
pushCurrentBranch: (cwd, fallbackBranch) => core.pushCurrentBranch(cwd, fallbackBranch),
|
pushCurrentBranch: (cwd, fallbackBranch) => core.pushCurrentBranch(cwd, fallbackBranch),
|
||||||
pullCurrentBranch: (cwd) => core.pullCurrentBranch(cwd),
|
pullCurrentBranch: (cwd) => core.pullCurrentBranch(cwd),
|
||||||
readRangeContext: (cwd, baseBranch) => core.readRangeContext(cwd, baseBranch),
|
readRangeContext: (cwd, baseBranch) => core.readRangeContext(cwd, baseBranch),
|
||||||
@@ -1903,4 +1904,90 @@ it.layer(TestLayer)("git integration", (it) => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("tokenizeCommitFlags", () => {
|
||||||
|
it("returns empty array for undefined", () => {
|
||||||
|
expect(tokenizeCommitFlags(undefined)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns empty array for empty string", () => {
|
||||||
|
expect(tokenizeCommitFlags("")).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns empty array for whitespace-only string", () => {
|
||||||
|
expect(tokenizeCommitFlags(" ")).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("tokenizes a single flag", () => {
|
||||||
|
expect(tokenizeCommitFlags("--no-gpg-sign")).toEqual(["--no-gpg-sign"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("tokenizes multiple flags separated by spaces", () => {
|
||||||
|
expect(tokenizeCommitFlags("--no-gpg-sign --signoff")).toEqual([
|
||||||
|
"--no-gpg-sign",
|
||||||
|
"--signoff",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles extra whitespace between flags", () => {
|
||||||
|
expect(tokenizeCommitFlags(" --no-gpg-sign --signoff ")).toEqual([
|
||||||
|
"--no-gpg-sign",
|
||||||
|
"--signoff",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps flags with = values intact", () => {
|
||||||
|
expect(tokenizeCommitFlags("--cleanup=verbatim")).toEqual(["--cleanup=verbatim"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops tokens that do not start with a dash", () => {
|
||||||
|
expect(tokenizeCommitFlags("--author Foo")).toEqual(["--author"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops all non-flag tokens from a mixed input", () => {
|
||||||
|
expect(tokenizeCommitFlags("HEAD --no-verify somefile.txt -S")).toEqual([
|
||||||
|
"--no-verify",
|
||||||
|
"-S",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("commit with extraArgs", () => {
|
||||||
|
it.effect("passes extra flags through to git commit", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const tmp = yield* makeTmpDir();
|
||||||
|
yield* initRepoWithCommit(tmp);
|
||||||
|
const core = yield* GitCore;
|
||||||
|
|
||||||
|
yield* writeTextFile(path.join(tmp, "extra.txt"), "extra args test\n");
|
||||||
|
yield* git(tmp, ["add", "extra.txt"]);
|
||||||
|
|
||||||
|
const { commitSha } = yield* core.commit(tmp, "test extra args", "", [
|
||||||
|
"--no-gpg-sign",
|
||||||
|
]);
|
||||||
|
expect(commitSha).toBeTruthy();
|
||||||
|
|
||||||
|
// Verify the commit was created with the right message
|
||||||
|
const logOutput = yield* git(tmp, ["log", "-1", "--pretty=%s"]);
|
||||||
|
expect(logOutput).toBe("test extra args");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
it.effect("works without extra args (backward compat)", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const tmp = yield* makeTmpDir();
|
||||||
|
yield* initRepoWithCommit(tmp);
|
||||||
|
const core = yield* GitCore;
|
||||||
|
|
||||||
|
yield* writeTextFile(path.join(tmp, "compat.txt"), "compat test\n");
|
||||||
|
yield* git(tmp, ["add", "compat.txt"]);
|
||||||
|
|
||||||
|
const { commitSha } = yield* core.commit(tmp, "no extra args", "");
|
||||||
|
expect(commitSha).toBeTruthy();
|
||||||
|
|
||||||
|
const logOutput = yield* git(tmp, ["log", "-1", "--pretty=%s"]);
|
||||||
|
expect(logOutput).toBe("no extra args");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -804,13 +804,16 @@ const makeGitCore = Effect.gen(function* () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const commit: GitCoreShape["commit"] = (cwd, subject, body) =>
|
const commit: GitCoreShape["commit"] = (cwd, subject, body, extraArgs = []) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const args = ["commit", "-m", subject];
|
const args = ["commit", "-m", subject];
|
||||||
const trimmedBody = body.trim();
|
const trimmedBody = body.trim();
|
||||||
if (trimmedBody.length > 0) {
|
if (trimmedBody.length > 0) {
|
||||||
args.push("-m", trimmedBody);
|
args.push("-m", trimmedBody);
|
||||||
}
|
}
|
||||||
|
// Append extra flags after the message args so an argument-consuming
|
||||||
|
// flag (e.g. `-C`) cannot accidentally swallow `-m` or the subject.
|
||||||
|
args.push(...extraArgs);
|
||||||
yield* runGit("GitCore.commit.commit", cwd, args);
|
yield* runGit("GitCore.commit.commit", cwd, args);
|
||||||
const commitSha = yield* runGitStdout("GitCore.commit.revParseHead", cwd, [
|
const commitSha = yield* runGitStdout("GitCore.commit.revParseHead", cwd, [
|
||||||
"rev-parse",
|
"rev-parse",
|
||||||
|
|||||||
@@ -207,6 +207,23 @@ interface CommitAndBranchSuggestion {
|
|||||||
commitMessage: string;
|
commitMessage: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tokenize and sanitise user-provided extra flags for `git commit`.
|
||||||
|
*
|
||||||
|
* Each token must look like a CLI flag (start with `-`). Tokens that don't
|
||||||
|
* start with a dash are silently dropped so that a malformed value like
|
||||||
|
* `--author "Foo"` (which the naive split turns into `["--author", "Foo"]`)
|
||||||
|
* cannot inject a positional argument into the git invocation.
|
||||||
|
*/
|
||||||
|
export function tokenizeCommitFlags(rawFlags?: string): string[] {
|
||||||
|
const tokens = (rawFlags ?? "")
|
||||||
|
.trim()
|
||||||
|
.split(/\s+/g)
|
||||||
|
.filter((value) => value.length > 0);
|
||||||
|
|
||||||
|
return tokens.filter((token) => token.startsWith("-"));
|
||||||
|
}
|
||||||
|
|
||||||
function formatCommitMessage(subject: string, body: string): string {
|
function formatCommitMessage(subject: string, body: string): string {
|
||||||
const trimmedBody = body.trim();
|
const trimmedBody = body.trim();
|
||||||
if (trimmedBody.length === 0) {
|
if (trimmedBody.length === 0) {
|
||||||
@@ -682,6 +699,7 @@ export const makeGitManager = Effect.gen(function* () {
|
|||||||
cwd: string,
|
cwd: string,
|
||||||
branch: string | null,
|
branch: string | null,
|
||||||
commitMessage?: string,
|
commitMessage?: string,
|
||||||
|
commitFlags?: string,
|
||||||
preResolvedSuggestion?: CommitAndBranchSuggestion,
|
preResolvedSuggestion?: CommitAndBranchSuggestion,
|
||||||
filePaths?: readonly string[],
|
filePaths?: readonly string[],
|
||||||
model?: string,
|
model?: string,
|
||||||
@@ -700,7 +718,12 @@ export const makeGitManager = Effect.gen(function* () {
|
|||||||
return { status: "skipped_no_changes" as const };
|
return { status: "skipped_no_changes" as const };
|
||||||
}
|
}
|
||||||
|
|
||||||
const { commitSha } = yield* gitCore.commit(cwd, suggestion.subject, suggestion.body);
|
const { commitSha } = yield* gitCore.commit(
|
||||||
|
cwd,
|
||||||
|
suggestion.subject,
|
||||||
|
suggestion.body,
|
||||||
|
tokenizeCommitFlags(commitFlags),
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
status: "created" as const,
|
status: "created" as const,
|
||||||
commitSha,
|
commitSha,
|
||||||
@@ -1050,6 +1073,7 @@ export const makeGitManager = Effect.gen(function* () {
|
|||||||
input.cwd,
|
input.cwd,
|
||||||
currentBranch,
|
currentBranch,
|
||||||
commitMessageForStep,
|
commitMessageForStep,
|
||||||
|
input.commitFlags,
|
||||||
preResolvedCommitSuggestion,
|
preResolvedCommitSuggestion,
|
||||||
input.filePaths,
|
input.filePaths,
|
||||||
input.textGenerationModel,
|
input.textGenerationModel,
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export interface GitCoreShape {
|
|||||||
cwd: string,
|
cwd: string,
|
||||||
subject: string,
|
subject: string,
|
||||||
body: string,
|
body: string,
|
||||||
|
extraArgs?: readonly string[],
|
||||||
) => Effect.Effect<{ commitSha: string }, GitCommandError>;
|
) => Effect.Effect<{ commitSha: string }, GitCommandError>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const AppSettingsSchema = Schema.Struct({
|
|||||||
codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(
|
codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(
|
||||||
Schema.withConstructorDefault(() => Option.some("")),
|
Schema.withConstructorDefault(() => Option.some("")),
|
||||||
),
|
),
|
||||||
|
gitCommitFlags: Schema.String.check(Schema.isMaxLength(4096)).pipe(
|
||||||
|
Schema.withConstructorDefault(() => Option.some("")),
|
||||||
|
),
|
||||||
defaultThreadEnvMode: Schema.Literals(["local", "worktree"]).pipe(
|
defaultThreadEnvMode: Schema.Literals(["local", "worktree"]).pipe(
|
||||||
Schema.withConstructorDefault(() => Option.some("local")),
|
Schema.withConstructorDefault(() => Option.some("local")),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
|
|||||||
import { ScrollArea } from "~/components/ui/scroll-area";
|
import { ScrollArea } from "~/components/ui/scroll-area";
|
||||||
import { Textarea } from "~/components/ui/textarea";
|
import { Textarea } from "~/components/ui/textarea";
|
||||||
import { toastManager } from "~/components/ui/toast";
|
import { toastManager } from "~/components/ui/toast";
|
||||||
|
import { useAppSettings } from "~/appSettings";
|
||||||
import { openInPreferredEditor } from "~/editorPreferences";
|
import { openInPreferredEditor } from "~/editorPreferences";
|
||||||
import {
|
import {
|
||||||
gitBranchesQueryOptions,
|
gitBranchesQueryOptions,
|
||||||
@@ -160,6 +161,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
|||||||
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
|
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
|
||||||
[activeThreadId],
|
[activeThreadId],
|
||||||
);
|
);
|
||||||
|
const { settings } = useAppSettings();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
|
const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
|
||||||
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
|
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
|
||||||
@@ -205,6 +207,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
|||||||
useIsMutating({ mutationKey: gitMutationKeys.runStackedAction(gitCwd) }) > 0;
|
useIsMutating({ mutationKey: gitMutationKeys.runStackedAction(gitCwd) }) > 0;
|
||||||
const isPullRunning = useIsMutating({ mutationKey: gitMutationKeys.pull(gitCwd) }) > 0;
|
const isPullRunning = useIsMutating({ mutationKey: gitMutationKeys.pull(gitCwd) }) > 0;
|
||||||
const isGitActionRunning = isRunStackedActionRunning || isPullRunning;
|
const isGitActionRunning = isRunStackedActionRunning || isPullRunning;
|
||||||
|
const configuredCommitFlags = settings.gitCommitFlags.trim();
|
||||||
const isDefaultBranch = useMemo(() => {
|
const isDefaultBranch = useMemo(() => {
|
||||||
const branchName = gitStatusForActions?.branch;
|
const branchName = gitStatusForActions?.branch;
|
||||||
if (!branchName) return false;
|
if (!branchName) return false;
|
||||||
@@ -355,6 +358,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
|||||||
const promise = runImmediateGitActionMutation.mutateAsync({
|
const promise = runImmediateGitActionMutation.mutateAsync({
|
||||||
action,
|
action,
|
||||||
...(commitMessage ? { commitMessage } : {}),
|
...(commitMessage ? { commitMessage } : {}),
|
||||||
|
...(configuredCommitFlags ? { commitFlags: configuredCommitFlags } : {}),
|
||||||
...(featureBranch ? { featureBranch } : {}),
|
...(featureBranch ? { featureBranch } : {}),
|
||||||
...(filePaths ? { filePaths } : {}),
|
...(filePaths ? { filePaths } : {}),
|
||||||
});
|
});
|
||||||
@@ -448,6 +452,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
|
|||||||
},
|
},
|
||||||
|
|
||||||
[
|
[
|
||||||
|
configuredCommitFlags,
|
||||||
isDefaultBranch,
|
isDefaultBranch,
|
||||||
runImmediateGitActionMutation,
|
runImmediateGitActionMutation,
|
||||||
setPendingDefaultBranchAction,
|
setPendingDefaultBranchAction,
|
||||||
|
|||||||
@@ -119,11 +119,13 @@ export function gitRunStackedActionMutationOptions(input: {
|
|||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
action,
|
action,
|
||||||
commitMessage,
|
commitMessage,
|
||||||
|
commitFlags,
|
||||||
featureBranch,
|
featureBranch,
|
||||||
filePaths,
|
filePaths,
|
||||||
}: {
|
}: {
|
||||||
action: GitStackedAction;
|
action: GitStackedAction;
|
||||||
commitMessage?: string;
|
commitMessage?: string;
|
||||||
|
commitFlags?: string;
|
||||||
featureBranch?: boolean;
|
featureBranch?: boolean;
|
||||||
filePaths?: string[];
|
filePaths?: string[];
|
||||||
}) => {
|
}) => {
|
||||||
@@ -133,6 +135,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
|||||||
cwd: input.cwd,
|
cwd: input.cwd,
|
||||||
action,
|
action,
|
||||||
...(commitMessage ? { commitMessage } : {}),
|
...(commitMessage ? { commitMessage } : {}),
|
||||||
|
...(commitFlags ? { commitFlags } : {}),
|
||||||
...(featureBranch ? { featureBranch } : {}),
|
...(featureBranch ? { featureBranch } : {}),
|
||||||
...(filePaths ? { filePaths } : {}),
|
...(filePaths ? { filePaths } : {}),
|
||||||
...(input.model ? { model: input.model } : {}),
|
...(input.model ? { model: input.model } : {}),
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ function SettingsRouteView() {
|
|||||||
|
|
||||||
const codexBinaryPath = settings.codexBinaryPath;
|
const codexBinaryPath = settings.codexBinaryPath;
|
||||||
const codexHomePath = settings.codexHomePath;
|
const codexHomePath = settings.codexHomePath;
|
||||||
|
const gitCommitFlags = settings.gitCommitFlags;
|
||||||
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
|
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
|
||||||
const availableEditors = serverConfigQuery.data?.availableEditors;
|
const availableEditors = serverConfigQuery.data?.availableEditors;
|
||||||
|
|
||||||
@@ -615,6 +616,48 @@ function SettingsRouteView() {
|
|||||||
) : null}
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-2xl border border-border bg-card p-5">
|
||||||
|
<div className="mb-4">
|
||||||
|
<h2 className="text-sm font-medium text-foreground">Git</h2>
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">
|
||||||
|
Configure extra flags for app-run <code>git commit</code> commands.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<label htmlFor="git-commit-flags" className="block space-y-1">
|
||||||
|
<span className="text-xs font-medium text-foreground">
|
||||||
|
Extra git commit flags
|
||||||
|
</span>
|
||||||
|
<Input
|
||||||
|
id="git-commit-flags"
|
||||||
|
value={gitCommitFlags}
|
||||||
|
onChange={(event) => updateSettings({ gitCommitFlags: event.target.value })}
|
||||||
|
placeholder="--no-gpg-sign"
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
Applied to app-run git commit commands only. Example:{" "}
|
||||||
|
<code>--no-gpg-sign</code>. Quoted arguments are not supported yet.
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() =>
|
||||||
|
updateSettings({
|
||||||
|
gitCommitFlags: defaults.gitCommitFlags,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Restore default
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section className="rounded-2xl border border-border bg-card p-5">
|
<section className="rounded-2xl border border-border bg-card p-5">
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<h2 className="text-sm font-medium text-foreground">Responses</h2>
|
<h2 className="text-sm font-medium text-foreground">Responses</h2>
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export const GitRunStackedActionInput = Schema.Struct({
|
|||||||
cwd: TrimmedNonEmptyStringSchema,
|
cwd: TrimmedNonEmptyStringSchema,
|
||||||
action: GitStackedAction,
|
action: GitStackedAction,
|
||||||
commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
|
commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
|
||||||
|
commitFlags: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4_096))),
|
||||||
featureBranch: Schema.optional(Schema.Boolean),
|
featureBranch: Schema.optional(Schema.Boolean),
|
||||||
filePaths: Schema.optional(
|
filePaths: Schema.optional(
|
||||||
Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
|
Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
|
||||||
|
|||||||
Reference in new issue
Block a user