Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 18 additions & 9 deletions src/tools/sync/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:(<branchName>(.*))/.exec(origin);
const originDefaultBranch = /HEAD branch:(<branchName>(.*))/.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<GitContext | undefined> => {
Expand Down
13 changes: 13 additions & 0 deletions tests/tools/sync/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down