Skip to content

Commit dcebebb

Browse files
committed
Fix tests
1 parent 8082f82 commit dcebebb

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/services/checkpoints/CheckpointService.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -242,37 +242,33 @@ export class CheckpointService {
242242
* repository. Addionally, creates a hidden branch for storing checkpoints.
243243
*/
244244
private static async initRepo({ taskId, git, baseDir, log }: Required<CheckpointServiceOptions>) {
245-
if (!existsSync(path.join(baseDir, ".git"))) {
246-
try {
247-
await git.init()
248-
log(`[ensureGitRepo] Initialized new Git repository at ${baseDir}`)
249-
250-
// We need at least one file to commit, otherwise the initial
251-
// commit will fail, unless we use the `--allow-empty` flag.
252-
// However, using an empty commit causes problems when restoring
253-
// the checkpoint (i.e. the `git restore` command doesn't work
254-
// for empty commits).
255-
await fs.writeFile(path.join(baseDir, ".gitkeep"), "")
256-
await git.add(".")
257-
const commit = await git.commit("Initial commit")
258-
259-
if (!commit.commit) {
260-
throw new Error("Failed to create initial commit")
261-
}
262-
263-
log(`[ensureGitRepo] Initial commit: ${commit.commit}`)
264-
} catch (err) {
265-
log(
266-
`[ensureGitRepo] Failed to initialize repository: ${err instanceof Error ? err.message : String(err)}`,
267-
)
268-
269-
throw err
270-
}
245+
const isExistingRepo = existsSync(path.join(baseDir, ".git"))
246+
247+
if (!isExistingRepo) {
248+
await git.init()
249+
log(`[initRepo] Initialized new Git repository at ${baseDir}`)
271250
}
272251

273252
await git.addConfig("user.name", "Roo Code")
274253
await git.addConfig("user.email", "[email protected]")
275254

255+
if (!isExistingRepo) {
256+
// We need at least one file to commit, otherwise the initial
257+
// commit will fail, unless we use the `--allow-empty` flag.
258+
// However, using an empty commit causes problems when restoring
259+
// the checkpoint (i.e. the `git restore` command doesn't work
260+
// for empty commits).
261+
await fs.writeFile(path.join(baseDir, ".gitkeep"), "")
262+
await git.add(".")
263+
const commit = await git.commit("Initial commit")
264+
265+
if (!commit.commit) {
266+
throw new Error("Failed to create initial commit")
267+
}
268+
269+
log(`[initRepo] Initial commit: ${commit.commit}`)
270+
}
271+
276272
const currentBranch = await git.revparse(["--abbrev-ref", "HEAD"])
277273
const currentSha = await git.revparse(["HEAD"])
278274

src/services/checkpoints/__tests__/CheckpointService.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from "fs/promises"
44
import path from "path"
55
import os from "os"
66

7-
import { CommitResult, simpleGit, SimpleGit } from "simple-git"
7+
import { simpleGit, SimpleGit } from "simple-git"
88

99
import { CheckpointService } from "../CheckpointService"
1010

@@ -57,8 +57,9 @@ describe("CheckpointService", () => {
5757

5858
const checkpoints = await service.listCheckpoints()
5959
expect(checkpoints.length).toBe(2)
60-
expect(checkpoints[0].message).toBe(commitMessage)
61-
expect(checkpoints[0].hash).toBe(commit?.commit)
60+
const checkpoint = checkpoints.find(({ message }) => message === commitMessage)
61+
expect(checkpoint).toBeDefined()
62+
expect(checkpoint?.hash).toBe(commit?.commit)
6263
})
6364

6465
it("saves and restores checkpoints", async () => {

0 commit comments

Comments
 (0)