From 8ff80637ab838971843abea13b9f91f64ca59bc3 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Wed, 8 Apr 2026 22:28:53 +0200 Subject: [PATCH] refactor(web): use head.shortName for default branch Now that Repository.head returns a GitRef instead of GitCommit, we can use the ref name directly instead of hash-matching against the refs list. Co-Authored-By: Claude Opus 4.6 (1M context) --- webui2/src/__generated__/graphql.ts | 17 ++++++++++++----- webui2/src/routes/$repo.tsx | 4 ++-- webui2/src/routes/$repo/index.tsx | 5 +---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/webui2/src/__generated__/graphql.ts b/webui2/src/__generated__/graphql.ts index a09c4332b496b871e6ca29f2572595187ba9eb73..43a0ff6313e99c5a8f14bf4b398e9a3432dcac27 100644 --- a/webui2/src/__generated__/graphql.ts +++ b/webui2/src/__generated__/graphql.ts @@ -731,6 +731,8 @@ export enum GitObjectType { /** A git branch or tag reference. */ export type GitRef = { __typename?: 'GitRef'; + /** Git commit the reference points to. */ + commit: GitCommit; /** Commit hash the reference points to. */ hash: Scalars['String']['output']; /** Full reference name, e.g. refs/heads/main or refs/tags/v1.0. */ @@ -748,10 +750,12 @@ export type GitRefConnection = { totalCount: Scalars['Int']['output']; }; -/** The kind of git reference: a branch or a tag. */ +/** The kind of git reference: a branch, a tag, or a detached commit. */ export enum GitRefType { /** A local branch (refs/heads/*). */ Branch = 'BRANCH', + /** A detached HEAD pointing directly at a commit. */ + Commit = 'COMMIT', /** An annotated or lightweight tag (refs/tags/*). */ Tag = 'TAG' } @@ -1006,11 +1010,11 @@ export type Repository = { */ commits: GitCommitConnection; /** - * The commit pointed to by HEAD in the git repository. - * Null if HEAD cannot be resolved to a commit, for example in an empty or unborn + * The reference pointed to by HEAD in the git repository. + * Null if HEAD cannot be resolved, for example in an empty or unborn * repository, or if HEAD is missing or invalid. */ - head?: Maybe; + head?: Maybe; /** Look up an identity by id prefix. Returns null if no identity matches the prefix. */ identity?: Maybe; /** @@ -1021,7 +1025,10 @@ export type Repository = { lastCommits: Array; /** The name of the repository. Null for the default (unnamed) repository in a single-repo setup. */ name?: Maybe; - /** All branches and tags, optionally filtered by type. */ + /** + * All branches and tags, optionally filtered by type. BRANCH and TAG are + * the only accepted filter values; passing COMMIT returns an error. + */ refs: GitRefConnection; /** Directory listing at path under ref. An empty path returns the root tree. */ tree: Array; diff --git a/webui2/src/routes/$repo.tsx b/webui2/src/routes/$repo.tsx index a687a9a5bfe5e736c8fb1369709ff03e11a894dd..7448dafa18acd87e5898f4c519abcf0475a6c585 100644 --- a/webui2/src/routes/$repo.tsx +++ b/webui2/src/routes/$repo.tsx @@ -8,7 +8,7 @@ export const REFS_QUERY = gql` repository(ref: $repo) { name head { - hash + shortName } refs { nodes { @@ -25,7 +25,7 @@ export const REFS_QUERY = gql` export interface RefsQueryData { repository: { name: string; - head: { hash: string } | null; + head: { shortName: string } | null; refs: { nodes: GitRef[] } | null; } | null; } diff --git a/webui2/src/routes/$repo/index.tsx b/webui2/src/routes/$repo/index.tsx index 48c5d839a9d2624fc21c5c95f2ce10a113997973..4d17a83cb182bc05634f2e1a96fa7b434c97d16f 100644 --- a/webui2/src/routes/$repo/index.tsx +++ b/webui2/src/routes/$repo/index.tsx @@ -13,10 +13,7 @@ export const Route = createFileRoute("/$repo/")({ query: REFS_QUERY, variables: { repo: ref }, }); - const refs = data?.repository?.refs?.nodes ?? []; - const headHash = data?.repository?.head?.hash; - const defaultRef = headHash ? refs.find((r) => r.hash === headHash) : undefined; - const refName = defaultRef?.shortName ?? refs[0]?.shortName ?? "master"; + const refName = data?.repository?.head?.shortName ?? "master"; throw redirect({ to: "/$repo/tree/$ref/$",