Upload main.js via GUI
This commit is contained in:
34
main.js
34
main.js
@@ -1912,6 +1912,18 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
const destPath = (data.destPath || '').replace(/^\//, '').replace(/\/$/, '');
|
||||
if (!owner || !repo) return { ok: false, error: 'missing-owner-or-repo' };
|
||||
|
||||
const gitExecOptions = {
|
||||
stdio: 'pipe',
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
GIT_TERMINAL_PROMPT: '0',
|
||||
GIT_PAGER: 'cat',
|
||||
PAGER: 'cat'
|
||||
},
|
||||
maxBuffer: 10 * 1024 * 1024
|
||||
};
|
||||
|
||||
// Auto-Backup vor Upload (wenn in Einstellungen aktiviert)
|
||||
const autoBackupEnabled = Boolean(credentials && credentials.autoBackupEnabled);
|
||||
const uploadSessionId = String(data.uploadSessionId || '').trim();
|
||||
@@ -2020,7 +2032,7 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
|
||||
const tmpDir = getSafeTmpDir(`git-push-file-${owner}-${repo}`);
|
||||
try {
|
||||
execSync(`git clone --depth 1 --branch ${branch} "${authClone}" "${tmpDir}"`, { stdio: 'inherit' });
|
||||
execSync(`git clone --depth 1 --branch ${branch} "${authClone}" "${tmpDir}"`, gitExecOptions);
|
||||
|
||||
// Zielort im Repo bestimmen
|
||||
let destDirInRepo = tmpDir;
|
||||
@@ -2035,9 +2047,9 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
fs.copyFileSync(data.localFolder, finalFileDest);
|
||||
|
||||
// Git Befehle
|
||||
execSync(`git -C "${tmpDir}" add .`, { stdio: 'inherit' });
|
||||
try { execSync(`git -C "${tmpDir}" commit -m "Upload file ${fileName} via GUI"`, { stdio: 'inherit' }); } catch (_) {}
|
||||
execSync(`git -C "${tmpDir}" push origin ${branch}`, { stdio: 'inherit' });
|
||||
execSync(`git -C "${tmpDir}" add .`, gitExecOptions);
|
||||
try { execSync(`git -C "${tmpDir}" commit -m "Upload file ${fileName} via GUI"`, gitExecOptions); } catch (_) {}
|
||||
execSync(`git -C "${tmpDir}" push origin ${branch}`, gitExecOptions);
|
||||
|
||||
setTimeout(() => { try { if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (_) {} }, 5_000);
|
||||
return { ok: true, usedGit: true, singleFile: true, msg: 'Uploaded via Git (Fallback)' };
|
||||
@@ -2055,7 +2067,7 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
}
|
||||
|
||||
let gitAvailable = true;
|
||||
try { execSync('git --version', { stdio: 'ignore' }); } catch (e) { gitAvailable = false; }
|
||||
try { execSync('git --version', { stdio: 'ignore', env: gitExecOptions.env }); } catch (e) { gitAvailable = false; }
|
||||
|
||||
let finalCloneUrl = cloneUrl;
|
||||
if (!finalCloneUrl && giteaUrl) {
|
||||
@@ -2079,7 +2091,7 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
const tmpDir = getSafeTmpDir(`gitea-push-${owner}-${repo}`);
|
||||
|
||||
try {
|
||||
execSync(`git clone --depth 1 --branch ${branch} "${authClone}" "${tmpDir}"`, { stdio: 'inherit' });
|
||||
execSync(`git clone --depth 1 --branch ${branch} "${authClone}" "${tmpDir}"`, gitExecOptions);
|
||||
|
||||
// FIXED: Respektieren von destPath und Ordnernamen im Git-Workflow
|
||||
const folderName = ppath.basename(data.localFolder);
|
||||
@@ -2106,16 +2118,16 @@ ipcMain.handle('upload-and-push', async (event, data) => {
|
||||
fs.cpSync(data.localFolder, finalDest, { recursive: true, force: true });
|
||||
} else {
|
||||
if (process.platform === 'win32') {
|
||||
execSync(`robocopy "${data.localFolder}" "${finalDest}" /E /NFL /NDL /NJH /NJS /nc /ns`, { stdio: 'inherit', shell: true });
|
||||
execSync(`robocopy "${data.localFolder}" "${finalDest}" /E /NFL /NDL /NJH /NJS /nc /ns`, { ...gitExecOptions, shell: true });
|
||||
} else {
|
||||
execSync(`cp -r "${data.localFolder}/." "${finalDest}"`, { stdio: 'inherit', shell: true });
|
||||
execSync(`cp -r "${data.localFolder}/." "${finalDest}"`, { ...gitExecOptions, shell: true });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(`git -C "${tmpDir}" add .`, { stdio: 'inherit' });
|
||||
try { execSync(`git -C "${tmpDir}" commit -m "Update from Git Manager GUI"`, { stdio: 'inherit' }); } catch (_) {}
|
||||
execSync(`git -C "${tmpDir}" push origin ${branch}`, { stdio: 'inherit' });
|
||||
execSync(`git -C "${tmpDir}" add .`, gitExecOptions);
|
||||
try { execSync(`git -C "${tmpDir}" commit -m "Update from Git Manager GUI"`, gitExecOptions); } catch (_) {}
|
||||
execSync(`git -C "${tmpDir}" push origin ${branch}`, gitExecOptions);
|
||||
} catch (e) { throw e; }
|
||||
|
||||
setTimeout(() => { try { if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (_) {} }, 5_000);
|
||||
|
||||
Reference in New Issue
Block a user