git功能已完备
This commit is contained in:
@@ -214,6 +214,9 @@ class ConfigPanel {
|
||||
case 'importGitFile':
|
||||
await this.importGitFile(data.filePath);
|
||||
break;
|
||||
case 'openGitRepoInVSCode':
|
||||
await this.openGitRepoInVSCode(data.repoId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -1186,17 +1189,25 @@ class ConfigPanel {
|
||||
// 过滤出分支引用 (refs/heads/ 和 refs/remotes/origin/)
|
||||
const branchRefs = refs.filter(ref => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
|
||||
console.log('🌿 过滤后的分支引用:', branchRefs);
|
||||
// 构建分支数据
|
||||
// 构建分支数据 - 修复分支名称显示
|
||||
const branches = branchRefs.map(ref => {
|
||||
const isRemote = ref.ref.startsWith('refs/remotes/');
|
||||
const branchName = isRemote
|
||||
? ref.ref.replace('refs/remotes/origin/', '')
|
||||
: ref.ref.replace('refs/heads/', '');
|
||||
let branchName;
|
||||
if (isRemote) {
|
||||
// 远程分支:移除 refs/remotes/origin/ 前缀
|
||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||
// 可以选择添加远程标识,或者不添加
|
||||
// branchName = `origin/${branchName}`; // 如果需要显示远程标识
|
||||
}
|
||||
else {
|
||||
// 本地分支:移除 refs/heads/ 前缀
|
||||
branchName = ref.ref.replace('refs/heads/', '');
|
||||
}
|
||||
return {
|
||||
name: branchName,
|
||||
isCurrent: branchName === 'main' || branchName === 'master',
|
||||
isRemote: isRemote,
|
||||
selected: branchName === 'main' || branchName === 'master'
|
||||
selected: false // 所有分支默认不选中
|
||||
};
|
||||
});
|
||||
console.log('🎯 最终分支列表:', branches);
|
||||
@@ -1219,7 +1230,7 @@ class ConfigPanel {
|
||||
// 如果方法失败,使用模拟数据
|
||||
console.log('🔄 使用模拟分支数据');
|
||||
const mockBranches = [
|
||||
{ name: 'main', isCurrent: true, isRemote: false, selected: true },
|
||||
{ name: 'main', isCurrent: true, isRemote: false, selected: false },
|
||||
{ name: 'master', isCurrent: false, isRemote: false, selected: false },
|
||||
{ name: 'develop', isCurrent: false, isRemote: false, selected: false },
|
||||
{ name: 'feature/new-feature', isCurrent: false, isRemote: false, selected: false }
|
||||
@@ -1328,6 +1339,38 @@ class ConfigPanel {
|
||||
});
|
||||
}
|
||||
}
|
||||
async openGitRepoInVSCode(repoId) {
|
||||
const repo = this.gitRepos.find(r => r.id === repoId);
|
||||
if (!repo) {
|
||||
vscode.window.showErrorMessage('未找到指定的 Git 仓库');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 检查仓库目录是否存在
|
||||
if (!fs.existsSync(repo.localPath)) {
|
||||
vscode.window.showErrorMessage('Git 仓库目录不存在,请重新克隆');
|
||||
return;
|
||||
}
|
||||
// 使用 VSCode 的文件选择器让用户选择要打开的文件
|
||||
const fileUri = await vscode.window.showOpenDialog({
|
||||
defaultUri: vscode.Uri.file(repo.localPath),
|
||||
canSelectFiles: true,
|
||||
canSelectFolders: false,
|
||||
canSelectMany: false,
|
||||
openLabel: '选择要打开的文件',
|
||||
title: `在 ${repo.name} 中选择文件`
|
||||
});
|
||||
if (fileUri && fileUri.length > 0) {
|
||||
// 打开选中的文件
|
||||
const document = await vscode.workspace.openTextDocument(fileUri[0]);
|
||||
await vscode.window.showTextDocument(document);
|
||||
vscode.window.showInformationMessage(`已打开文件: ${path.basename(fileUri[0].fsPath)}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
vscode.window.showErrorMessage(`打开 Git 仓库文件失败: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ConfigPanel = ConfigPanel;
|
||||
//# sourceMappingURL=ConfigPanel.js.map
|
||||
Reference in New Issue
Block a user