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

Function loadWorktreeSnapshot

desktop/project-git/worktree-snapshot.ts:72–112  ·  view source on GitHub ↗
(
  projectId: string,
  options: { baselineRev?: string | undefined | null | undefined } = {},
)

Source from the content-addressed store, hash-verified

70}
71
72export async function loadWorktreeSnapshot(
73 projectId: string,
74 options: { baselineRev?: string | undefined | null | undefined } = {},
75): Promise<WorktreeSnapshot> {
76 return withStagedWorktree(projectId, async ({ env, hasHead }) => {
77 const baselineRev = options.baselineRev?.trim() || (hasHead ? 'HEAD' : EMPTY_TREE_OID)
78 const diffArguments = (extraArgs: string[]) => [
79 'diff',
80 '--cached',
81 ...extraArgs,
82 baselineRev,
83 '--',
84 ]
85
86 const patchPromise = runGitWithOptions(
87 projectId,
88 diffArguments(['--unified=1', '--no-color', '--no-ext-diff', '--find-renames']),
89 {
90 env,
91 timeout: 20_000,
92 maxBuffer: 1024 * 1024 * 24,
93 },
94 ).then(({ stdout }) => stdout.trim())
95
96 const statsPromise = loadWorktreeStats(projectId, { baselineRev, env, hasHead }).catch(() => ({
97 fileCount: 0,
98 insertions: 0,
99 deletions: 0,
100 diffStat: '',
101 nameStatus: '',
102 numStat: '',
103 }))
104
105 const [stats, patchOutput] = await Promise.all([statsPromise, patchPromise])
106
107 return {
108 ...stats,
109 patch: patchOutput,
110 }
111 })
112}
113
114export async function loadWorktreeStats(
115 projectId: string,

Callers 1

loadProjectDiffFunction · 0.90

Calls 5

runGitWithOptionsFunction · 0.90
withStagedWorktreeFunction · 0.85
loadWorktreeStatsFunction · 0.85
allMethod · 0.80
diffArgumentsFunction · 0.70

Tested by

no test coverage detected