Browse Source

fix: ensure that vcs is still set to git even if no commits in repo

Aiden Cline 2 months ago
parent
commit
767a81f930

+ 3 - 13
packages/opencode/src/project/project.ts

@@ -64,17 +64,6 @@ export namespace Project {
       if (id) Bun.file(path.join(git, "opencode")).write(id)
       if (id) Bun.file(path.join(git, "opencode")).write(id)
     }
     }
     timer.stop()
     timer.stop()
-    if (!id) {
-      const project: Info = {
-        id: "global",
-        worktree: "/",
-        time: {
-          created: Date.now(),
-        },
-      }
-      await Storage.write<Info>(["project", "global"], project)
-      return project
-    }
     worktree = await $`git rev-parse --show-toplevel`
     worktree = await $`git rev-parse --show-toplevel`
       .quiet()
       .quiet()
       .nothrow()
       .nothrow()
@@ -87,8 +76,9 @@ export namespace Project {
       .cwd(worktree)
       .cwd(worktree)
       .text()
       .text()
       .then((x) => path.resolve(worktree, x.trim()))
       .then((x) => path.resolve(worktree, x.trim()))
+    const projectID = id || "global"
     const project: Info = {
     const project: Info = {
-      id,
+      id: projectID,
       worktree,
       worktree,
       vcsDir,
       vcsDir,
       vcs: "git",
       vcs: "git",
@@ -96,7 +86,7 @@ export namespace Project {
         created: Date.now(),
         created: Date.now(),
       },
       },
     }
     }
-    await Storage.write<Info>(["project", id], project)
+    await Storage.write<Info>(["project", projectID], project)
     return project
     return project
   }
   }
 
 

+ 3 - 1
packages/opencode/test/project/project.test.ts

@@ -16,7 +16,9 @@ describe("Project.fromDirectory", () => {
 
 
     expect(project).toBeDefined()
     expect(project).toBeDefined()
     expect(project.id).toBe("global")
     expect(project.id).toBe("global")
-    expect(project.worktree).toBe("/")
+    expect(project.vcs).toBe("git")
+    expect(project.worktree).toBe(tmp.path)
+    expect(project.vcsDir).toBe(path.join(tmp.path, ".git"))
 
 
     const opencodeFile = path.join(tmp.path, ".git", "opencode")
     const opencodeFile = path.join(tmp.path, ".git", "opencode")
     const fileExists = await Bun.file(opencodeFile).exists()
     const fileExists = await Bun.file(opencodeFile).exists()