-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdiffIndexGenerateCommit.ts
More file actions
47 lines (39 loc) · 1.32 KB
/
diffIndexGenerateCommit.ts
File metadata and controls
47 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
/**
* Git commit AutoCommitMsg script.
*/
import { execFileSync } from "child_process";
import { generateCommitMessage } from "./diffIndexGenerate";
import { shouldShowHelp } from "./utils";
const HELP_TEXT: string = `Usage: gacm [--cached] [--help|-h]
Check Git changes, generate a commit message, and run Git commit.
Options:
--cached Use only staged changes (equivalent to git --cached).
If the flag is omitted, then the standard \`git status\` logic is followed:
look for staged changes and use them, otherwise use unstaged changes.
--help, -h Show this help and exit.`;
/**
* Command-line entry-point.
*/
function main(argv: string[]): void {
if (shouldShowHelp(argv)) {
console.log(HELP_TEXT);
return;
}
const useCached: boolean = argv.includes("--cached");
const passthrough: string[] = argv.filter(
(arg: string) => arg !== "--cached",
);
const msg: string = generateCommitMessage(useCached);
const commitArgs: string[] = ["commit", "--edit", "-m", msg, ...passthrough];
execFileSync("git", commitArgs, { stdio: "inherit" });
}
if (require.main === module) {
try {
main(process.argv.slice(2));
} catch (err) {
const message: string = err instanceof Error ? err.message : String(err);
console.error(`Error: ${message}`);
process.exit(1);
}
}