summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-11-11 15:14:37 -0500
committeropencode <[email protected]>2025-11-11 20:17:36 +0000
commitce1397cc34c6a571d455e5089bcf33a9b505cd7e (patch)
tree8ff098c92182563395684f92ccb26948467b3af3
parentdc7c5ced4c6cc3643f62268182530cb41132cdfa (diff)
downloadopencode-ce1397cc34c6a571d455e5089bcf33a9b505cd7e.tar.gz
opencode-ce1397cc34c6a571d455e5089bcf33a9b505cd7e.zip
core: add test to verify OpenCode doesn't crash when starting in git repositories with no commit history
-rw-r--r--packages/opencode/test/project/project.test.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/opencode/test/project/project.test.ts b/packages/opencode/test/project/project.test.ts
new file mode 100644
index 000000000..8e53c5322
--- /dev/null
+++ b/packages/opencode/test/project/project.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, test } from "bun:test"
+import { Project } from "../../src/project/project"
+import { Log } from "../../src/util/log"
+import { $ } from "bun"
+import path from "path"
+import { tmpdir } from "../fixture/fixture"
+
+Log.init({ print: false })
+
+describe("Project.fromDirectory", () => {
+ test("should handle git repository with no commits", async () => {
+ await using tmp = await tmpdir()
+ await $`git init`.cwd(tmp.path).quiet()
+
+ const project = await Project.fromDirectory(tmp.path)
+
+ expect(project).toBeDefined()
+ expect(project.id).toBe("global")
+ expect(project.worktree).toBe("/")
+
+ const opencodeFile = path.join(tmp.path, ".git", "opencode")
+ const fileExists = await Bun.file(opencodeFile).exists()
+ expect(fileExists).toBe(false)
+ })
+
+ test("should handle git repository with commits", async () => {
+ await using tmp = await tmpdir({ git: true })
+
+ const project = await Project.fromDirectory(tmp.path)
+
+ expect(project).toBeDefined()
+ expect(project.id).not.toBe("global")
+ expect(project.vcs).toBe("git")
+ expect(project.worktree).toBe(tmp.path)
+
+ const opencodeFile = path.join(tmp.path, ".git", "opencode")
+ const fileExists = await Bun.file(opencodeFile).exists()
+ expect(fileExists).toBe(true)
+ })
+})