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

Function loadWorktreeStats

desktop/project-git/worktree-snapshot.ts:114–177  ·  view source on GitHub ↗
(
  projectId: string,
  options: {
    baselineRev?: string | undefined | null | undefined
    env?: NodeJS.ProcessEnv
    hasHead?: boolean | undefined
  } = {},
)

Source from the content-addressed store, hash-verified

112}
113
114export async function loadWorktreeStats(
115 projectId: string,
116 options: {
117 baselineRev?: string | undefined | null | undefined
118 env?: NodeJS.ProcessEnv
119 hasHead?: boolean | undefined
120 } = {},
121): Promise<WorktreeStats> {
122 const loadStats = async (context?: {
123 env?: NodeJS.ProcessEnv
124 hasHead?: boolean | undefined
125 }) => {
126 const hasHead = context?.hasHead ?? false
127 const baselineRev =
128 context?.hasHead === false
129 ? options.baselineRev?.trim() || EMPTY_TREE_OID
130 : options.baselineRev?.trim() || (hasHead ? 'HEAD' : EMPTY_TREE_OID)
131 const diffArguments = (extraArgs: string[]) => [
132 'diff',
133 '--cached',
134 ...extraArgs,
135 baselineRev,
136 '--',
137 ]
138
139 const numStatOutput = await runGitWithOptions(
140 projectId,
141 diffArguments(['--numstat', '--find-renames']),
142 {
143 env: context?.env ?? process.env,
144 timeout: 20_000,
145 maxBuffer: 1024 * 1024 * 4,
146 },
147 ).then(
148 ({ stdout }) => stdout.trim(),
149 () => '',
150 )
151
152 const numStat = parseNumStat(numStatOutput)
153
154 return {
155 fileCount: numStat.fileCount,
156 insertions: numStat.insertions,
157 deletions: numStat.deletions,
158 diffStat: '',
159 nameStatus: '',
160 numStat: numStatOutput,
161 }
162 }
163
164 if (options.env) {
165 return loadStats({ env: options.env, hasHead: options.hasHead ?? false })
166 }
167
168 return withTemporaryIndex(projectId, async ({ env, hasHead }) => {
169 await runGitWithOptions(projectId, ['add', '-A', '--', '.'], {
170 env,
171 timeout: 20_000,

Callers 2

loadProjectDiffStatsFunction · 0.90
loadWorktreeSnapshotFunction · 0.85

Calls 3

withTemporaryIndexFunction · 0.90
runGitWithOptionsFunction · 0.90
loadStatsFunction · 0.85

Tested by

no test coverage detected