From afb1bbeb71ad9e85aa2bd40d43bc5d06eb26ae8b Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Fri, 17 Apr 2026 16:36:44 +0800 Subject: [PATCH] fix(service): use default_branch for graph and reflog endpoints - git_commit_graph: use default_branch when rev is None - git_commit_graph_react: use default_branch when rev is None - git_commit_reflog: fall back to default_branch when HEAD is detached Fixes errors: - reference 'refs/heads/master' not found (graph-react endpoint) - HEAD has no name (reflog endpoint when HEAD is detached) --- libs/service/git/commit.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/service/git/commit.rs b/libs/service/git/commit.rs index 56d8ac3..386c16c 100644 --- a/libs/service/git/commit.rs +++ b/libs/service/git/commit.rs @@ -1031,6 +1031,15 @@ impl AppService { ) -> Result, AppError> { let repo = self.utils_find_repo(namespace, repo_name, ctx).await?; + // If refname is None and HEAD is detached, fall back to default_branch + let refname = refname.or_else(|| { + if repo.default_branch.is_empty() { + None + } else { + Some(repo.default_branch.clone()) + } + }); + let entries = git_spawn!(repo, domain -> { domain.reflog_entries(refname.as_deref()) })?; @@ -1064,7 +1073,13 @@ impl AppService { } let repo = self.utils_find_repo(namespace, repo_name, ctx).await?; - let rev_clone = query.rev.clone(); + let rev_clone = query.rev.clone().or_else(|| { + if repo.default_branch.is_empty() { + None + } else { + Some(format!("refs/heads/{}", repo.default_branch)) + } + }); let limit = query.limit.unwrap_or(0); let graph = git_spawn!(repo, domain -> { @@ -1112,7 +1127,13 @@ impl AppService { } let repo = self.utils_find_repo(namespace, repo_name, ctx).await?; - let rev_clone = query.rev.clone(); + let rev_clone = query.rev.clone().or_else(|| { + if repo.default_branch.is_empty() { + None + } else { + Some(format!("refs/heads/{}", repo.default_branch)) + } + }); let limit = query.limit.unwrap_or(0); let (graph, refs_grouped) = git_spawn!(repo, domain -> {