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 biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
"$schema": "https://biomejs.dev/schemas/2.3.9/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@octomind/octomind",
"version": "3.4.0",
"version": "3.4.1",
"description": "a command line client for octomind apis",
"main": "./dist/index.js",
"packageManager": "pnpm@10.26.0+sha512.3b3f6c725ebe712506c0ab1ad4133cf86b1f4b687effce62a9b38b4d72e3954242e643190fc51fa1642949c735f403debd44f5cb0edd657abe63a8b6a7e1e402",
Expand All @@ -26,7 +26,7 @@
"lint": "pnpm apigen && npx genversion -des src/version.ts && biome check",
"tsc": "tsc --project tsconfig.build.json",
"dev:staging": "pnpm apigen && OCTOMIND_CONFIG_FILE=octomind.dev.staging.json OCTOMIND_API_URL=https://preview.octomind.dev/api tsx src/index.ts",
"dev:prod": "pnpm apigen && OCTOMIND_CONFIG_FILE=octomind.dev.staging.json OCTOMIND_API_URL=https://app.octomind.dev/api tsx src/index.ts",
"dev:prod": "pnpm apigen && OCTOMIND_CONFIG_FILE=octomind.dev.prod.json OCTOMIND_API_URL=https://app.octomind.dev/api tsx src/index.ts",
Comment thread
Germandrummer92 marked this conversation as resolved.
"apigen": "openapi-typescript https://preview.octomind.dev/openapi.yaml --output src/api.ts && orval",
"build": "pnpm apigen && npx genversion -des src/version.ts && pnpm gendoc && tsc --project tsconfig.build.json",
"octomind": "pnpm apigen && tsx src/index.ts",
Expand Down
35 changes: 30 additions & 5 deletions src/tools/sync/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { simpleGit } from "simple-git";

import { ExecutionContext } from "./types";

const FALLBACK_DEFAULT_BRANCH = "refs/heads/main";

export const parseGitRemote = async (): Promise<{
owner?: string;
repo?: string;
Expand Down Expand Up @@ -41,11 +43,34 @@ export type GitContext = ExecutionContext & {
defaultBranch?: string;
};

export const getDefaultBranch = async (): Promise<string> => {
const symbolicRef = (
await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD")
).trim();
return symbolicRef.replace("refs/remotes/origin/", "refs/heads/");
export const getDefaultBranch = async (
allowedMethod: "symbolicRef+origin" | "origin" = "symbolicRef+origin",
): Promise<string> => {
if (allowedMethod === "symbolicRef+origin") {
const symbolicRef = (
await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD")
).trim();
const symbolicRefBranch = symbolicRef.replace(
"refs/remotes/origin/",
"refs/heads/",
);

if (symbolicRefBranch) {
return symbolicRefBranch;
}
}

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);

return originDefaultBranch?.groups?.["branchName"]
? `refs/heads/${originDefaultBranch?.groups?.["branchName"]}`
: FALLBACK_DEFAULT_BRANCH;
};

export const getGitContext = async (): Promise<GitContext | undefined> => {
Expand Down
10 changes: 9 additions & 1 deletion tests/tools/sync/git.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {parseGitRemote} from "../../../src/tools/sync/git";
import {getDefaultBranch, parseGitRemote} from "../../../src/tools/sync/git";

describe('git', () => {
it("should return the actual owner and repo", async () => {
Expand All @@ -7,4 +7,12 @@ describe('git', () => {
expect(remote.owner).toEqual("OctoMind-dev");
expect(remote.repo).toEqual("cli");
})

it.each(["origin"] as const)("should return the actual default branch for method '%s'", async (allowedMethod) => {
const defaultBranch = await getDefaultBranch(allowedMethod);

expect(defaultBranch).toEqual("refs/heads/main");
});


})
15 changes: 14 additions & 1 deletion tests/tools/sync/git.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {simpleGit} from "simple-git";
import {parseGitRemote, getGitContext} from "../../../src/tools/sync/git";
import {parseGitRemote, getGitContext, getDefaultBranch} from "../../../src/tools/sync/git";
import {mock} from "jest-mock-extended";

jest.mock("simple-git");
Expand All @@ -14,6 +14,19 @@ describe("git", () => {
console.error = jest.fn();
})

describe("getDefaultBranch", () => {
it("should fallback if both origin and symbolic ref fail", async () => {
console.warn = jest.fn();
mockGit.raw.mockResolvedValue("")
mockGit.remote.mockResolvedValue("")

const defaultBranch = await getDefaultBranch();

expect(defaultBranch).toEqual("refs/heads/main")
expect(console.warn).toHaveBeenCalled()
})
})

describe("parseGitRemote", () => {
it("parses SSH git remote format (git@github.com:owner/repo.git)", async () => {
mockGit.remote.mockResolvedValue("git@github.com:my-org/my-repo.git");
Expand Down