添加了代码上传功能,但是存在bug待修复
This commit is contained in:
@@ -226,6 +226,12 @@ class ConfigPanel {
|
||||
case 'openTheModuleFolder':
|
||||
await this.openTheModuleFolder(data.moduleType, data.id);
|
||||
break;
|
||||
case 'uploadGitModuleFolder':
|
||||
await this.uploadGitModuleFolder(data.folderId, data.username, data.password);
|
||||
break;
|
||||
case 'uploadLocalModuleFolder':
|
||||
await this.uploadLocalModuleFolder(data.folderId, data.repoUrl, data.branchName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -1603,6 +1609,341 @@ class ConfigPanel {
|
||||
const folderName = pathParts[pathParts.length - 1];
|
||||
return path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
}
|
||||
async uploadGitModuleFolder(folderId, username, password) {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder || folder.type !== 'git') {
|
||||
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
||||
return;
|
||||
}
|
||||
// 获取完整路径
|
||||
const fullPath = this.getModuleFolderFullPath(folder);
|
||||
if (!fullPath) {
|
||||
vscode.window.showErrorMessage('无法获取模块文件夹的完整路径');
|
||||
return;
|
||||
}
|
||||
await vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: `正在上传 Git 仓库: ${folder.name}`,
|
||||
cancellable: false
|
||||
}, async (progress) => {
|
||||
try {
|
||||
progress.report({ increment: 0, message: '检查更改...' });
|
||||
// 使用命令行 Git 提交并推送
|
||||
await this.commitAndPushUsingCommandLine(fullPath);
|
||||
progress.report({ increment: 100, message: '完成' });
|
||||
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ Git 上传失败:', error);
|
||||
vscode.window.showErrorMessage(`Git 仓库上传失败: ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 上传本地模块文件夹到新的 Git 仓库(使用命令行 Git)
|
||||
*/
|
||||
async uploadLocalModuleFolder(folderId, repoUrl, branchName) {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder || folder.type !== 'local') {
|
||||
vscode.window.showErrorMessage('未找到指定的本地模块文件夹');
|
||||
return;
|
||||
}
|
||||
// 获取完整路径
|
||||
const fullPath = this.getModuleFolderFullPath(folder);
|
||||
if (!fullPath) {
|
||||
vscode.window.showErrorMessage('无法获取模块文件夹的完整路径');
|
||||
return;
|
||||
}
|
||||
await vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: `正在上传本地文件夹到 Git 仓库: ${folder.name}`,
|
||||
cancellable: false
|
||||
}, async (progress) => {
|
||||
try {
|
||||
progress.report({ increment: 0, message: '检查目录...' });
|
||||
// 检查目录是否存在
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
throw new Error('本地文件夹不存在');
|
||||
}
|
||||
progress.report({ increment: 10, message: '初始化 Git 仓库...' });
|
||||
// 使用命令行 Git 初始化仓库
|
||||
await this.initGitRepository(fullPath, branchName);
|
||||
progress.report({ increment: 20, message: '添加远程仓库...' });
|
||||
// 使用命令行 Git 添加远程仓库
|
||||
await this.addGitRemote(fullPath, repoUrl);
|
||||
progress.report({ increment: 40, message: '提交初始文件...' });
|
||||
// 使用命令行 Git 提交初始文件
|
||||
await this.commitInitialFiles(fullPath);
|
||||
progress.report({ increment: 60, message: '推送到远程仓库...' });
|
||||
// 使用命令行 Git 推送到远程仓库
|
||||
await this.pushToRemoteWithForce(fullPath, branchName);
|
||||
progress.report({ increment: 100, message: '完成' });
|
||||
// 更新文件夹类型为 git
|
||||
folder.type = 'git';
|
||||
await this.saveCurrentProjectData();
|
||||
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ 本地文件夹上传失败:', error);
|
||||
vscode.window.showErrorMessage(`本地文件夹上传失败: ${error}`);
|
||||
// 清理:删除可能创建的 .git 文件夹
|
||||
try {
|
||||
const gitDir = path.join(fullPath, '.git');
|
||||
if (fs.existsSync(gitDir)) {
|
||||
await fs.promises.rm(gitDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
catch (cleanupError) {
|
||||
console.error('清理 .git 文件夹失败:', cleanupError);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 使用命令行 Git 初始化仓库
|
||||
*/
|
||||
async initGitRepository(fullPath, branchName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('📁 初始化 Git 仓库...');
|
||||
exec(`git init && git checkout -b ${branchName}`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error('❌ Git 初始化失败:', error);
|
||||
reject(new Error(`Git 初始化失败: ${stderr || error.message}`));
|
||||
return;
|
||||
}
|
||||
console.log('✅ Git 初始化成功');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 使用命令行 Git 添加远程仓库
|
||||
*/
|
||||
async addGitRemote(fullPath, repoUrl) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('📡 添加远程仓库...');
|
||||
exec(`git remote add origin ${repoUrl}`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error('❌ 添加远程仓库失败:', error);
|
||||
reject(new Error(`添加远程仓库失败: ${stderr || error.message}`));
|
||||
return;
|
||||
}
|
||||
console.log('✅ 远程仓库添加成功');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 使用命令行 Git 提交初始文件
|
||||
*/
|
||||
async commitInitialFiles(fullPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('💾 提交初始文件...');
|
||||
const commands = [
|
||||
'git add .',
|
||||
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`
|
||||
];
|
||||
exec(commands.join(' && '), {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// 检查是否是"没有更改可提交"的错误
|
||||
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
||||
console.log('ℹ️ 没有需要提交的更改');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
console.error('❌ Git 提交失败:', error);
|
||||
reject(new Error(`Git 提交失败: ${stderr || error.message}`));
|
||||
return;
|
||||
}
|
||||
console.log('✅ 初始文件提交成功');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 使用命令行 Git 强制推送到远程仓库
|
||||
*/
|
||||
async pushToRemoteWithForce(fullPath, branchName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('🚀 强制推送到远程仓库...');
|
||||
exec(`git push -u origin ${branchName} --force`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
console.log('📋 Git push stdout:', stdout);
|
||||
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));
|
||||
return;
|
||||
}
|
||||
console.log('✅ Git 推送成功');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
async getCurrentBranch(dir) {
|
||||
try {
|
||||
const currentBranch = await isomorphic_git_1.default.currentBranch({
|
||||
fs: fs,
|
||||
dir: dir,
|
||||
fullname: false
|
||||
});
|
||||
if (!currentBranch) {
|
||||
// 如果没有当前分支,尝试从 HEAD 文件读取
|
||||
const headPath = path.join(dir, '.git', 'HEAD');
|
||||
if (fs.existsSync(headPath)) {
|
||||
const headContent = await fs.promises.readFile(headPath, 'utf8');
|
||||
const match = headContent.match(/ref: refs\/heads\/(.+)/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
throw new Error('无法确定当前分支');
|
||||
}
|
||||
return currentBranch;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取当前分支失败:', error);
|
||||
throw new Error(`获取当前分支失败: ${error}`);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 使用命令行 Git 进行推送(带详细调试)
|
||||
*/
|
||||
async pushUsingCommandLine(fullPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('🚀 使用命令行 Git 推送...');
|
||||
console.log(`📁 工作目录: ${fullPath}`);
|
||||
// 先检查 Git 状态
|
||||
exec('git status', {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (statusError, statusStdout, statusStderr) => {
|
||||
console.log('🔍 Git 状态:', statusStdout);
|
||||
// 然后执行推送
|
||||
exec('git push', {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
console.log('📋 Git push stdout:', stdout);
|
||||
console.log('📋 Git push stderr:', stderr);
|
||||
if (error) {
|
||||
console.error('❌ Git push 失败:', error);
|
||||
reject(new Error(`Git 推送失败: ${stderr || error.message}`));
|
||||
return;
|
||||
}
|
||||
// 检查实际的推送结果
|
||||
if (stdout.includes('Everything up-to-date')) {
|
||||
console.log('ℹ️ 没有需要推送的更改');
|
||||
resolve();
|
||||
}
|
||||
else if (stdout.includes('To http') || stdout.includes('To https') || stdout.includes('To git@')) {
|
||||
console.log('✅ Git 推送成功');
|
||||
resolve();
|
||||
}
|
||||
else {
|
||||
console.log('⚠️ 推送结果不明确,可能需要手动检查');
|
||||
reject(new Error('推送结果不明确,请检查远程仓库'));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 检查 Git 远程配置
|
||||
*/
|
||||
async checkGitRemote(fullPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { exec } = require('child_process');
|
||||
console.log('🔍 检查 Git 远程配置...');
|
||||
exec('git remote -v', {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error('检查远程配置失败:', error);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
console.log('📡 Git 远程配置:', stdout);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 使用命令行 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(' && '), {
|
||||
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}`));
|
||||
return;
|
||||
}
|
||||
console.log('✅ Git 提交并推送成功');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ConfigPanel = ConfigPanel;
|
||||
//# sourceMappingURL=ConfigPanel.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -43,9 +43,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||
</td>
|
||||
<td>
|
||||
${folder.type === 'git' ? `
|
||||
<button class="btn-sync" onclick="syncModuleFolder('${folder.id}')" style="margin-right: 5px;">同步</button>
|
||||
` : ''}
|
||||
<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>
|
||||
@@ -96,7 +94,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.btn-sync {
|
||||
.btn-upload {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
padding: 4px 8px;
|
||||
@@ -105,9 +103,15 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.btn-sync:hover {
|
||||
.btn-upload:hover {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
}
|
||||
|
||||
.btn-upload:disabled {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* 树状分支样式 */
|
||||
.branch-tree {
|
||||
@@ -394,13 +398,111 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
);
|
||||
}
|
||||
|
||||
// 同步 Git 模块文件夹
|
||||
function syncModuleFolder(folderId) {
|
||||
console.log('🔄 同步模块文件夹:', folderId);
|
||||
// 上传模块文件夹功能
|
||||
function uploadModuleFolder(folderId, folderType) {
|
||||
console.log('📤 上传模块文件夹:', { folderId, folderType });
|
||||
|
||||
if (folderType === 'git') {
|
||||
// Git 类型:直接上传(相当于 push)
|
||||
showConfirmDialog(
|
||||
'确认上传',
|
||||
'确定要将 Git 文件夹的内容上传到远程仓库吗?这将执行 git push 操作。',
|
||||
function() {
|
||||
vscode.postMessage({
|
||||
type: 'uploadGitModuleFolder',
|
||||
folderId: folderId
|
||||
});
|
||||
},
|
||||
function() {
|
||||
console.log('❌ 用户取消上传 Git 文件夹');
|
||||
}
|
||||
);
|
||||
} else if (folderType === 'local') {
|
||||
// Local 类型:弹出 URL 输入对话框
|
||||
showUploadDialog(folderId);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加上传对话框函数
|
||||
function showUploadDialog(folderId) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'uploadModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog" style="width: 500px;">
|
||||
<div class="modal-title">上传本地文件夹到 Git 仓库</div>
|
||||
<div class="merge-dialog-content">
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">Git 仓库 URL</label>
|
||||
<input type="text" id="gitRepoUrlInput" class="merge-input-field"
|
||||
placeholder="请输入 Git 仓库 URL,例如: https://github.com/username/repo.git">
|
||||
<div class="merge-input-help">将把当前文件夹的内容上传到此仓库</div>
|
||||
</div>
|
||||
<div class="merge-input-section">
|
||||
<label class="merge-input-label">分支名称</label>
|
||||
<input type="text" id="branchNameInput" class="merge-input-field"
|
||||
placeholder="请输入分支名称" value="">
|
||||
<div class="merge-input-help">将以当前文件夹名称作为分支名创建新分支</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeUploadDialog()">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" onclick="confirmUpload('\${folderId}')">确定上传</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
// 自动聚焦到 URL 输入框
|
||||
setTimeout(() => {
|
||||
const urlInput = document.getElementById('gitRepoUrlInput');
|
||||
if (urlInput) {
|
||||
urlInput.focus();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function confirmUpload(folderId) {
|
||||
const urlInput = document.getElementById('gitRepoUrlInput');
|
||||
const branchInput = document.getElementById('branchNameInput');
|
||||
|
||||
const repoUrl = urlInput.value.trim();
|
||||
const branchName = branchInput.value.trim();
|
||||
|
||||
if (!repoUrl) {
|
||||
alert('请输入 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repoUrl.startsWith('http')) {
|
||||
alert('请输入有效的 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!branchName) {
|
||||
alert('请输入分支名称');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('📤 确认上传本地文件夹:', { folderId, repoUrl, branchName });
|
||||
|
||||
vscode.postMessage({
|
||||
type: 'syncGitModuleFolder',
|
||||
folderId: folderId
|
||||
type: 'uploadLocalModuleFolder',
|
||||
folderId: folderId,
|
||||
repoUrl: repoUrl,
|
||||
branchName: branchName
|
||||
});
|
||||
|
||||
closeUploadDialog();
|
||||
}
|
||||
|
||||
function closeUploadDialog() {
|
||||
const modal = document.getElementById('uploadModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function goBackToContainers() {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user