0
0

新增git分支显示功能

This commit is contained in:
xubing
2025-11-27 18:34:57 +08:00
parent fecbcdc59b
commit 9f44664b0b
6 changed files with 749 additions and 167 deletions

View File

@@ -1086,9 +1086,8 @@ class ConfigPanel {
console.log('🌿 过滤后的分支引用:', branchRefs);
// 构建分支数据 - 修复分支名称显示
const branches = branchRefs.map(ref => {
const isRemote = ref.ref.startsWith('refs/remotes/');
let branchName;
if (isRemote) {
if (ref.ref.startsWith('refs/remotes/')) {
// 远程分支:移除 refs/remotes/origin/ 前缀
branchName = ref.ref.replace('refs/remotes/origin/', '');
}
@@ -1099,7 +1098,6 @@ class ConfigPanel {
return {
name: branchName,
isCurrent: branchName === 'main' || branchName === 'master',
isRemote: isRemote,
selected: false // 所有分支默认不选中
};
});
@@ -1108,11 +1106,15 @@ class ConfigPanel {
throw new Error('未找到任何分支');
}
progress.report({ increment: 80, message: '处理分支数据...' });
// 发送分支数据到前端
// === 新增:构建分支树状结构 ===
const branchTree = this.buildBranchTree(branches);
console.log('🌳 构建的分支树结构:', branchTree);
// 发送分支数据到前端 - 同时包含扁平列表和树状结构
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: branches,
branchTree: branchTree,
repoUrl: url
});
}
@@ -1130,6 +1132,39 @@ class ConfigPanel {
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
}
}
/**
* 构建分支树状结构
*/
buildBranchTree(branches) {
const root = [];
branches.forEach(branch => {
const parts = branch.name.split('/');
let currentLevel = root;
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
const isLeaf = i === parts.length - 1;
const fullName = parts.slice(0, i + 1).join('/');
let node = currentLevel.find((n) => n.name === part);
if (!node) {
node = {
name: part,
fullName: fullName,
isLeaf: isLeaf,
children: [],
level: i,
expanded: true // 默认展开
};
currentLevel.push(node);
}
if (isLeaf) {
// 叶子节点存储分支信息
node.branch = branch;
}
currentLevel = node.children;
}
});
return root;
}
async cloneBranches(url, branches) {
try {
console.log('🚀 开始克隆分支:', { url, branches });