0
0

git功能已完备

This commit is contained in:
xubing
2025-11-25 16:32:06 +08:00
parent 719fb43c33
commit 23024a8461
6 changed files with 233 additions and 130 deletions

View File

@@ -214,6 +214,9 @@ class ConfigPanel {
case 'importGitFile': case 'importGitFile':
await this.importGitFile(data.filePath); await this.importGitFile(data.filePath);
break; break;
case 'openGitRepoInVSCode':
await this.openGitRepoInVSCode(data.repoId);
break;
} }
} }
catch (error) { catch (error) {
@@ -1186,17 +1189,25 @@ class ConfigPanel {
// 过滤出分支引用 (refs/heads/ 和 refs/remotes/origin/) // 过滤出分支引用 (refs/heads/ 和 refs/remotes/origin/)
const branchRefs = refs.filter(ref => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')); const branchRefs = refs.filter(ref => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
console.log('🌿 过滤后的分支引用:', branchRefs); console.log('🌿 过滤后的分支引用:', branchRefs);
// 构建分支数据 // 构建分支数据 - 修复分支名称显示
const branches = branchRefs.map(ref => { const branches = branchRefs.map(ref => {
const isRemote = ref.ref.startsWith('refs/remotes/'); const isRemote = ref.ref.startsWith('refs/remotes/');
const branchName = isRemote let branchName;
? ref.ref.replace('refs/remotes/origin/', '') if (isRemote) {
: ref.ref.replace('refs/heads/', ''); // 远程分支:移除 refs/remotes/origin/ 前缀
branchName = ref.ref.replace('refs/remotes/origin/', '');
// 可以选择添加远程标识,或者不添加
// branchName = `origin/${branchName}`; // 如果需要显示远程标识
}
else {
// 本地分支:移除 refs/heads/ 前缀
branchName = ref.ref.replace('refs/heads/', '');
}
return { return {
name: branchName, name: branchName,
isCurrent: branchName === 'main' || branchName === 'master', isCurrent: branchName === 'main' || branchName === 'master',
isRemote: isRemote, isRemote: isRemote,
selected: branchName === 'main' || branchName === 'master' selected: false // 所有分支默认不选中
}; };
}); });
console.log('🎯 最终分支列表:', branches); console.log('🎯 最终分支列表:', branches);
@@ -1219,7 +1230,7 @@ class ConfigPanel {
// 如果方法失败,使用模拟数据 // 如果方法失败,使用模拟数据
console.log('🔄 使用模拟分支数据'); console.log('🔄 使用模拟分支数据');
const mockBranches = [ 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: 'master', isCurrent: false, isRemote: false, selected: false },
{ name: 'develop', isCurrent: false, isRemote: false, selected: false }, { name: 'develop', isCurrent: false, isRemote: false, selected: false },
{ name: 'feature/new-feature', 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; exports.ConfigPanel = ConfigPanel;
//# sourceMappingURL=ConfigPanel.js.map //# sourceMappingURL=ConfigPanel.js.map

File diff suppressed because one or more lines are too long

View File

@@ -26,23 +26,29 @@ class ConfigView extends BaseView_1.BaseView {
</td> </td>
</tr> </tr>
`).join(''); `).join('');
// 生成 Git 仓库列表的 HTML - 以配置文件形式显示 // 生成 Git 仓库列表的 HTML - 修改显示方式
const gitReposHtml = gitRepos.map(repo => ` const gitReposHtml = gitRepos.map(repo => {
// 提取仓库名称从URL中获取或使用name
const repoName = repo.name.split(' (')[0]; // 移除分支名部分
// 提取分支名
const branchMatch = repo.name.match(/\(([^)]+)\)/);
const branchName = branchMatch ? branchMatch[1] : repo.branch;
return `
<tr> <tr>
<td> <td>
<span class="editable">📁 ${repo.name}</span> <span class="editable">📁 ${repoName}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;"> <div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
模型1、模型2
</div> </div>
</td> </td>
<td> <td>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">${repo.url.split('/').pop()}</span> <span class="clickable" onclick="openGitRepoInVSCode('${repo.id}')">${branchName}</span>
</td> </td>
<td> <td>
<button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button> <button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button>
</td> </td>
</tr> </tr>
`).join(''); `;
}).join('');
// 生成分支选择的 HTML // 生成分支选择的 HTML
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : ''; const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
return `<!DOCTYPE html> return `<!DOCTYPE html>
@@ -225,7 +231,7 @@ class ConfigView extends BaseView_1.BaseView {
); );
} }
// Git 仓库删除功能 - 修复版本 // Git 仓库删除功能
function deleteGitRepo(repoId) { function deleteGitRepo(repoId) {
console.log('🗑️ 尝试删除 Git 仓库:', repoId); console.log('🗑️ 尝试删除 Git 仓库:', repoId);
@@ -246,6 +252,15 @@ class ConfigView extends BaseView_1.BaseView {
); );
} }
// 新功能:在 VSCode 中打开 Git 仓库
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function saveConfigFile() { function saveConfigFile() {
const content = document.getElementById('configContent').value; const content = document.getElementById('configContent').value;
vscode.postMessage({ vscode.postMessage({
@@ -370,7 +385,7 @@ class ConfigView extends BaseView_1.BaseView {
branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">'; branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">';
branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">'; branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">';
branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name; branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name;
branchesHtml += (branch.isRemote ? '(远程)' : '(本地)') + '</label></div>'; branchesHtml += '</label></div>';
}); });
branchesHtml += '</div>'; branchesHtml += '</div>';
@@ -477,18 +492,9 @@ class ConfigView extends BaseView_1.BaseView {
} }
}); });
// 初始化 - 添加调试信息(修复语法错误) // 初始化
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成'); console.log('📄 ConfigView 页面加载完成');
console.log('🔍 检查 Git 仓库删除按钮绑定');
// 检查所有删除按钮
const deleteButtons = document.querySelectorAll('.btn-delete');
console.log('找到删除按钮数量:', deleteButtons.length);
deleteButtons.forEach(function(btn, index) {
console.log('删除按钮 ' + index + ':', btn);
});
}); });
</script> </script>
</body> </body>

