refactor(ui): group menu by category and unify file selection
This commit is contained in:
+17
-16
@@ -1,5 +1,12 @@
|
||||
import { loadConfig } from "../config";
|
||||
import { isGitRepo, getStagedDiff, getUnstagedFiles, getRepoRoot, stageFiles } from "../git";
|
||||
import {
|
||||
isGitRepo,
|
||||
getStagedFiles,
|
||||
getStagedDiff,
|
||||
getUnstagedFiles,
|
||||
getRepoRoot,
|
||||
applyFileSelection,
|
||||
} from "../git";
|
||||
import { selectFiles } from "../selector";
|
||||
import { BACK, SKIP_WAIT } from "../menu";
|
||||
import { collectProjectContext } from "../context";
|
||||
@@ -53,22 +60,16 @@ export async function handleReview(args: ParsedArgs): Promise<number> {
|
||||
console.error(`\n ${RED()}Error: Not a git repository.${RESET()}\n`);
|
||||
return 1;
|
||||
}
|
||||
diff = await getStagedDiff();
|
||||
sourceLabel = "staged changes";
|
||||
const stagedFiles = await getStagedFiles();
|
||||
const unstagedFiles = await getUnstagedFiles();
|
||||
sourceLabel = "selected changes";
|
||||
|
||||
// If no staged changes, offer to stage unstaged files
|
||||
if (!diff) {
|
||||
const unstagedFiles = await getUnstagedFiles();
|
||||
if (unstagedFiles.length > 0) {
|
||||
const selected = await selectFiles([], unstagedFiles);
|
||||
if (selected === BACK) return SKIP_WAIT as unknown as number;
|
||||
if (selected.length > 0) {
|
||||
await stageFiles(selected);
|
||||
console.log(` ${GREEN()}Staged ${selected.length} file(s).${RESET()}`);
|
||||
diff = await getStagedDiff();
|
||||
}
|
||||
}
|
||||
if (stagedFiles.length > 0 || unstagedFiles.length > 0) {
|
||||
const selected = await selectFiles(stagedFiles, unstagedFiles);
|
||||
if (selected === BACK) return SKIP_WAIT as unknown as number;
|
||||
await applyFileSelection(stagedFiles, unstagedFiles, selected);
|
||||
}
|
||||
diff = await getStagedDiff();
|
||||
}
|
||||
|
||||
if (!diff) {
|
||||
@@ -110,7 +111,7 @@ export async function handleReview(args: ParsedArgs): Promise<number> {
|
||||
}
|
||||
|
||||
try {
|
||||
const callbacks: StreamCallbacks = tty ? {
|
||||
const callbacks: StreamCallbacks | undefined = tty ? {
|
||||
onToken: (token) => process.stdout.write(token),
|
||||
} : undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user