feat(commands): add ability to choose files to stage (#22)
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
|||||||
confirm,
|
confirm,
|
||||||
intro,
|
intro,
|
||||||
isCancel,
|
isCancel,
|
||||||
|
multiselect,
|
||||||
note,
|
note,
|
||||||
outro,
|
outro,
|
||||||
select,
|
select,
|
||||||
@@ -31,7 +32,7 @@ import {
|
|||||||
} from "@clack/prompts";
|
} from "@clack/prompts";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import simpleGit from "simple-git";
|
import simpleGit, { ResetMode } from "simple-git";
|
||||||
|
|
||||||
const command = new Command("commit")
|
const command = new Command("commit")
|
||||||
.alias("c")
|
.alias("c")
|
||||||
@@ -69,6 +70,37 @@ const command = new Command("commit")
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stageableFiles = (await simpleGit().status()).files;
|
||||||
|
if (stageAll === false) {
|
||||||
|
const stagedFiles = (await simpleGit().diff(["--name-only", "--cached"]))
|
||||||
|
.split("\n")
|
||||||
|
.filter((file) => file);
|
||||||
|
|
||||||
|
const filesToStage = await multiselect({
|
||||||
|
message: "Which files would you like to stash?",
|
||||||
|
options: stageableFiles.map((file) => ({
|
||||||
|
value: file.path,
|
||||||
|
label: file.path,
|
||||||
|
hint: file.from,
|
||||||
|
})),
|
||||||
|
initialValues: stagedFiles,
|
||||||
|
required: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isCancel(filesToStage)) {
|
||||||
|
cancel("Commit creation cancelled");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
await simpleGit().reset(ResetMode.MIXED);
|
||||||
|
await simpleGit().add(filesToStage);
|
||||||
|
} else if (stageAll === true) {
|
||||||
|
note(
|
||||||
|
stageableFiles.map((file) => file.path).join("\n"),
|
||||||
|
"Committing following files",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const changedLines = (
|
const changedLines = (
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user