0
0

修复了上传的bug,现在功能是完全的,ui待完善

This commit is contained in:
xubing
2025-11-28 16:54:23 +08:00
parent e2a4b7a80d
commit cd58f6d8ed
7 changed files with 260 additions and 181 deletions

View File

@@ -1628,20 +1628,28 @@ class ConfigPanel {
}, async (progress) => {
try {
progress.report({ increment: 0, message: '检查更改...' });
// 使用命令行 Git 提交并推送
// 使用改进的 Git 提交并推送
await this.commitAndPushUsingCommandLine(fullPath);
progress.report({ increment: 100, message: '完成' });
// 添加上传成功标记
folder.uploaded = true;
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
// 更新 Webview 显示
this.updateWebview();
}
catch (error) {
console.error('❌ Git 上传失败:', error);
vscode.window.showErrorMessage(`Git 仓库上传失败: ${error.message}`);
// 如果是"没有更改"的错误,显示友好提示
if (error.message.includes('没有需要提交的更改')) {
vscode.window.showWarningMessage(`没有检测到更改,无需上传: ${folder.name}`);
}
else {
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
}
}
});
}
/**
* 上传本地模块文件夹到新的 Git 仓库(使用命令行 Git
*/
async uploadLocalModuleFolder(folderId, repoUrl, branchName) {
const folder = this.moduleFolders.find(f => f.id === folderId);
if (!folder || folder.type !== 'local') {
@@ -1678,14 +1686,17 @@ class ConfigPanel {
// 使用命令行 Git 推送到远程仓库
await this.pushToRemoteWithForce(fullPath, branchName);
progress.report({ increment: 100, message: '完成' });
// 更新文件夹类型为 git
// 更新文件夹类型为 git 并标记已上传
folder.type = 'git';
folder.uploaded = true;
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
// 更新 Webview 显示
this.updateWebview();
}
catch (error) {
console.error('❌ 本地文件夹上传失败:', error);
vscode.window.showErrorMessage(`本地文件夹上传失败: ${error}`);
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
// 清理:删除可能创建的 .git 文件夹
try {
const gitDir = path.join(fullPath, '.git');
@@ -1700,7 +1711,7 @@ class ConfigPanel {
});
}
/**
* 使用命令行 Git 初始化仓库
* 使用命令行 Git 初始化仓库(简化版本)
*/
async initGitRepository(fullPath, branchName) {
return new Promise((resolve, reject) => {
@@ -1712,7 +1723,7 @@ class ConfigPanel {
}, (error, stdout, stderr) => {
if (error) {
console.error('❌ Git 初始化失败:', error);
reject(new Error(`Git 初始化失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
console.log('✅ Git 初始化成功');
@@ -1721,7 +1732,7 @@ class ConfigPanel {
});
}
/**
* 使用命令行 Git 添加远程仓库
* 使用命令行 Git 添加远程仓库(简化版本)
*/
async addGitRemote(fullPath, repoUrl) {
return new Promise((resolve, reject) => {
@@ -1733,7 +1744,7 @@ class ConfigPanel {
}, (error, stdout, stderr) => {
if (error) {
console.error('❌ 添加远程仓库失败:', error);
reject(new Error(`添加远程仓库失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
console.log('✅ 远程仓库添加成功');
@@ -1742,7 +1753,7 @@ class ConfigPanel {
});
}
/**
* 使用命令行 Git 提交初始文件
* 使用命令行 Git 提交初始文件(简化版本)
*/
async commitInitialFiles(fullPath) {
return new Promise((resolve, reject) => {
@@ -1764,7 +1775,7 @@ class ConfigPanel {
return;
}
console.error('❌ Git 提交失败:', error);
reject(new Error(`Git 提交失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
console.log('✅ 初始文件提交成功');
@@ -1773,7 +1784,7 @@ class ConfigPanel {
});
}
/**
* 使用命令行 Git 强制推送到远程仓库
* 使用命令行 Git 强制推送到远程仓库(简化版本)
*/
async pushToRemoteWithForce(fullPath, branchName) {
return new Promise((resolve, reject) => {
@@ -1787,18 +1798,7 @@ class ConfigPanel {
console.log('📋 Git push stderr:', stderr);
if (error) {
console.error('❌ Git 推送失败:', error);
// 提供更友好的错误信息
let userMessage = stderr || error.message;
if (stderr.includes('Authentication failed') || stderr.includes('401')) {
userMessage = '认证失败:请确保 Git 凭据已正确配置,或者使用 Personal Access Token';
}
else if (stderr.includes('Permission denied') || stderr.includes('403')) {
userMessage = '权限被拒绝:请检查您是否有权限推送到该仓库';
}
else if (stderr.includes('could not read Username')) {
userMessage = '认证配置问题:请检查 Git 凭据存储配置';
}
reject(new Error(userMessage));
reject(new Error(stderr || error.message));
return;
}
console.log('✅ Git 推送成功');
@@ -1897,53 +1897,75 @@ class ConfigPanel {
});
}
/**
* 使用命令行 Git 提交并推送
* 改进的 Git 提交并推送方法
*/
async commitAndPushUsingCommandLine(fullPath) {
return new Promise((resolve, reject) => {
const { exec } = require('child_process');
console.log('🚀 使用命令行 Git 提交并推送...');
console.log(`📁 工作目录: ${fullPath}`);
// 先添加所有更改并提交,然后推送
const commands = [
'git add .',
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
'git push'
];
exec(commands.join(' && '), {
// 先检查是否有更改
exec('git status --porcelain', {
cwd: fullPath,
encoding: 'utf8'
}, (error, stdout, stderr) => {
console.log('📋 Git 命令输出:', stdout);
console.log('📋 Git 命令错误:', stderr);
if (error) {
// 检查是否是"没有更改可提交"的错误
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
console.log(' 没有需要提交的更改,直接推送');
// 如果没有更改,直接推送
exec('git push', {
cwd: fullPath,
encoding: 'utf8'
}, (pushError, pushStdout, pushStderr) => {
if (pushError) {
console.error('❌ Git push 失败:', pushError);
reject(new Error(`Git 推送失败: ${pushStderr || pushError.message}`));
return;
}
console.log('✅ Git 推送成功');
resolve();
});
return;
}
console.error('❌ Git 提交/推送失败:', error);
reject(new Error(`Git 操作失败: ${stderr || error.message}`));
}, (statusError, statusStdout, statusStderr) => {
if (statusError) {
console.error('❌ 检查 Git 状态失败:', statusError);
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
return;
}
console.log('✅ Git 提交并推送成功');
resolve();
// 如果没有更改
if (!statusStdout.trim()) {
console.log(' 没有需要提交的更改');
reject(new Error('没有需要提交的更改'));
return;
}
console.log('📋 检测到更改:', statusStdout);
// 有更改时才提交并推送
const commands = [
'git add .',
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
'git push'
];
exec(commands.join(' && '), {
cwd: fullPath,
encoding: 'utf8'
}, (error, stdout, stderr) => {
console.log('📋 Git 命令输出:', stdout);
console.log('📋 Git 命令错误:', stderr);
if (error) {
console.error('❌ Git 提交/推送失败:', error);
reject(new Error(stderr || error.message));
return;
}
console.log('✅ Git 提交并推送成功');
resolve();
});
});
});
}
/**
* 简化的推送方法
*/
simplePush(fullPath, resolve, reject) {
const { exec } = require('child_process');
exec('git push', {
cwd: fullPath,
encoding: 'utf8'
}, (pushError, pushStdout, pushStderr) => {
console.log('📋 Git push 输出:', pushStdout);
console.log('📋 Git push 错误:', pushStderr);
if (pushError) {
console.error('❌ Git push 失败');
// 直接使用 Git 的错误信息
reject(new Error(pushStderr || pushError.message));
return;
}
// 只要没有错误就认为是成功
console.log('✅ Git 推送成功');
resolve();
});
}
}
exports.ConfigPanel = ConfigPanel;
//# sourceMappingURL=ConfigPanel.js.map

File diff suppressed because one or more lines are too long

View File

@@ -31,23 +31,26 @@ class ConfigView extends BaseView_1.BaseView {
// 生成模块文件夹的 HTML - 按类别分类显示
const moduleFoldersHtml = moduleFolders.map((folder) => {
const icon = folder.type === 'git' ? '📁' : '📁';
// 根据类型确定类别显示
const category = folder.type === 'git' ? 'git' : 'local';
// 根据类型和上传状态确定类别显示
let category = folder.type === 'git' ? 'git' : 'local';
if (folder.uploaded) {
category += '(已上传)';
}
return `
<tr>
<td>
<span class="editable">${icon} ${folder.name}</span>
</td>
<td>${category}</td>
<td>
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
</td>
<td>
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
</td>
</tr>
`;
<tr>
<td>
<span class="editable">${icon} ${folder.name}</span>
</td>
<td class="category-${folder.type}">${category}</td>
<td>
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
</td>
<td>
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
</td>
</tr>
`;
}).join('');
// 生成分支选择的 HTML - 使用树状结构
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
@@ -234,15 +237,25 @@ class ConfigView extends BaseView_1.BaseView {
}
/* 类别标签样式 */
.category-git {
color: var(--vscode-gitDecoration-untrackedResourceForeground);
font-weight: bold;
}
.category-local {
color: var(--vscode-charts-orange);
font-weight: bold;
}
.category-git {
color: var(--vscode-gitDecoration-untrackedResourceForeground);
font-weight: bold;
}
.category-local {
color: var(--vscode-charts-orange);
font-weight: bold;
}
.category-git已上传 {
color: var(--vscode-gitDecoration-addedResourceForeground);
font-weight: bold;
}
.category-local已上传 {
color: var(--vscode-gitDecoration-addedResourceForeground);
font-weight: bold;
}
</style>
</head>
<body>

File diff suppressed because one or more lines are too long

View File

@@ -1942,23 +1942,33 @@ private async uploadGitModuleFolder(folderId: string, username: string, password
try {
progress.report({ increment: 0, message: '检查更改...' });
// 使用命令行 Git 提交并推送
// 使用改进的 Git 提交并推送
await this.commitAndPushUsingCommandLine(fullPath);
progress.report({ increment: 100, message: '完成' });
// 添加上传成功标记
folder.uploaded = true;
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
// 更新 Webview 显示
this.updateWebview();
} catch (error) {
console.error('❌ Git 上传失败:', error);
vscode.window.showErrorMessage(`Git 仓库上传失败: ${error.message}`);
// 如果是"没有更改"的错误,显示友好提示
if (error.message.includes('没有需要提交的更改')) {
vscode.window.showWarningMessage(`没有检测到更改,无需上传: ${folder.name}`);
} else {
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
}
}
});
}
/**
* 上传本地模块文件夹到新的 Git 仓库(使用命令行 Git
*/
private async uploadLocalModuleFolder(folderId: string, repoUrl: string, branchName: string): Promise<void> {
const folder = this.moduleFolders.find(f => f.id === folderId);
if (!folder || folder.type !== 'local') {
@@ -2008,15 +2018,19 @@ private async uploadLocalModuleFolder(folderId: string, repoUrl: string, branchN
progress.report({ increment: 100, message: '完成' });
// 更新文件夹类型为 git
// 更新文件夹类型为 git 并标记已上传
folder.type = 'git';
folder.uploaded = true;
await this.saveCurrentProjectData();
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
// 更新 Webview 显示
this.updateWebview();
} catch (error) {
console.error('❌ 本地文件夹上传失败:', error);
vscode.window.showErrorMessage(`本地文件夹上传失败: ${error}`);
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
// 清理:删除可能创建的 .git 文件夹
try {
@@ -2032,7 +2046,7 @@ private async uploadLocalModuleFolder(folderId: string, repoUrl: string, branchN
}
/**
* 使用命令行 Git 初始化仓库
* 使用命令行 Git 初始化仓库(简化版本)
*/
private async initGitRepository(fullPath: string, branchName: string): Promise<void> {
return new Promise((resolve, reject) => {
@@ -2046,7 +2060,7 @@ private async initGitRepository(fullPath: string, branchName: string): Promise<v
}, (error, stdout, stderr) => {
if (error) {
console.error('❌ Git 初始化失败:', error);
reject(new Error(`Git 初始化失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
@@ -2057,7 +2071,7 @@ private async initGitRepository(fullPath: string, branchName: string): Promise<v
}
/**
* 使用命令行 Git 添加远程仓库
* 使用命令行 Git 添加远程仓库(简化版本)
*/
private async addGitRemote(fullPath: string, repoUrl: string): Promise<void> {
return new Promise((resolve, reject) => {
@@ -2071,7 +2085,7 @@ private async addGitRemote(fullPath: string, repoUrl: string): Promise<void> {
}, (error, stdout, stderr) => {
if (error) {
console.error('❌ 添加远程仓库失败:', error);
reject(new Error(`添加远程仓库失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
@@ -2082,7 +2096,7 @@ private async addGitRemote(fullPath: string, repoUrl: string): Promise<void> {
}
/**
* 使用命令行 Git 提交初始文件
* 使用命令行 Git 提交初始文件(简化版本)
*/
private async commitInitialFiles(fullPath: string): Promise<void> {
return new Promise((resolve, reject) => {
@@ -2108,7 +2122,7 @@ private async commitInitialFiles(fullPath: string): Promise<void> {
}
console.error('❌ Git 提交失败:', error);
reject(new Error(`Git 提交失败: ${stderr || error.message}`));
reject(new Error(stderr || error.message));
return;
}
@@ -2119,7 +2133,7 @@ private async commitInitialFiles(fullPath: string): Promise<void> {
}
/**
* 使用命令行 Git 强制推送到远程仓库
* 使用命令行 Git 强制推送到远程仓库(简化版本)
*/
private async pushToRemoteWithForce(fullPath: string, branchName: string): Promise<void> {
return new Promise((resolve, reject) => {
@@ -2136,19 +2150,7 @@ private async pushToRemoteWithForce(fullPath: string, branchName: string): Promi
if (error) {
console.error('❌ Git 推送失败:', error);
// 提供更友好的错误信息
let userMessage = stderr || error.message;
if (stderr.includes('Authentication failed') || stderr.includes('401')) {
userMessage = '认证失败:请确保 Git 凭据已正确配置,或者使用 Personal Access Token';
} else if (stderr.includes('Permission denied') || stderr.includes('403')) {
userMessage = '权限被拒绝:请检查您是否有权限推送到该仓库';
} else if (stderr.includes('could not read Username')) {
userMessage = '认证配置问题:请检查 Git 凭据存储配置';
}
reject(new Error(userMessage));
reject(new Error(stderr || error.message));
return;
}
@@ -2259,7 +2261,7 @@ private async checkGitRemote(fullPath: string): Promise<void> {
}
/**
* 使用命令行 Git 提交并推送
* 改进的 Git 提交并推送方法
*/
private async commitAndPushUsingCommandLine(fullPath: string): Promise<void> {
return new Promise((resolve, reject) => {
@@ -2268,49 +2270,77 @@ private async commitAndPushUsingCommandLine(fullPath: string): Promise<void> {
console.log('🚀 使用命令行 Git 提交并推送...');
console.log(`📁 工作目录: ${fullPath}`);
// 先添加所有更改并提交,然后推送
const commands = [
'git add .',
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
'git push'
];
exec(commands.join(' && '), {
// 先检查是否有更改
exec('git status --porcelain', {
cwd: fullPath,
encoding: 'utf8'
}, (error, stdout, stderr) => {
console.log('📋 Git 命令输出:', stdout);
console.log('📋 Git 命令错误:', stderr);
if (error) {
// 检查是否是"没有更改可提交"的错误
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
console.log(' 没有需要提交的更改,直接推送');
// 如果没有更改,直接推送
exec('git push', {
cwd: fullPath,
encoding: 'utf8'
}, (pushError, pushStdout, pushStderr) => {
if (pushError) {
console.error('❌ Git push 失败:', pushError);
reject(new Error(`Git 推送失败: ${pushStderr || pushError.message}`));
return;
}
console.log('✅ Git 推送成功');
resolve();
});
return;
}
console.error('❌ Git 提交/推送失败:', error);
reject(new Error(`Git 操作失败: ${stderr || error.message}`));
}, (statusError, statusStdout, statusStderr) => {
if (statusError) {
console.error('❌ 检查 Git 状态失败:', statusError);
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
return;
}
console.log('✅ Git 提交并推送成功');
resolve();
// 如果没有更改
if (!statusStdout.trim()) {
console.log(' 没有需要提交的更改');
reject(new Error('没有需要提交的更改'));
return;
}
console.log('📋 检测到更改:', statusStdout);
// 有更改时才提交并推送
const commands = [
'git add .',
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
'git push'
];
exec(commands.join(' && '), {
cwd: fullPath,
encoding: 'utf8'
}, (error, stdout, stderr) => {
console.log('📋 Git 命令输出:', stdout);
console.log('📋 Git 命令错误:', stderr);
if (error) {
console.error('❌ Git 提交/推送失败:', error);
reject(new Error(stderr || error.message));
return;
}
console.log('✅ Git 提交并推送成功');
resolve();
});
});
});
}
/**
* 简化的推送方法
*/
private simplePush(fullPath: string, resolve: any, reject: any): void {
const { exec } = require('child_process');
exec('git push', {
cwd: fullPath,
encoding: 'utf8'
}, (pushError, pushStdout, pushStderr) => {
console.log('📋 Git push 输出:', pushStdout);
console.log('📋 Git push 错误:', pushStderr);
if (pushError) {
console.error('❌ Git push 失败');
// 直接使用 Git 的错误信息
reject(new Error(pushStderr || pushError.message));
return;
}
// 只要没有错误就认为是成功
console.log('✅ Git 推送成功');
resolve();
});
}
}

View File

@@ -34,6 +34,7 @@ export interface ModuleFolder {
type: 'git' | 'local';
localPath: string;
containerId: string;
uploaded?: boolean;
}
// 完整数据模型接口

View File

@@ -74,27 +74,30 @@ export class ConfigView extends BaseView {
`).join('');
// 生成模块文件夹的 HTML - 按类别分类显示
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
const icon = folder.type === 'git' ? '📁' : '📁';
// 根据类型确定类别显示
const category = folder.type === 'git' ? 'git' : 'local';
return `
<tr>
<td>
<span class="editable">${icon} ${folder.name}</span>
</td>
<td>${category}</td>
<td>
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
</td>
<td>
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
</td>
</tr>
`;
}).join('');
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
const icon = folder.type === 'git' ? '📁' : '📁';
// 根据类型和上传状态确定类别显示
let category = folder.type === 'git' ? 'git' : 'local';
if (folder.uploaded) {
category += '(已上传)';
}
return `
<tr>
<td>
<span class="editable">${icon} ${folder.name}</span>
</td>
<td class="category-${folder.type}">${category}</td>
<td>
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
</td>
<td>
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
</td>
</tr>
`;
}).join('');
// 生成分支选择的 HTML - 使用树状结构
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
@@ -282,15 +285,25 @@ export class ConfigView extends BaseView {
}
/* 类别标签样式 */
.category-git {
color: var(--vscode-gitDecoration-untrackedResourceForeground);
font-weight: bold;
}
.category-local {
color: var(--vscode-charts-orange);
font-weight: bold;
}
.category-git {
color: var(--vscode-gitDecoration-untrackedResourceForeground);
font-weight: bold;
}
.category-local {
color: var(--vscode-charts-orange);
font-weight: bold;
}
.category-git已上传 {
color: var(--vscode-gitDecoration-addedResourceForeground);
font-weight: bold;
}
.category-local已上传 {
color: var(--vscode-gitDecoration-addedResourceForeground);
font-weight: bold;
}
</style>
</head>
<body>