Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

feat: add selective file staging to commit dialog (#872)

Guilherme Vieirac3bfcc36b870
diff --git a/apps/server/src/git/Layers/GitCore.test.ts b/apps/server/src/git/Layers/GitCore.test.ts
index 379c44472..6c98229e8 100644
--- a/apps/server/src/git/Layers/GitCore.test.ts
+++ b/apps/server/src/git/Layers/GitCore.test.ts
@@ -97,7 +97,7 @@ const makeIsolatedGitCore = (gitService: GitServiceShape) =>
return {
status: (input) => core.status(input),
statusDetails: (cwd) => core.statusDetails(cwd),
- prepareCommitContext: (cwd) => core.prepareCommitContext(cwd),
+ prepareCommitContext: (cwd, filePaths?) => core.prepareCommitContext(cwd, filePaths),
commit: (cwd, subject, body) => core.commit(cwd, subject, body),
pushCurrentBranch: (cwd, fallbackBranch) => core.pushCurrentBranch(cwd, fallbackBranch),
pullCurrentBranch: (cwd) => core.pullCurrentBranch(cwd),
@@ -1711,6 +1711,45 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
+ it.effect("prepareCommitContext stages only selected files when filePaths provided", () =>
+ Effect.gen(function* () {
+ const tmp = yield* makeTmpDir();
+ yield* initRepoWithCommit(tmp);
+ const core = yield* GitCore;
+
+ yield* writeTextFile(path.join(tmp, "a.txt"), "file a\n");
+ yield* writeTextFile(path.join(tmp, "b.txt"), "file b\n");
+
+ const context = yield* core.prepareCommitContext(tmp, ["a.txt"]);
+ expect(context).not.toBeNull();
+ expect(context!.stagedSummary).toContain("a.txt");
+ expect(context!.stagedSummary).not.toContain("b.txt");
+
+ yield* core.commit(tmp, "Add only a.txt", "");
+
+ // b.txt should still be untracked after commit
+ const statusAfter = yield* git(tmp, ["status", "--porcelain"]);
+ expect(statusAfter).toContain("b.txt");
+ expect(statusAfter).not.toContain("a.txt");
+ }),
+ );
+
+ it.effect("prepareCommitContext stages everything when filePaths is undefined", () =>
+ Effect.gen(function* () {
+ const tmp = yield* makeTmpDir();
+ yield* initRepoWithCommit(tmp);
+ const core = yield* GitCore;
+
+ yield* writeTextFile(path.join(tmp, "a.txt"), "file a\n");
+ yield* writeTextFile(path.join(tmp, "b.txt"), "file b\n");
+
+ const context = yield* core.prepareCommitContext(tmp);
+ expect(context).not.toBeNull();
+ expect(context!.stagedSummary).toContain("a.txt");
+ expect(context!.stagedSummary).toContain("b.txt");
+ }),
+ );
+
it.effect("pushes with upstream setup and then skips when up to date", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
diff --git a/apps/server/src/git/Layers/GitCore.ts b/apps/server/src/git/Layers/GitCore.ts
index 3fa0ef1f0..f5b9168ab 100644
--- a/apps/server/src/git/Layers/GitCore.ts
+++ b/apps/server/src/git/Layers/GitCore.ts
@@ -766,9 +766,21 @@ const makeGitCore = Effect.gen(function* () {
})),
);
- const prepareCommitContext: GitCoreShape["prepareCommitContext"] = (cwd) =>
+ const prepareCommitContext: GitCoreShape["prepareCommitContext"] = (cwd, filePaths) =>
Effect.gen(function* () {
- yield* runGit("GitCore.prepareCommitContext.addAll", cwd, ["add", "-A"]);
+ if (filePaths && filePaths.length > 0) {
+ yield* runGit("GitCore.prepareCommitContext.reset", cwd, ["reset"]).pipe(
+ Effect.catch(() => Effect.void),
+ );
+ yield* runGit("GitCore.prepareCommitContext.addSelected", cwd, [
+ "add",
+ "-A",
+ "--",
+ ...filePaths,
+ ]);
+ } else {
+ yield* runGit("GitCore.prepareCommitContext.addAll", cwd, ["add", "-A"]);
+ }
const stagedSummary = yield* runGitStdout("GitCore.prepareCommitContext.stagedSummary", cwd, [
"diff",
diff --git a/apps/server/src/git/Layers/GitManager.test.ts b/apps/server/src/git/Layers/GitManager.test.ts
index cc80eda23..8c72941cd 100644
--- a/apps/server/src/git/Layers/GitManager.test.ts
+++ b/apps/server/src/git/Layers/GitManager.test.ts
@@ -451,6 +451,7 @@ function runStackedAction(
action: "commit" | "commit_push" | "commit_push_pr";
commitMessage?: string;
featureBranch?: boolean;
+ filePaths?: readonly string[];
},
) {
return manager.runStackedAction(input);
@@ -767,6 +768,31 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
+ it.effect("commits only selected files when filePaths is provided", () =>
+ Effect.gen(function* () {
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
+ yield* initRepo(repoDir);
+ fs.writeFileSync(path.join(repoDir, "a.txt"), "file a\n");
+ fs.writeFileSync(path.join(repoDir, "b.txt"), "file b\n");
+
+ const { manager } = yield* makeManager();
+ const result = yield* runStackedAction(manager, {
+ cwd: repoDir,
+ action: "commit",
+ filePaths: ["a.txt"],
+ });
+
+ expect(result.commit.status).toBe("created");
+
+ // b.txt should remain in the working tree
+ const statusStdout = yield* runGit(repoDir, ["status", "--porcelain"]).pipe(
+ Effect.map((r) => r.stdout),
+ );
+ expect(statusStdout).toContain("b.txt");
+ expect(statusStdout).not.toContain("a.txt");
+ }),
+ );
+
it.effect("creates feature branch, commits, and pushes with featureBranch option", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
diff --git a/apps/server/src/git/Layers/GitManager.ts b/apps/server/src/git/Layers/GitManager.ts
index 97760e2d3..835779517 100644
--- a/apps/server/src/git/Layers/GitManager.ts
+++ b/apps/server/src/git/Layers/GitManager.ts
@@ -638,9 +638,10 @@ export const makeGitManager = Effect.gen(function* () {
commitMessage?: string;
/** When true, also produce a semantic feature branch name. */
includeBranch?: boolean;
+ filePaths?: readonly string[];
}) =>
Effect.gen(function* () {
- const context = yield* gitCore.prepareCommitContext(input.cwd);
+ const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths);
if (!context) {
return null;
}
@@ -680,6 +681,7 @@ export const makeGitManager = Effect.gen(function* () {
branch: string | null,
commitMessage?: string,
preResolvedSuggestion?: CommitAndBranchSuggestion,
+ filePaths?: readonly string[],
) =>
Effect.gen(function* () {
const suggestion =
@@ -688,6 +690,7 @@ export const makeGitManager = Effect.gen(function* () {
cwd,
branch,
...(commitMessage ? { commitMessage } : {}),
+ ...(filePaths ? { filePaths } : {}),
}));
if (!suggestion) {
return { status: "skipped_no_changes" as const };
@@ -964,12 +967,18 @@ export const makeGitManager = Effect.gen(function* () {
},
);
- const runFeatureBranchStep = (cwd: string, branch: string | null, commitMessage?: string) =>
+ const runFeatureBranchStep = (
+ cwd: string,
+ branch: string | null,
+ commitMessage?: string,
+ filePaths?: readonly string[],
+ ) =>
Effect.gen(function* () {
const suggestion = yield* resolveCommitAndBranchSuggestion({
cwd,
branch,
...(commitMessage ? { commitMessage } : {}),
+ ...(filePaths ? { filePaths } : {}),
includeBranch: true,
});
if (!suggestion) {
@@ -1018,6 +1027,7 @@ export const makeGitManager = Effect.gen(function* () {
input.cwd,
initialStatus.branch,
input.commitMessage,
+ input.filePaths,
);
branchStep = result.branchStep;
commitMessageForStep = result.resolvedCommitMessage;
@@ -1033,6 +1043,7 @@ export const makeGitManager = Effect.gen(function* () {
currentBranch,
commitMessageForStep,
preResolvedCommitSuggestion,
+ input.filePaths,
);
const push = wantsPush
diff --git a/apps/server/src/git/Services/GitCore.ts b/apps/server/src/git/Services/GitCore.ts
index 502ac349d..879927934 100644
--- a/apps/server/src/git/Services/GitCore.ts
+++ b/apps/server/src/git/Services/GitCore.ts
@@ -101,6 +101,7 @@ export interface GitCoreShape {
*/
readonly prepareCommitContext: (
cwd: string,
+ filePaths?: readonly string[],
) => Effect.Effect<GitPreparedCommitContext | null, GitCommandError>;
/**
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx
index ea1865bc8..e4fad02af 100644
--- a/apps/web/src/components/GitActionsControl.tsx
+++ b/apps/web/src/components/GitActionsControl.tsx
@@ -16,6 +16,7 @@ import {
summarizeGitResult,
} from "./GitActionsControl.logic";
import { Button } from "~/components/ui/button";
+import { Checkbox } from "~/components/ui/checkbox";
import {
Dialog,
DialogDescription,
@@ -56,6 +57,7 @@ interface PendingDefaultBranchAction {
commitMessage?: string;
forcePushOnlyProgress: boolean;
onConfirmed?: () => void;
+ filePaths?: string[];
}
type GitActionToastId = ReturnType<typeof toastManager.add>;
@@ -159,6 +161,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
const queryClient = useQueryClient();
const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
+ const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());
+ const [isEditingFiles, setIsEditingFiles] = useState(false);
const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =
useState<PendingDefaultBranchAction | null>(null);
@@ -179,6 +183,11 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
const gitStatusForActions = isGitStatusOutOfSync ? null : gitStatus;
+ const allFiles = gitStatusForActions?.workingTree.files ?? [];
+ const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
+ const allSelected = excludedFiles.size === 0;
+ const noneSelected = selectedFiles.length === 0;
+
const initMutation = useMutation(gitInitMutationOptions({ cwd: gitCwd, queryClient }));
const runImmediateGitActionMutation = useMutation(
@@ -257,6 +266,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
featureBranch = false,
isDefaultBranchOverride,
progressToastId,
+ filePaths,
}: {
action: GitStackedAction;
commitMessage?: string;
@@ -267,6 +277,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
featureBranch?: boolean;
isDefaultBranchOverride?: boolean;
progressToastId?: GitActionToastId;
+ filePaths?: string[];
}) => {
const actionStatus = statusOverride ?? gitStatusForActions;
const actionBranch = actionStatus?.branch ?? null;
@@ -289,6 +300,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
...(commitMessage ? { commitMessage } : {}),
forcePushOnlyProgress,
...(onConfirmed ? { onConfirmed } : {}),
+ ...(filePaths ? { filePaths } : {}),
});
return;
}
@@ -338,6 +350,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
action,
...(commitMessage ? { commitMessage } : {}),
...(featureBranch ? { featureBranch } : {}),
+ ...(filePaths ? { filePaths } : {}),
});
try {
@@ -439,7 +452,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
const continuePendingDefaultBranchAction = useCallback(() => {
if (!pendingDefaultBranchAction) return;
- const { action, commitMessage, forcePushOnlyProgress, onConfirmed } =
+ const { action, commitMessage, forcePushOnlyProgress, onConfirmed, filePaths } =
pendingDefaultBranchAction;
setPendingDefaultBranchAction(null);
void runGitActionWithToast({
@@ -447,6 +460,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
...(commitMessage ? { commitMessage } : {}),
forcePushOnlyProgress,
...(onConfirmed ? { onConfirmed } : {}),
+ ...(filePaths ? { filePaths } : {}),
skipDefaultBranchPrompt: true,
});
}, [pendingDefaultBranchAction, runGitActionWithToast]);
@@ -457,6 +471,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
commitMessage?: string;
forcePushOnlyProgress?: boolean;
onConfirmed?: () => void;
+ filePaths?: string[];
}) => {
void runGitActionWithToast({
...actionParams,
@@ -469,7 +484,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
const checkoutFeatureBranchAndContinuePendingAction = useCallback(() => {
if (!pendingDefaultBranchAction) return;
- const { action, commitMessage, forcePushOnlyProgress, onConfirmed } =
+ const { action, commitMessage, forcePushOnlyProgress, onConfirmed, filePaths } =
pendingDefaultBranchAction;
setPendingDefaultBranchAction(null);
checkoutNewBranchAndRunAction({
@@ -477,6 +492,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
...(commitMessage ? { commitMessage } : {}),
forcePushOnlyProgress,
...(onConfirmed ? { onConfirmed } : {}),
+ ...(filePaths ? { filePaths } : {}),
});
}, [pendingDefaultBranchAction, checkoutNewBranchAndRunAction]);
@@ -486,12 +502,21 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
setIsCommitDialogOpen(false);
setDialogCommitMessage("");
+ setExcludedFiles(new Set());
+ setIsEditingFiles(false);
checkoutNewBranchAndRunAction({
action: "commit",
...(commitMessage ? { commitMessage } : {}),
+ ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),
});
- }, [isCommitDialogOpen, dialogCommitMessage, checkoutNewBranchAndRunAction]);
+ }, [
+ allSelected,
+ isCommitDialogOpen,
+ dialogCommitMessage,
+ checkoutNewBranchAndRunAction,
+ selectedFiles,
+ ]);
const runQuickAction = useCallback(() => {
if (quickAction.kind === "open_pr") {
@@ -548,6 +573,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
void runGitActionWithToast({ action: "commit_push_pr" });
return;
}
+ setExcludedFiles(new Set());
+ setIsEditingFiles(false);
setIsCommitDialogOpen(true);
},
[openExistingPr, runGitActionWithToast, setIsCommitDialogOpen],
@@ -558,14 +585,19 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
const commitMessage = dialogCommitMessage.trim();
setIsCommitDialogOpen(false);
setDialogCommitMessage("");
+ setExcludedFiles(new Set());
+ setIsEditingFiles(false);
void runGitActionWithToast({
action: "commit",
...(commitMessage ? { commitMessage } : {}),
+ ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),
});
}, [
+ allSelected,
dialogCommitMessage,
isCommitDialogOpen,
runGitActionWithToast,
+ selectedFiles,
setDialogCommitMessage,
setIsCommitDialogOpen,
]);
@@ -730,6 +762,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
if (!open) {
setIsCommitDialogOpen(false);
setDialogCommitMessage("");
+ setExcludedFiles(new Set());
+ setIsEditingFiles(false);
}
}}
>
@@ -752,37 +786,99 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
</span>
</div>
<div className="space-y-1">
- <p className="text-muted-foreground">Files</p>
- {!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ {isEditingFiles && allFiles.length > 0 && (
+ <Checkbox
+ checked={allSelected}
+ indeterminate={!allSelected && !noneSelected}
+ onCheckedChange={() => {
+ setExcludedFiles(
+ allSelected ? new Set(allFiles.map((f) => f.path)) : new Set(),
+ );
+ }}
+ />
+ )}
+ <span className="text-muted-foreground">Files</span>
+ {!allSelected && !isEditingFiles && (
+ <span className="text-muted-foreground">
+ ({selectedFiles.length} of {allFiles.length})
+ </span>
+ )}
+ </div>
+ {allFiles.length > 0 && (
+ <Button
+ variant="ghost"
+ size="xs"
+ onClick={() => setIsEditingFiles((prev) => !prev)}
+ >
+ {isEditingFiles ? "Done" : "Edit"}
+ </Button>
+ )}
+ </div>
+ {!gitStatusForActions || allFiles.length === 0 ? (
<p className="font-medium">none</p>
) : (
<div className="space-y-2">
<ScrollArea className="h-44 rounded-md border border-input bg-background">
<div className="space-y-1 p-1">
- {gitStatusForActions.workingTree.files.map((file) => (
- <button
- type="button"
- key={file.path}
- className="flex w-full items-center justify-between gap-3 rounded-md px-2 py-1 font-mono text-left transition-colors hover:bg-accent/50"
- onClick={() => openChangedFileInEditor(file.path)}
- >
- <span className="truncate">{file.path}</span>
- <span className="shrink-0">
- <span className="text-success">+{file.insertions}</span>
- <span className="text-muted-foreground"> / </span>
- <span className="text-destructive">-{file.deletions}</span>
- </span>
- </button>
- ))}
+ {allFiles.map((file) => {
+ const isExcluded = excludedFiles.has(file.path);
+ return (
+ <div
+ key={file.path}
+ className="flex w-full items-center gap-2 rounded-md px-2 py-1 font-mono text-xs transition-colors hover:bg-accent/50"
+ >
+ {isEditingFiles && (
+ <Checkbox
+ checked={!excludedFiles.has(file.path)}
+ onCheckedChange={() => {
+ setExcludedFiles((prev) => {
+ const next = new Set(prev);
+ if (next.has(file.path)) {
+ next.delete(file.path);
+ } else {
+ next.add(file.path);
+ }
+ return next;
+ });
+ }}
+ />
+ )}
+ <button
+ type="button"
+ className="flex flex-1 items-center justify-between gap-3 text-left truncate"
+ onClick={() => openChangedFileInEditor(file.path)}
+ >
+ <span
+ className={`truncate${isExcluded ? " text-muted-foreground" : ""}`}
+ >
+ {file.path}
+ </span>
+ <span className="shrink-0">
+ {isExcluded ? (
+ <span className="text-muted-foreground">Excluded</span>
+ ) : (
+ <>
+ <span className="text-success">+{file.insertions}</span>
+ <span className="text-muted-foreground"> / </span>
+ <span className="text-destructive">-{file.deletions}</span>
+ </>
+ )}
+ </span>
+ </button>
+ </div>
+ );
+ })}
</div>
</ScrollArea>
<div className="flex justify-end font-mono">
<span className="text-success">
- +{gitStatusForActions.workingTree.insertions}
+ +{selectedFiles.reduce((sum, f) => sum + f.insertions, 0)}
</span>
<span className="text-muted-foreground"> / </span>
<span className="text-destructive">
- -{gitStatusForActions.workingTree.deletions}
+ -{selectedFiles.reduce((sum, f) => sum + f.deletions, 0)}
</span>
</div>
</div>
@@ -806,14 +902,21 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
onClick={() => {
setIsCommitDialogOpen(false);
setDialogCommitMessage("");
+ setExcludedFiles(new Set());
+ setIsEditingFiles(false);
}}
>
Cancel
</Button>
- <Button variant="outline" size="sm" onClick={runDialogActionOnNewBranch}>
+ <Button
+ variant="outline"
+ size="sm"
+ disabled={noneSelected}
+ onClick={runDialogActionOnNewBranch}
+ >
Commit on new branch
</Button>
- <Button size="sm" onClick={runDialogAction}>
+ <Button size="sm" disabled={noneSelected} onClick={runDialogAction}>
Commit
</Button>
</DialogFooter>
diff --git a/apps/web/src/lib/gitReactQuery.ts b/apps/web/src/lib/gitReactQuery.ts
index fe0c4705b..9b5fe7731 100644
--- a/apps/web/src/lib/gitReactQuery.ts
+++ b/apps/web/src/lib/gitReactQuery.ts
@@ -119,10 +119,12 @@ export function gitRunStackedActionMutationOptions(input: {
action,
commitMessage,
featureBranch,
+ filePaths,
}: {
action: GitStackedAction;
commitMessage?: string;
featureBranch?: boolean;
+ filePaths?: string[];
}) => {
const api = ensureNativeApi();
if (!input.cwd) throw new Error("Git action is unavailable.");
@@ -131,6 +133,7 @@ export function gitRunStackedActionMutationOptions(input: {
action,
...(commitMessage ? { commitMessage } : {}),
...(featureBranch ? { featureBranch } : {}),
+ ...(filePaths ? { filePaths } : {}),
});
},
onSettled: async () => {
diff --git a/packages/contracts/src/git.ts b/packages/contracts/src/git.ts
index 34ab11b16..081b4d0d8 100644
--- a/packages/contracts/src/git.ts
+++ b/packages/contracts/src/git.ts
@@ -61,6 +61,9 @@ export const GitRunStackedActionInput = Schema.Struct({
action: GitStackedAction,
commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
featureBranch: Schema.optional(Schema.Boolean),
+ filePaths: Schema.optional(
+ Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
+ ),
});
export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;