MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / prepareCommitMessageContext

Function prepareCommitMessageContext

desktop/project-git/commit-context.ts:45–179  ·  view source on GitHub ↗
(
  projectId: string,
  includeUnstaged: boolean,
)

Source from the content-addressed store, hash-verified

43}
44
45export async function prepareCommitMessageContext(
46 projectId: string,
47 includeUnstaged: boolean,
48): Promise<CommitMessageContext | null> {
49 if (!(await isGitRepository(projectId))) {
50 return null
51 }
52
53 const diffArguments = (hasHead: boolean, extraArgs: string[]) => [
54 'diff',
55 '--cached',
56 ...(hasHead ? [] : ['--root']),
57 ...extraArgs,
58 '--',
59 ]
60
61 const loadContextOutputs = async (options?: {
62 env?: NodeJS.ProcessEnv
63 hasHead?: boolean | undefined
64 }) => {
65 const hasHead = options?.hasHead ?? (await hasHeadCommit(projectId))
66
67 const [
68 branch,
69 originUrl,
70 shortStatOutput,
71 diffStatOutput,
72 nameStatusOutput,
73 numStatOutput,
74 patchOutput,
75 ] = await Promise.all([
76 getBranch(projectId),
77 getOriginUrl(projectId),
78 runGitWithOptions(projectId, diffArguments(hasHead, ['--shortstat']), {
79 env: options?.env ?? process.env,
80 timeout: 10_000,
81 maxBuffer: 1024 * 1024 * 4,
82 }).then(
83 ({ stdout }) => stdout.trim(),
84 () => '',
85 ),
86 runGitWithOptions(projectId, diffArguments(hasHead, ['--stat=200,200', '--find-renames']), {
87 env: options?.env ?? process.env,
88 timeout: 10_000,
89 maxBuffer: 1024 * 1024 * 4,
90 }).then(
91 ({ stdout }) => stdout.trim(),
92 () => '',
93 ),
94 runGitWithOptions(projectId, diffArguments(hasHead, ['--name-status', '--find-renames']), {
95 env: options?.env ?? process.env,
96 timeout: 10_000,
97 maxBuffer: 1024 * 1024 * 4,
98 }).then(
99 ({ stdout }) => stdout.trim(),
100 () => '',
101 ),
102 runGitWithOptions(projectId, diffArguments(hasHead, ['--numstat', '--find-renames']), {

Callers 1

commitProjectChangesFunction · 0.90

Calls 6

isGitRepositoryFunction · 0.90
withTemporaryIndexFunction · 0.90
runGitWithOptionsFunction · 0.90
loadContextOutputsFunction · 0.85
countNonEmptyLinesFunction · 0.85
parseShortStatFunction · 0.70

Tested by

no test coverage detected