fix(service): use default_branch for graph and reflog endpoints
Some checks are pending
CI / Rust Lint & Check (push) Waiting to run
CI / Rust Tests (push) Waiting to run
CI / Frontend Lint & Type Check (push) Waiting to run
CI / Frontend Build (push) Blocked by required conditions

- 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)
This commit is contained in:
ZhenYi 2026-04-17 16:36:44 +08:00
parent a4dc507b66
commit afb1bbeb71

View File

@ -1031,6 +1031,15 @@ impl AppService {
) -> Result<Vec<CommitReflogEntryResponse>, 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 -> {