MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / _bundleWithFallback

Function _bundleWithFallback

source code/utils/teleport/gitBundle.ts:52–148  ·  view source on GitHub ↗
(
  gitRoot: string,
  bundlePath: string,
  maxBytes: number,
  hasStash: boolean,
  signal: AbortSignal | undefined,
)

Source from the content-addressed store, hash-verified

50// commit of HEAD's tree (or the stash tree if WIP exists) — no history,
51// just the snapshot. Receiver needs refs/seed/root handling for that tier.
52async function _bundleWithFallback(
53 gitRoot: string,
54 bundlePath: string,
55 maxBytes: number,
56 hasStash: boolean,
57 signal: AbortSignal | undefined,
58): Promise<BundleCreateResult> {
59 // --all picks up refs/seed/stash; HEAD needs it explicit.
60 const extra = hasStash ? ['refs/seed/stash'] : []
61 const mkBundle = (base: string) =>
62 execFileNoThrowWithCwd(
63 gitExe(),
64 ['bundle', 'create', bundlePath, base, ...extra],
65 { cwd: gitRoot, abortSignal: signal },
66 )
67
68 const allResult = await mkBundle('--all')
69 if (allResult.code !== 0) {
70 return {
71 ok: false,
72 error: `git bundle create --all failed (${allResult.code}): ${allResult.stderr.slice(0, 200)}`,
73 failReason: 'git_error',
74 }
75 }
76
77 const { size: allSize } = await stat(bundlePath)
78 if (allSize <= maxBytes) {
79 return { ok: true, size: allSize, scope: 'all' }
80 }
81
82 // bundle create overwrites in place.
83 logForDebugging(
84 `[gitBundle] --all bundle is ${(allSize / 1024 / 1024).toFixed(1)}MB (> ${(maxBytes / 1024 / 1024).toFixed(0)}MB), retrying HEAD-only`,
85 )
86 const headResult = await mkBundle('HEAD')
87 if (headResult.code !== 0) {
88 return {
89 ok: false,
90 error: `git bundle create HEAD failed (${headResult.code}): ${headResult.stderr.slice(0, 200)}`,
91 failReason: 'git_error',
92 }
93 }
94
95 const { size: headSize } = await stat(bundlePath)
96 if (headSize <= maxBytes) {
97 return { ok: true, size: headSize, scope: 'head' }
98 }
99
100 // Last resort: squash to a single parentless commit. Uses the stash tree
101 // when WIP exists (bakes uncommitted changes in — can't bundle the stash
102 // ref separately since its parents would drag history back).
103 logForDebugging(
104 `[gitBundle] HEAD bundle is ${(headSize / 1024 / 1024).toFixed(1)}MB, retrying squashed-root`,
105 )
106 const treeRef = hasStash ? 'refs/seed/stash^{tree}' : 'HEAD^{tree}'
107 const commitTree = await execFileNoThrowWithCwd(
108 gitExe(),
109 ['commit-tree', treeRef, '-m', 'seed'],

Callers 1

createAndUploadGitBundleFunction · 0.85

Calls 4

mkBundleFunction · 0.85
statFunction · 0.85
logForDebuggingFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85

Tested by

no test coverage detected