MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / prepareCommitMessageHook

Function prepareCommitMessageHook

out/cli.cjs:86110–86181  ·  view source on GitHub ↗
(isStageAllFlag = false)

Source from the content-addressed store, hash-verified

86108 }
86109 }
86110);
86111
86112// src/commands/prepare-commit-msg-hook.ts
86113var import_promises4 = __toESM(require("fs/promises"), 1);
86114init_dist2();
86115var [messageFilePath, commitSource] = process.argv.slice(2);
86116var prepareCommitMessageHook = async (isStageAllFlag = false) => {
86117 try {
86118 if (!messageFilePath) {
86119 throw new Error(
86120 'Commit message file path is missing. This file should be called from the "prepare-commit-msg" git hook'
86121 );
86122 }
86123 if (commitSource) return;
86124 if (isStageAllFlag) {
86125 const changedFiles = await getChangedFiles();
86126 if (changedFiles) await gitAdd({ files: changedFiles });
86127 else {
86128 ce("No changes detected, write some code and run `oco` again");
86129 process.exit(1);
86130 }
86131 }
86132 const staged = await getStagedFiles();
86133 if (!staged) return;
86134 ae("opencommit");
86135 const config8 = getConfig();
86136 if (!config8.OCO_API_KEY) {
86137 ce(
86138 "No OCO_API_KEY is set. Set your key via `oco config set OCO_API_KEY=<value>. For more info see https://github.com/di-sukharev/opencommit"
86139 );
86140 return;
86141 }
86142 const spin = le();
86143 spin.start("Generating commit message");
86144 let commitMessage;
86145 try {
86146 commitMessage = await generateCommitMessageByDiff(
86147 await getDiff({ files: staged })
86148 );
86149 } catch (error) {
86150 spin.stop("Done");
86151 throw error;
86152 }
86153 spin.stop("Done");
86154 const fileContent = await import_promises4.default.readFile(messageFilePath);
86155 const messageWithComment = `# ${commitMessage}
86156
86157# ---------- [OpenCommit] ---------- #
86158# Remove the # above to use this generated commit message.
86159# To cancel the commit, just close this window without making any changes.
86160
86161${fileContent.toString()}`;
86162 const messageWithoutComment = `${commitMessage}
86163
86164${fileContent.toString()}`;
86165 const message = config8.OCO_HOOK_AUTO_UNCOMMENT ? messageWithoutComment : messageWithComment;
86166 await import_promises4.default.writeFile(messageFilePath, message);
86167 } catch (error) {

Callers 1

cli.cjsFile · 0.70

Calls 8

getChangedFilesFunction · 0.70
gitAddFunction · 0.70
getStagedFilesFunction · 0.70
getConfigFunction · 0.70
getDiffFunction · 0.70
startMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…