fix: 仓库页面 ref 选择器填充最近提交

This commit is contained in:
2026-06-19 22:40:19 +08:00
parent 96c4e7d88a
commit c4e0ef33ab
+12 -4
View File
@@ -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;