MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / initShadowGit

Function initShadowGit

src/services/checkpoints/ShadowCheckpointService.ts:165–243  ·  view source on GitHub ↗
(onInit?: () => Promise<void>)

Source from the content-addressed store, hash-verified

163 }
164
165 public async initShadowGit(onInit?: () => Promise<void>) {
166 if (this.git) {
167 throw new Error("Shadow git repo already initialized")
168 }
169
170 const nestedGitPath = await this.getNestedGitRepository()
171
172 if (nestedGitPath) {
173 // Show persistent error message with the offending path
174 const relativePath = path.relative(this.workspaceDir, nestedGitPath)
175 const message = t("common:errors.nested_git_repos_warning", { path: relativePath })
176 vscode.window.showErrorMessage(message)
177
178 throw new Error(
179 `Checkpoints are disabled because a nested git repository was detected at: ${relativePath}. ` +
180 "Please remove or relocate nested git repositories to use the checkpoints feature.",
181 )
182 }
183
184 await fs.mkdir(this.checkpointsDir, { recursive: true })
185 const git = createSanitizedGit(this.checkpointsDir)
186 const gitVersion = await git.version()
187 this.log(`[${this.constructor.name}#create] git = ${gitVersion}`)
188
189 let created = false
190 const startTime = Date.now()
191
192 if (await fileExistsAtPath(this.dotGitDir)) {
193 this.log(`[${this.constructor.name}#initShadowGit] shadow git repo already exists at ${this.dotGitDir}`)
194 const worktree = await this.getShadowGitConfigWorktree(git)
195
196 if (!worktree) {
197 throw new Error("Checkpoints require core.worktree to be set in the shadow git config")
198 }
199
200 const worktreeTrimmed = worktree.trim()
201
202 if (!arePathsEqual(worktreeTrimmed, this.workspaceDir)) {
203 throw new Error(
204 `Checkpoints can only be used in the original workspace: ${worktreeTrimmed} !== ${this.workspaceDir}`,
205 )
206 }
207
208 await this.writeExcludeFile()
209 this.baseHash = await git.revparse(["HEAD"])
210 } else {
211 this.log(`[${this.constructor.name}#initShadowGit] creating shadow git repo at ${this.checkpointsDir}`)
212 await git.init({ "--template": "" })
213 await git.addConfig("core.worktree", this.workspaceDir) // Sets the working tree to the current workspace.
214 await git.addConfig("commit.gpgSign", "false") // Disable commit signing for shadow repo.
215 await git.addConfig("user.name", "Roo Code")
216 await git.addConfig("user.email", "noreply@example.com")
217 await this.writeExcludeFile()
218 await this.stageAll(git)
219 const { commit } = await git.commit("initial commit", { "--allow-empty": null })
220 this.baseHash = commit
221 created = true
222 }

Callers

nothing calls this directly

Calls 7

tFunction · 0.90
fileExistsAtPathFunction · 0.90
arePathsEqualFunction · 0.90
createSanitizedGitFunction · 0.85
logMethod · 0.65
emitMethod · 0.65
showErrorMessageMethod · 0.45

Tested by

no test coverage detected