From 411583aeef3f0f6fd037bb57c42aa9e3faa231fa Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 20:16:49 +0100 Subject: [PATCH] fix it --- package.json | 2 +- src/tools/sync/git.ts | 27 ++++++++++++++++++--------- tests/tools/sync/git.spec.ts | 13 +++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index f44457d..def5b15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@octomind/octomind", - "version": "3.5.0", + "version": "3.5.1", "description": "a command line client for octomind apis", "main": "./dist/index.js", "packageManager": "pnpm@10.26.0+sha512.3b3f6c725ebe712506c0ab1ad4133cf86b1f4b687effce62a9b38b4d72e3954242e643190fc51fa1642949c735f403debd44f5cb0edd657abe63a8b6a7e1e402", diff --git a/src/tools/sync/git.ts b/src/tools/sync/git.ts index 8479e2f..765b3bd 100644 --- a/src/tools/sync/git.ts +++ b/src/tools/sync/git.ts @@ -66,17 +66,26 @@ export const getDefaultBranch = async ( } } - const origin = await simpleGit().remote(["show", "origin"]); - if (!origin) { - console.warn("could not identify default branch, falling back to 'main'"); - return FALLBACK_DEFAULT_BRANCH; - } + try { + const origin = await simpleGit().remote(["show", "origin"]); + if (!origin) { + console.warn("could not identify default branch, falling back to 'main'"); + return FALLBACK_DEFAULT_BRANCH; + } - const originDefaultBranch = /HEAD branch:((.*))/.exec(origin); + const originDefaultBranch = /HEAD branch:((.*))/.exec(origin); + + return originDefaultBranch?.groups?.["branchName"] + ? `refs/heads/${originDefaultBranch?.groups?.["branchName"]}` + : FALLBACK_DEFAULT_BRANCH; + } catch (e) { + console.warn( + "could not identify default branch, falling back to 'main'", + e, + ); + } - return originDefaultBranch?.groups?.["branchName"] - ? `refs/heads/${originDefaultBranch?.groups?.["branchName"]}` - : FALLBACK_DEFAULT_BRANCH; + return FALLBACK_DEFAULT_BRANCH; }; export const getGitContext = async (): Promise => { diff --git a/tests/tools/sync/git.spec.ts b/tests/tools/sync/git.spec.ts index 0b07136..a033fd3 100644 --- a/tests/tools/sync/git.spec.ts +++ b/tests/tools/sync/git.spec.ts @@ -25,6 +25,19 @@ describe("git", () => { expect(defaultBranch).toEqual("refs/heads/main") expect(console.warn).toHaveBeenCalled() }) + + it("should fallback if both origin and symbolic ref do not return anything and origin throws", async () => { + console.warn = jest.fn(); + mockGit.raw.mockResolvedValue("") + mockGit.remote.mockRejectedValue("") + + const defaultBranch = await getDefaultBranch(); + + expect(defaultBranch).toEqual("refs/heads/main") + expect(console.warn).toHaveBeenCalled() + }) + + }) describe("parseGitRemote", () => {