(name: string)
| 323 | * @returns The commit hash of the checkpoint |
| 324 | */ |
| 325 | export async function createCheckpoint(name: string): Promise<string> { |
| 326 | // Add a timestamp to make the tag name unique |
| 327 | const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); |
| 328 | const uniqueName = `${name}-${timestamp}`; |
| 329 | |
| 330 | // Create a tag for the checkpoint |
| 331 | const tagCmd = new Deno.Command("git", { |
| 332 | args: ["tag", uniqueName], |
| 333 | stdout: "piped", |
| 334 | stderr: "piped", |
| 335 | }); |
| 336 | |
| 337 | const tagOutput = await tagCmd.output(); |
| 338 | if (!tagOutput.success) { |
| 339 | const errorOutput = new TextDecoder().decode(tagOutput.stderr); |
| 340 | await logMessage("error", `Creating checkpoint tag failed: ${errorOutput}`, { |
| 341 | name: uniqueName, |
| 342 | }); |
| 343 | throw new Error(`Creating checkpoint tag failed: ${errorOutput}`); |
| 344 | } |
| 345 | |
| 346 | // Get the commit hash for the tag |
| 347 | const revParseCmd = new Deno.Command("git", { |
| 348 | args: ["rev-parse", uniqueName], |
| 349 | stdout: "piped", |
| 350 | stderr: "piped", |
| 351 | }); |
| 352 | |
| 353 | const revParseOutput = await revParseCmd.output(); |
| 354 | if (!revParseOutput.success) { |
| 355 | const errorOutput = new TextDecoder().decode(revParseOutput.stderr); |
| 356 | await logMessage("error", `Getting checkpoint commit hash failed: ${errorOutput}`, { |
| 357 | name: uniqueName, |
| 358 | }); |
| 359 | throw new Error(`Getting checkpoint commit hash failed: ${errorOutput}`); |
| 360 | } |
| 361 | |
| 362 | const commitHash = new TextDecoder().decode(revParseOutput.stdout).trim(); |
| 363 | |
| 364 | await logMessage("info", `Created checkpoint ${uniqueName} at commit ${commitHash}`); |
| 365 | |
| 366 | return commitHash; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Get the current branch name |
no test coverage detected