diff --git a/templates/pages/repo.html b/templates/pages/repo.html index daefca7..a178a1f 100644 --- a/templates/pages/repo.html +++ b/templates/pages/repo.html @@ -168,7 +168,15 @@ const refsResp = await fetch(`/api/repos/${repoId}/refs`); if (refsResp.ok) { currentRefs = await refsResp.json(); - populateRefSelects(currentRefs); + + // Fetch recent commits independently + let commits = []; + try { + const graphResp = await fetch(`/api/repos/${repoId}/graph?max_commits=20`); + if (graphResp.ok) commits = await graphResp.json(); + } catch (e) { /* ignore */ } + + populateRefSelects(currentRefs, commits); updateButtonLinks(); } @@ -195,7 +203,7 @@ document.getElementById('error-message').textContent = message; } - function populateRefSelects(refs) { + function populateRefSelects(refs, commits) { const selects = ['select-base', 'select-head']; const branches = refs.filter(r => !r.is_tag); const tags = refs.filter(r => r.is_tag); @@ -231,10 +239,10 @@ } // Add "Recent Commits" group - if (GitGraph.commits && GitGraph.commits.length > 0) { + if (commits && commits.length > 0) { const group = document.createElement('optgroup'); group.label = '最近提交'; - GitGraph.commits.slice(0, 20).forEach(commit => { + commits.forEach(commit => { const opt = document.createElement('option'); opt.value = commit.hash; opt.dataset.hash = commit.hash;