Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions apps/mobile/src/features/threads/git/GitCommitSheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type InputProps = {
const state = vi.hoisted(() => ({
refName: "main" as string | null,
cwd: "/repo",
files: [
{ path: "include.ts", insertions: 1, deletions: 0 },
{ path: "later.ts", insertions: 1, deletions: 0 },
],
result: null as object | null,
pressables: [] as PressProps[],
buttons: [] as PressProps[],
Expand Down Expand Up @@ -60,10 +64,7 @@ vi.mock("../../../state/query", () => ({
refName: state.refName,
isDefaultRef: false,
workingTree: {
files: [
{ path: "include.ts", insertions: 1, deletions: 0 },
{ path: "later.ts", insertions: 1, deletions: 0 },
],
files: [...state.files],
},
},
}),
Expand Down Expand Up @@ -119,9 +120,13 @@ function openSheet() {
};
act(render);
const row = (path: string) => state.pressables.findLast((p) => p.accessibilityLabel === path)!;
const toggleAllButton = () =>
state.buttons.findLast((b) => b.label === "Select all" || b.label === "Deselect all");
return {
isIncluded: (path: string) => row(path).accessibilityState?.checked,
toggle: (path: string) => act(() => row(path).onPress()),
toggleAllLabel: () => toggleAllButton()?.label,
toggleAll: () => act(() => toggleAllButton()!.onPress()),
message: () => state.inputs.at(-1)?.value,
setMessage: (text: string) => act(() => state.inputs.at(-1)?.onChangeText?.(text)),
refresh: () => act(render),
Expand Down Expand Up @@ -285,3 +290,37 @@ it("clears inherited exclusions and message on success with stale branch status"
expect(reopened.message()).toBe("");
reopened.close();
});

it("treats remaining files as all selected when an excluded file disappears", async () => {
const initialFiles = state.files;
state.cwd = "/repo/stale-excluded";
state.refName = "main";
state.result = { commit: { status: "created" } };
state.ran = [];
state.createdBranch = undefined;
state.waitBeforeProgress = null;

const sheet = openSheet();
try {
sheet.toggle("later.ts");
state.files = initialFiles.slice(0, 1);
sheet.refresh();

expect(sheet.toggleAllLabel()).toBe("Deselect all");
sheet.toggleAll();
state.files = initialFiles;
sheet.refresh();
expect(sheet.isIncluded("later.ts")).toBe(false);
expect(sheet.isIncluded("include.ts")).toBe(false);

sheet.toggle("include.ts");
state.files = initialFiles.slice(0, 1);
sheet.refresh();
await sheet.commit();
expect(state.ran).toEqual([
{ action: "commit", featureBranch: false, filePaths: ["include.ts"] },
]);
} finally {
state.files = initialFiles;
}
});
8 changes: 5 additions & 3 deletions apps/mobile/src/features/threads/git/GitCommitSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function GitCommitSheet(props: GitCommitSheetProps) {
}

const selectedFiles = allFiles.filter((file) => !excludedFiles.has(file.path));
const allSelected = excludedFiles.size === 0;
const allSelected = selectedFiles.length === allFiles.length;
const noneSelected = selectedFiles.length === 0;
const selectedInsertions = selectedFiles.reduce((sum, file) => sum + file.insertions, 0);
const selectedDeletions = selectedFiles.reduce((sum, file) => sum + file.deletions, 0);
Expand All @@ -131,7 +131,7 @@ export function GitCommitSheet(props: GitCommitSheetProps) {
action: "commit",
featureBranch,
...(commitMessage ? { commitMessage } : {}),
...(!allSelected ? { filePaths: selectedFiles.map((file) => file.path) } : {}),
...(excludedFiles.size > 0 ? { filePaths: selectedFiles.map((file) => file.path) } : {}),
onProgress: (event) => {
if (event.kind === "action_failed") checkedOutBranch = event.createdBranch;
},
Expand Down Expand Up @@ -216,7 +216,9 @@ export function GitCommitSheet(props: GitCommitSheetProps) {
tone="text"
onPress={() =>
setExcludedFiles(
allSelected ? new Set(allFiles.map((file) => file.path)) : new Set(),
allSelected
? new Set([...excludedFiles, ...allFiles.map((file) => file.path)])
: new Set(),
)
}
/>
Expand Down
Loading