refactor(ui): group menu by category and unify file selection
This commit is contained in:
+14
-14
@@ -1,5 +1,11 @@
|
||||
import { loadConfig } from "../config";
|
||||
import { isGitRepo, getStagedDiff, getUnstagedFiles, stageFiles } from "../git";
|
||||
import {
|
||||
isGitRepo,
|
||||
getStagedFiles,
|
||||
getStagedDiff,
|
||||
getUnstagedFiles,
|
||||
applyFileSelection,
|
||||
} from "../git";
|
||||
import { selectFiles } from "../selector";
|
||||
import { BACK, SKIP_WAIT } from "../menu";
|
||||
import {
|
||||
@@ -51,21 +57,15 @@ export async function handleSuggest(args: ParsedArgs): Promise<number> {
|
||||
diff = "";
|
||||
}
|
||||
} else {
|
||||
diff = await getStagedDiff();
|
||||
const stagedFiles = await getStagedFiles();
|
||||
const unstagedFiles = await getUnstagedFiles();
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user