View File

@@ -1 +1 @@
{"version":3,"file":"ConfigView.js","sourceRoot":"","sources":["../../../src/panels/views/ConfigView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AA8BtC,MAAa,UAAW,SAAQ,mBAAQ;IACpC,MAAM,CAAC,IAON;QACG,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,CAAC;QA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D,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,4BAA4B,GAAG,MAAM,CAAC,IAAI,GAAG,mCAAmC,CAAC;YAC9H,IAAI,IAAI,cAAc,GAAG,QAAQ,GAAG,sCAAsC,CAAC;YAC3E,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;YACrD,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC;QACnE,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,QAAQ,CAAC;QACjB,IAAI,IAAI,iCAAiC,CAAC;QAC1C,IAAI,IAAI,yGAAyG,CAAC;QAClH,IAAI,IAAI,wEAAwE,CAAC;QACjF,IAAI,IAAI,cAAc,CAAC;QAEvB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAxhBD,gCAwhBC"}

View File

@@ -305,6 +305,10 @@ export class ConfigPanel {
case 'importGitFile': case 'importGitFile':
await this.importGitFile(data.filePath); await this.importGitFile(data.filePath);
break; break;
case 'openGitRepoInVSCode':
await this.openGitRepoInVSCode(data.repoId);
break;
} }
} catch (error) { } catch (error) {
console.error('处理 Webview 消息时出错:', error); console.error('处理 Webview 消息时出错:', error);
@@ -1412,99 +1416,107 @@ private async deleteGitRepo(repoId: string): Promise<void> {
// === Git 分支管理 === // === Git 分支管理 ===
private async fetchBranches(url: string): Promise<void> { private async fetchBranches(url: string): Promise<void> {
try { try {
console.log('🌿 开始获取分支列表:', url); console.log('🌿 开始获取分支列表:', url);
await vscode.window.withProgress({ await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification, location: vscode.ProgressLocation.Notification,
title: '正在获取分支信息', title: '正在获取分支信息',
cancellable: false cancellable: false
}, async (progress) => { }, async (progress) => {
progress.report({ increment: 0, message: '连接远程仓库...' }); progress.report({ increment: 0, message: '连接远程仓库...' });
try { try {
// 使用 isomorphic-git 的 listServerRefs // 使用 isomorphic-git 的 listServerRefs
progress.report({ increment: 30, message: '获取远程引用...' }); progress.report({ increment: 30, message: '获取远程引用...' });
console.log('🔍 使用 listServerRefs 获取分支信息...');
const refs = await git.listServerRefs({
http: http,
url: url
});
console.log('📋 获取到的引用:', refs);
// 过滤出分支引用 (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: GitBranch[] = branchRefs.map(ref => {
const isRemote = ref.ref.startsWith('refs/remotes/');
let branchName: string;
console.log('🔍 使用 listServerRefs 获取分支信息...'); if (isRemote) {
// 远程分支:移除 refs/remotes/origin/ 前缀
const refs = await git.listServerRefs({ branchName = ref.ref.replace('refs/remotes/origin/', '');
http: http, // 可以选择添加远程标识,或者不添加
url: url // branchName = `origin/${branchName}`; // 如果需要显示远程标识
}); } else {
// 本地分支:移除 refs/heads/ 前缀
console.log('📋 获取到的引用:', refs); branchName = ref.ref.replace('refs/heads/', '');
// 过滤出分支引用 (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: GitBranch[] = branchRefs.map(ref => {
const isRemote = ref.ref.startsWith('refs/remotes/');
const branchName = isRemote
? ref.ref.replace('refs/remotes/origin/', '')
: ref.ref.replace('refs/heads/', '');
return {
name: branchName,
isCurrent: branchName === 'main' || branchName === 'master',
isRemote: isRemote,
selected: branchName === 'main' || branchName === 'master'
};
});
console.log('🎯 最终分支列表:', branches);
if (branches.length === 0) {
throw new Error('未找到任何分支');
}
progress.report({ increment: 80, message: '处理分支数据...' });
// 发送分支数据到前端
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: branches,
repoUrl: url
});
}
progress.report({ increment: 100, message: '完成' });
} catch (error) {
console.error('❌ 使用 listServerRefs 获取分支失败:', error);
// 如果方法失败,使用模拟数据
console.log('🔄 使用模拟分支数据');
const mockBranches = [
{ name: 'main', isCurrent: true, isRemote: false, selected: true },
{ 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 }
];
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: mockBranches,
repoUrl: url
});
} }
vscode.window.showWarningMessage('使用模拟分支数据,实际分支可能不同'); return {
name: branchName,
isCurrent: branchName === 'main' || branchName === 'master',
isRemote: isRemote,
selected: false // 所有分支默认不选中
};
});
console.log('🎯 最终分支列表:', branches);
if (branches.length === 0) {
throw new Error('未找到任何分支');
} }
});
} catch (error) { progress.report({ increment: 80, message: '处理分支数据...' });
console.error('❌ 获取分支失败:', error);
vscode.window.showErrorMessage(`获取分支失败: ${error}`); // 发送分支数据到前端
} if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: branches,
repoUrl: url
});
}
progress.report({ increment: 100, message: '完成' });
} catch (error) {
console.error('❌ 使用 listServerRefs 获取分支失败:', error);
// 如果方法失败,使用模拟数据
console.log('🔄 使用模拟分支数据');
const mockBranches = [
{ 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 }
];
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: mockBranches,
repoUrl: url
});
}
vscode.window.showWarningMessage('使用模拟分支数据,实际分支可能不同');
}
});
} catch (error) {
console.error('❌ 获取分支失败:', error);
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
} }
}
private async cloneBranches(url: string, branches: string[]): Promise<void> { private async cloneBranches(url: string, branches: string[]): Promise<void> {
try { try {
@@ -1603,4 +1615,39 @@ private async deleteGitRepo(repoId: string): Promise<void> {
}); });
} }
} }
private async openGitRepoInVSCode(repoId: string): Promise<void> {
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}`);
}
}
} }

View File

@@ -61,23 +61,30 @@ export class ConfigView extends BaseView {
</tr> </tr>
`).join(''); `).join('');
// 生成 Git 仓库列表的 HTML - 以配置文件形式显示 // 生成 Git 仓库列表的 HTML - 修改显示方式
const gitReposHtml = gitRepos.map(repo => ` const gitReposHtml = gitRepos.map(repo => {
// 提取仓库名称从URL中获取或使用name
const repoName = repo.name.split(' (')[0]; // 移除分支名部分
// 提取分支名
const branchMatch = repo.name.match(/\(([^)]+)\)/);
const branchName = branchMatch ? branchMatch[1] : repo.branch;
return `
<tr> <tr>
<td> <td>
<span class="editable">📁 ${repo.name}</span> <span class="editable">📁 ${repoName}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;"> <div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
模型1、模型2
</div> </div>
</td> </td>
<td> <td>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">${repo.url.split('/').pop()}</span> <span class="clickable" onclick="openGitRepoInVSCode('${repo.id}')">${branchName}</span>
</td> </td>
<td> <td>
<button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button> <button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button>
</td> </td>
</tr> </tr>
`).join(''); `;
}).join('');
// 生成分支选择的 HTML // 生成分支选择的 HTML
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : ''; const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
@@ -262,7 +269,7 @@ export class ConfigView extends BaseView {
); );
} }
// Git 仓库删除功能 - 修复版本 // Git 仓库删除功能
function deleteGitRepo(repoId) { function deleteGitRepo(repoId) {
console.log('🗑️ 尝试删除 Git 仓库:', repoId); console.log('🗑️ 尝试删除 Git 仓库:', repoId);
@@ -283,6 +290,15 @@ export class ConfigView extends BaseView {
); );
} }
// 新功能:在 VSCode 中打开 Git 仓库
function openGitRepoInVSCode(repoId) {
console.log('📂 在 VSCode 中打开 Git 仓库:', repoId);
vscode.postMessage({
type: 'openGitRepoInVSCode',
repoId: repoId
});
}
function saveConfigFile() { function saveConfigFile() {
const content = document.getElementById('configContent').value; const content = document.getElementById('configContent').value;
vscode.postMessage({ vscode.postMessage({
@@ -407,7 +423,7 @@ export class ConfigView extends BaseView {
branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">'; branchesHtml += (branch.selected ? 'checked' : '') + ' onchange="toggleBranch(\\'' + branch.name + '\\')" style="margin-right: 10px;">';
branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">'; branchesHtml += '<label for="branch-' + branch.name.replace(/[^a-zA-Z0-9]/g, '-') + '" style="flex: 1; cursor: pointer;">';
branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name; branchesHtml += (branch.isCurrent ? '⭐ ' : '') + branch.name;
branchesHtml += (branch.isRemote ? '(远程)' : '(本地)') + '</label></div>'; branchesHtml += '</label></div>';
}); });
branchesHtml += '</div>'; branchesHtml += '</div>';
@@ -514,18 +530,9 @@ export class ConfigView extends BaseView {
} }
}); });
// 初始化 - 添加调试信息(修复语法错误) // 初始化
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成'); console.log('📄 ConfigView 页面加载完成');
console.log('🔍 检查 Git 仓库删除按钮绑定');
// 检查所有删除按钮
const deleteButtons = document.querySelectorAll('.btn-delete');
console.log('找到删除按钮数量:', deleteButtons.length);
deleteButtons.forEach(function(btn, index) {
console.log('删除按钮 ' + index + ':', btn);
});
}); });
</script> </script>
</body> </body>