The best way to control Claude Code, Codex and more from any computer or phone
feat: add selective file staging to commit dialog (#872)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Guilherme Vieira committed
Mar 12, 2026 at 17:50 UTC
c3bfcc36b870adbdb01552a7c6b9313a836d7d75
8 files changed
+227
-29
apps/server/src/git/Layers/GitCore.test.ts
+40
-1
@@ -97,7 +97,7 @@ const makeIsolatedGitCore = (gitService: GitServiceShape) =>
97
return {
98
status: (input) => core.status(input),
99
statusDetails: (cwd) => core.statusDetails(cwd),
100
- prepareCommitContext: (cwd) => core.prepareCommitContext(cwd),
100
+ prepareCommitContext: (cwd, filePaths?) => core.prepareCommitContext(cwd, filePaths),
101
commit: (cwd, subject, body) => core.commit(cwd, subject, body),
102
pushCurrentBranch: (cwd, fallbackBranch) => core.pushCurrentBranch(cwd, fallbackBranch),
103
pullCurrentBranch: (cwd) => core.pullCurrentBranch(cwd),
@@ -1711,6 +1711,45 @@ it.layer(TestLayer)("git integration", (it) => {
1711
}),
1712
);
1713
1714
+ it.effect("prepareCommitContext stages only selected files when filePaths provided", () =>
1715
+ Effect.gen(function* () {
1716
+ const tmp = yield* makeTmpDir();
1717
+ yield* initRepoWithCommit(tmp);
1718
+ const core = yield* GitCore;
1719
+
1720
+ yield* writeTextFile(path.join(tmp, "a.txt"), "file a\n");
1721
+ yield* writeTextFile(path.join(tmp, "b.txt"), "file b\n");
1722
+
1723
+ const context = yield* core.prepareCommitContext(tmp, ["a.txt"]);
1724
+ expect(context).not.toBeNull();
1725
+ expect(context!.stagedSummary).toContain("a.txt");
1726
+ expect(context!.stagedSummary).not.toContain("b.txt");
1727
+
1728
+ yield* core.commit(tmp, "Add only a.txt", "");
1729
+
1730
+ // b.txt should still be untracked after commit
1731
+ const statusAfter = yield* git(tmp, ["status", "--porcelain"]);
1732
+ expect(statusAfter).toContain("b.txt");
1733
+ expect(statusAfter).not.toContain("a.txt");
1734
+ }),
1735
+ );
1736
+
1737
+ it.effect("prepareCommitContext stages everything when filePaths is undefined", () =>
1738
+ Effect.gen(function* () {
1739
+ const tmp = yield* makeTmpDir();
1740
+ yield* initRepoWithCommit(tmp);
1741
+ const core = yield* GitCore;
1742
+
1743
+ yield* writeTextFile(path.join(tmp, "a.txt"), "file a\n");
1744
+ yield* writeTextFile(path.join(tmp, "b.txt"), "file b\n");
1745
+
1746
+ const context = yield* core.prepareCommitContext(tmp);
1747
+ expect(context).not.toBeNull();
1748
+ expect(context!.stagedSummary).toContain("a.txt");
1749
+ expect(context!.stagedSummary).toContain("b.txt");
1750
+ }),
1751
+ );
1752
+
1753
it.effect("pushes with upstream setup and then skips when up to date", () =>
1754
Effect.gen(function* () {
1755
const tmp = yield* makeTmpDir();
apps/server/src/git/Layers/GitCore.ts
+14
-2
@@ -766,9 +766,21 @@ const makeGitCore = Effect.gen(function* () {
766
})),
767
);
768
769
- const prepareCommitContext: GitCoreShape["prepareCommitContext"] = (cwd) =>
769
+ const prepareCommitContext: GitCoreShape["prepareCommitContext"] = (cwd, filePaths) =>
770
Effect.gen(function* () {
771
- yield* runGit("GitCore.prepareCommitContext.addAll", cwd, ["add", "-A"]);
771
+ if (filePaths && filePaths.length > 0) {
772
+ yield* runGit("GitCore.prepareCommitContext.reset", cwd, ["reset"]).pipe(
773
+ Effect.catch(() => Effect.void),
774
+ );
775
+ yield* runGit("GitCore.prepareCommitContext.addSelected", cwd, [
776
+ "add",
777
+ "-A",
778
+ "--",
779
+ ...filePaths,
780
+ ]);
781
+ } else {
782
+ yield* runGit("GitCore.prepareCommitContext.addAll", cwd, ["add", "-A"]);
783
+ }
784
785
const stagedSummary = yield* runGitStdout("GitCore.prepareCommitContext.stagedSummary", cwd, [
786
"diff",
apps/server/src/git/Layers/GitManager.test.ts
+26
@@ -451,6 +451,7 @@ function runStackedAction(
451
action: "commit" | "commit_push" | "commit_push_pr";
452
commitMessage?: string;
453
featureBranch?: boolean;
454
+ filePaths?: readonly string[];
455
},
456
) {
457
return manager.runStackedAction(input);
@@ -767,6 +768,31 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
768
}),
769
);
770
771
+ it.effect("commits only selected files when filePaths is provided", () =>
772
+ Effect.gen(function* () {
773
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
774
+ yield* initRepo(repoDir);
775
+ fs.writeFileSync(path.join(repoDir, "a.txt"), "file a\n");
776
+ fs.writeFileSync(path.join(repoDir, "b.txt"), "file b\n");
777
+
778
+ const { manager } = yield* makeManager();
779
+ const result = yield* runStackedAction(manager, {
780
+ cwd: repoDir,
781
+ action: "commit",
782
+ filePaths: ["a.txt"],
783
+ });
784
+
785
+ expect(result.commit.status).toBe("created");
786
+
787
+ // b.txt should remain in the working tree
788
+ const statusStdout = yield* runGit(repoDir, ["status", "--porcelain"]).pipe(
789
+ Effect.map((r) => r.stdout),
790
+ );
791
+ expect(statusStdout).toContain("b.txt");
792
+ expect(statusStdout).not.toContain("a.txt");
793
+ }),
794
+ );
795
+
796
it.effect("creates feature branch, commits, and pushes with featureBranch option", () =>
797
Effect.gen(function* () {
798
const repoDir = yield* makeTempDir("t3code-git-manager-");
apps/server/src/git/Layers/GitManager.ts
+13
-2
@@ -638,9 +638,10 @@ export const makeGitManager = Effect.gen(function* () {
638
commitMessage?: string;
639
/** When true, also produce a semantic feature branch name. */
640
includeBranch?: boolean;
641
+ filePaths?: readonly string[];
642
}) =>
643
Effect.gen(function* () {
643
- const context = yield* gitCore.prepareCommitContext(input.cwd);
644
+ const context = yield* gitCore.prepareCommitContext(input.cwd, input.filePaths);
645
if (!context) {
646
return null;
647
}
@@ -680,6 +681,7 @@ export const makeGitManager = Effect.gen(function* () {
681
branch: string | null,
682
commitMessage?: string,
683
preResolvedSuggestion?: CommitAndBranchSuggestion,
684
+ filePaths?: readonly string[],
685
) =>
686
Effect.gen(function* () {
687
const suggestion =
@@ -688,6 +690,7 @@ export const makeGitManager = Effect.gen(function* () {
690
cwd,
691
branch,
692
...(commitMessage ? { commitMessage } : {}),
693
+ ...(filePaths ? { filePaths } : {}),
694
}));
695
if (!suggestion) {
696
return { status: "skipped_no_changes" as const };
@@ -964,12 +967,18 @@ export const makeGitManager = Effect.gen(function* () {
967
},
968
);
969
967
- const runFeatureBranchStep = (cwd: string, branch: string | null, commitMessage?: string) =>
970
+ const runFeatureBranchStep = (
971
+ cwd: string,
972
+ branch: string | null,
973
+ commitMessage?: string,
974
+ filePaths?: readonly string[],
975
+ ) =>
976
Effect.gen(function* () {
977
const suggestion = yield* resolveCommitAndBranchSuggestion({
978
cwd,
979
branch,
980
...(commitMessage ? { commitMessage } : {}),
981
+ ...(filePaths ? { filePaths } : {}),
982
includeBranch: true,
983
});
984
if (!suggestion) {
@@ -1018,6 +1027,7 @@ export const makeGitManager = Effect.gen(function* () {
1027
input.cwd,
1028
initialStatus.branch,
1029
input.commitMessage,
1030
+ input.filePaths,
1031
);
1032
branchStep = result.branchStep;
1033
commitMessageForStep = result.resolvedCommitMessage;
@@ -1033,6 +1043,7 @@ export const makeGitManager = Effect.gen(function* () {
1043
currentBranch,
1044
commitMessageForStep,
1045
preResolvedCommitSuggestion,
1046
+ input.filePaths,
1047
);
1048
1049
const push = wantsPush
apps/server/src/git/Services/GitCore.ts
+1
@@ -101,6 +101,7 @@ export interface GitCoreShape {
101
*/
102
readonly prepareCommitContext: (
103
cwd: string,
104
+ filePaths?: readonly string[],
105
) => Effect.Effect<GitPreparedCommitContext | null, GitCommandError>;
106
107
/**
apps/web/src/components/GitActionsControl.tsx
+127
-24
@@ -16,6 +16,7 @@ import {
16
summarizeGitResult,
17
} from "./GitActionsControl.logic";
18
import { Button } from "~/components/ui/button";
19
+import { Checkbox } from "~/components/ui/checkbox";
20
import {
21
Dialog,
22
DialogDescription,
@@ -56,6 +57,7 @@ interface PendingDefaultBranchAction {
57
commitMessage?: string;
58
forcePushOnlyProgress: boolean;
59
onConfirmed?: () => void;
60
+ filePaths?: string[];
61
}
62
63
type GitActionToastId = ReturnType<typeof toastManager.add>;
@@ -159,6 +161,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
161
const queryClient = useQueryClient();
162
const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
163
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
164
+ const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());
165
+ const [isEditingFiles, setIsEditingFiles] = useState(false);
166
const [pendingDefaultBranchAction, setPendingDefaultBranchAction] =
167
useState<PendingDefaultBranchAction | null>(null);
168
@@ -179,6 +183,11 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
183
184
const gitStatusForActions = isGitStatusOutOfSync ? null : gitStatus;
185
186
+ const allFiles = gitStatusForActions?.workingTree.files ?? [];
187
+ const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
188
+ const allSelected = excludedFiles.size === 0;
189
+ const noneSelected = selectedFiles.length === 0;
190
+
191
const initMutation = useMutation(gitInitMutationOptions({ cwd: gitCwd, queryClient }));
192
193
const runImmediateGitActionMutation = useMutation(
@@ -257,6 +266,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
266
featureBranch = false,
267
isDefaultBranchOverride,
268
progressToastId,
269
+ filePaths,
270
}: {
271
action: GitStackedAction;
272
commitMessage?: string;
@@ -267,6 +277,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
277
featureBranch?: boolean;
278
isDefaultBranchOverride?: boolean;
279
progressToastId?: GitActionToastId;
280
+ filePaths?: string[];
281
}) => {
282
const actionStatus = statusOverride ?? gitStatusForActions;
283
const actionBranch = actionStatus?.branch ?? null;
@@ -289,6 +300,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
300
...(commitMessage ? { commitMessage } : {}),
301
forcePushOnlyProgress,
302
...(onConfirmed ? { onConfirmed } : {}),
303
+ ...(filePaths ? { filePaths } : {}),
304
});
305
return;
306
}
@@ -338,6 +350,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
350
action,
351
...(commitMessage ? { commitMessage } : {}),
352
...(featureBranch ? { featureBranch } : {}),
353
+ ...(filePaths ? { filePaths } : {}),
354
});
355
356
try {
@@ -439,7 +452,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
452
453
const continuePendingDefaultBranchAction = useCallback(() => {
454
if (!pendingDefaultBranchAction) return;
442
- const { action, commitMessage, forcePushOnlyProgress, onConfirmed } =
455
+ const { action, commitMessage, forcePushOnlyProgress, onConfirmed, filePaths } =
456
pendingDefaultBranchAction;
457
setPendingDefaultBranchAction(null);
458
void runGitActionWithToast({
@@ -447,6 +460,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
460
...(commitMessage ? { commitMessage } : {}),
461
forcePushOnlyProgress,
462
...(onConfirmed ? { onConfirmed } : {}),
463
+ ...(filePaths ? { filePaths } : {}),
464
skipDefaultBranchPrompt: true,
465
});
466
}, [pendingDefaultBranchAction, runGitActionWithToast]);
@@ -457,6 +471,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
471
commitMessage?: string;
472
forcePushOnlyProgress?: boolean;
473
onConfirmed?: () => void;
474
+ filePaths?: string[];
475
}) => {
476
void runGitActionWithToast({
477
...actionParams,
@@ -469,7 +484,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
484
485
const checkoutFeatureBranchAndContinuePendingAction = useCallback(() => {
486
if (!pendingDefaultBranchAction) return;
472
- const { action, commitMessage, forcePushOnlyProgress, onConfirmed } =
487
+ const { action, commitMessage, forcePushOnlyProgress, onConfirmed, filePaths } =
488
pendingDefaultBranchAction;
489
setPendingDefaultBranchAction(null);
490
checkoutNewBranchAndRunAction({
@@ -477,6 +492,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
492
...(commitMessage ? { commitMessage } : {}),
493
forcePushOnlyProgress,
494
...(onConfirmed ? { onConfirmed } : {}),
495
+ ...(filePaths ? { filePaths } : {}),
496
});
497
}, [pendingDefaultBranchAction, checkoutNewBranchAndRunAction]);
498
@@ -486,12 +502,21 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
502
503
setIsCommitDialogOpen(false);
504
setDialogCommitMessage("");
505
+ setExcludedFiles(new Set());
506
+ setIsEditingFiles(false);
507
508
checkoutNewBranchAndRunAction({
509
action: "commit",
510
...(commitMessage ? { commitMessage } : {}),
511
+ ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),
512
});
494
- }, [isCommitDialogOpen, dialogCommitMessage, checkoutNewBranchAndRunAction]);
513
+ }, [
514
+ allSelected,
515
+ isCommitDialogOpen,
516
+ dialogCommitMessage,
517
+ checkoutNewBranchAndRunAction,
518
+ selectedFiles,
519
+ ]);
520
521
const runQuickAction = useCallback(() => {
522
if (quickAction.kind === "open_pr") {
@@ -548,6 +573,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
573
void runGitActionWithToast({ action: "commit_push_pr" });
574
return;
575
}
576
+ setExcludedFiles(new Set());
577
+ setIsEditingFiles(false);
578
setIsCommitDialogOpen(true);
579
},
580
[openExistingPr, runGitActionWithToast, setIsCommitDialogOpen],
@@ -558,14 +585,19 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
585
const commitMessage = dialogCommitMessage.trim();
586
setIsCommitDialogOpen(false);
587
setDialogCommitMessage("");
588
+ setExcludedFiles(new Set());
589
+ setIsEditingFiles(false);
590
void runGitActionWithToast({
591
action: "commit",
592
...(commitMessage ? { commitMessage } : {}),
593
+ ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),
594
});
595
}, [
596
+ allSelected,
597
dialogCommitMessage,
598
isCommitDialogOpen,
599
runGitActionWithToast,
600
+ selectedFiles,
601
setDialogCommitMessage,
602
setIsCommitDialogOpen,
603
]);
@@ -730,6 +762,8 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
762
if (!open) {
763
setIsCommitDialogOpen(false);
764
setDialogCommitMessage("");
765
+ setExcludedFiles(new Set());
766
+ setIsEditingFiles(false);
767
}
768
}}
769
>
@@ -752,37 +786,99 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
786
</span>
787
</div>
788
<div className="space-y-1">
755
- <p className="text-muted-foreground">Files</p>
756
- {!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
789
+ <div className="flex items-center justify-between">
790
+ <div className="flex items-center gap-2">
791
+ {isEditingFiles && allFiles.length > 0 && (
792
+ <Checkbox
793
+ checked={allSelected}
794
+ indeterminate={!allSelected && !noneSelected}
795
+ onCheckedChange={() => {
796
+ setExcludedFiles(
797
+ allSelected ? new Set(allFiles.map((f) => f.path)) : new Set(),
798
+ );
799
+ }}
800
+ />
801
+ )}
802
+ <span className="text-muted-foreground">Files</span>
803
+ {!allSelected && !isEditingFiles && (
804
+ <span className="text-muted-foreground">
805
+ ({selectedFiles.length} of {allFiles.length})
806
+ </span>
807
+ )}
808
+ </div>
809
+ {allFiles.length > 0 && (
810
+ <Button
811
+ variant="ghost"
812
+ size="xs"
813
+ onClick={() => setIsEditingFiles((prev) => !prev)}
814
+ >
815
+ {isEditingFiles ? "Done" : "Edit"}
816
+ </Button>
817
+ )}
818
+ </div>
819
+ {!gitStatusForActions || allFiles.length === 0 ? (
820
<p className="font-medium">none</p>
821
) : (
822
<div className="space-y-2">
823
<ScrollArea className="h-44 rounded-md border border-input bg-background">
824
<div className="space-y-1 p-1">
762
- {gitStatusForActions.workingTree.files.map((file) => (
763
- <button
764
- type="button"
765
- key={file.path}
766
- 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"
767
- onClick={() => openChangedFileInEditor(file.path)}
768
- >
769
- <span className="truncate">{file.path}</span>
770
- <span className="shrink-0">
771
- <span className="text-success">+{file.insertions}</span>
772
- <span className="text-muted-foreground"> / </span>
773
- <span className="text-destructive">-{file.deletions}</span>
774
- </span>
775
- </button>
776
- ))}
825
+ {allFiles.map((file) => {
826
+ const isExcluded = excludedFiles.has(file.path);
827
+ return (
828
+ <div
829
+ key={file.path}
830
+ className="flex w-full items-center gap-2 rounded-md px-2 py-1 font-mono text-xs transition-colors hover:bg-accent/50"
831
+ >
832
+ {isEditingFiles && (
833
+ <Checkbox
834
+ checked={!excludedFiles.has(file.path)}
835
+ onCheckedChange={() => {
836
+ setExcludedFiles((prev) => {
837
+ const next = new Set(prev);
838
+ if (next.has(file.path)) {
839
+ next.delete(file.path);
840
+ } else {
841
+ next.add(file.path);
842
+ }
843
+ return next;
844
+ });
845
+ }}
846
+ />
847
+ )}
848
+ <button
849
+ type="button"
850
+ className="flex flex-1 items-center justify-between gap-3 text-left truncate"
851
+ onClick={() => openChangedFileInEditor(file.path)}
852
+ >
853
+ <span
854
+ className={`truncate${isExcluded ? " text-muted-foreground" : ""}`}
855
+ >
856
+ {file.path}
857
+ </span>
858
+ <span className="shrink-0">
859
+ {isExcluded ? (
860
+ <span className="text-muted-foreground">Excluded</span>
861
+ ) : (
862
+ <>
863
+ <span className="text-success">+{file.insertions}</span>
864
+ <span className="text-muted-foreground"> / </span>
865
+ <span className="text-destructive">-{file.deletions}</span>
866
+ </>
867
+ )}
868
+ </span>
869
+ </button>
870
+ </div>
871
+ );
872
+ })}
873
</div>
874
</ScrollArea>
875
<div className="flex justify-end font-mono">
876
<span className="text-success">
781
- +{gitStatusForActions.workingTree.insertions}
877
+ +{selectedFiles.reduce((sum, f) => sum + f.insertions, 0)}
878
</span>
879
<span className="text-muted-foreground"> / </span>
880
<span className="text-destructive">
785
- -{gitStatusForActions.workingTree.deletions}
881
+ -{selectedFiles.reduce((sum, f) => sum + f.deletions, 0)}
882
</span>
883
</div>
884
</div>
@@ -806,14 +902,21 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
902
onClick={() => {
903
setIsCommitDialogOpen(false);
904
setDialogCommitMessage("");
905
+ setExcludedFiles(new Set());
906
+ setIsEditingFiles(false);
907
}}
908
>
909
Cancel
910
</Button>
813
- <Button variant="outline" size="sm" onClick={runDialogActionOnNewBranch}>
911
+ <Button
912
+ variant="outline"
913
+ size="sm"
914
+ disabled={noneSelected}
915
+ onClick={runDialogActionOnNewBranch}
916
+ >
917
Commit on new branch
918
</Button>
816
- <Button size="sm" onClick={runDialogAction}>
919
+ <Button size="sm" disabled={noneSelected} onClick={runDialogAction}>
920
Commit
921
</Button>
922
</DialogFooter>
apps/web/src/lib/gitReactQuery.ts
+3
@@ -119,10 +119,12 @@ export function gitRunStackedActionMutationOptions(input: {
119
action,
120
commitMessage,
121
featureBranch,
122
+ filePaths,
123
}: {
124
action: GitStackedAction;
125
commitMessage?: string;
126
featureBranch?: boolean;
127
+ filePaths?: string[];
128
}) => {
129
const api = ensureNativeApi();
130
if (!input.cwd) throw new Error("Git action is unavailable.");
@@ -131,6 +133,7 @@ export function gitRunStackedActionMutationOptions(input: {
133
action,
134
...(commitMessage ? { commitMessage } : {}),
135
...(featureBranch ? { featureBranch } : {}),
136
+ ...(filePaths ? { filePaths } : {}),
137
});
138
},
139
onSettled: async () => {
packages/contracts/src/git.ts
+3
@@ -61,6 +61,9 @@ export const GitRunStackedActionInput = Schema.Struct({
61
action: GitStackedAction,
62
commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
63
featureBranch: Schema.optional(Schema.Boolean),
64
+ filePaths: Schema.optional(
65
+ Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
66
+ ),
67
});
68
export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;
69