Update Gitea-Sektion:
Branch-Auswahl
Dieser Commit ist enthalten in:
@ -414,24 +414,58 @@ router.post('/set-remote/:projectId', (req, res) => {
|
||||
/**
|
||||
* POST /api/git/init-push/:projectId
|
||||
* Initialen Push mit Upstream-Tracking
|
||||
* Body: { targetBranch?: string, force?: boolean }
|
||||
* - targetBranch: Optional - Ziel-Branch auf Remote (z.B. "main" auch wenn lokal "master")
|
||||
* - force: Optional - Force-Push um Remote zu überschreiben
|
||||
*/
|
||||
router.post('/init-push/:projectId', (req, res) => {
|
||||
router.post('/init-push/:projectId', async (req, res) => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
const { branch } = req.body;
|
||||
const { targetBranch, force } = req.body;
|
||||
const application = getApplicationForProject(projectId);
|
||||
|
||||
if (!application) {
|
||||
return res.status(404).json({ error: 'Keine Anwendung für dieses Projekt konfiguriert' });
|
||||
}
|
||||
|
||||
const currentBranch = branch || 'main';
|
||||
const result = gitService.pushWithUpstream(application.local_path, currentBranch);
|
||||
// targetBranch kann null sein - dann wird der lokale Branch-Name verwendet
|
||||
// force: boolean - überschreibt Remote-Branch bei Konflikten
|
||||
const result = gitService.pushWithUpstream(application.local_path, targetBranch || null, 'origin', force === true);
|
||||
|
||||
if (result.success) {
|
||||
// Sync-Zeitpunkt aktualisieren
|
||||
const db = getDb();
|
||||
db.prepare('UPDATE applications SET last_sync = CURRENT_TIMESTAMP WHERE project_id = ?').run(projectId);
|
||||
|
||||
// Default-Branch in Gitea aktualisieren wenn der gepushte Branch abweicht
|
||||
if (application.gitea_repo_url && result.branch) {
|
||||
try {
|
||||
// Owner/Repo aus URL extrahieren (z.B. https://gitea.../AegisSight/TaskMate.git)
|
||||
const urlMatch = application.gitea_repo_url.match(/\/([^\/]+)\/([^\/]+?)(?:\.git)?$/);
|
||||
if (urlMatch) {
|
||||
const owner = urlMatch[1];
|
||||
const repoName = urlMatch[2];
|
||||
const actualBranch = result.branch;
|
||||
|
||||
// Default-Branch in Gitea setzen
|
||||
const updateResult = await giteaService.updateRepository(owner, repoName, {
|
||||
defaultBranch: actualBranch
|
||||
});
|
||||
|
||||
if (updateResult.success) {
|
||||
logger.info(`Default-Branch in Gitea auf '${actualBranch}' gesetzt für ${owner}/${repoName}`);
|
||||
result.giteaUpdated = true;
|
||||
result.defaultBranch = actualBranch;
|
||||
} else {
|
||||
logger.warn(`Konnte Default-Branch in Gitea nicht aktualisieren: ${updateResult.error}`);
|
||||
result.giteaUpdated = false;
|
||||
}
|
||||
}
|
||||
} catch (giteaError) {
|
||||
logger.warn('Fehler beim Aktualisieren des Default-Branch in Gitea:', giteaError);
|
||||
result.giteaUpdated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.json(result);
|
||||
@ -441,4 +475,31 @@ router.post('/init-push/:projectId', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/git/rename-branch/:projectId
|
||||
* Branch umbenennen
|
||||
* Body: { oldName: string, newName: string }
|
||||
*/
|
||||
router.post('/rename-branch/:projectId', (req, res) => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
const { oldName, newName } = req.body;
|
||||
const application = getApplicationForProject(projectId);
|
||||
|
||||
if (!application) {
|
||||
return res.status(404).json({ error: 'Keine Anwendung für dieses Projekt konfiguriert' });
|
||||
}
|
||||
|
||||
if (!oldName || !newName) {
|
||||
return res.status(400).json({ error: 'oldName und newName sind erforderlich' });
|
||||
}
|
||||
|
||||
const result = gitService.renameBranch(application.local_path, oldName, newName);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
logger.error('Fehler beim Umbenennen des Branches:', error);
|
||||
res.status(500).json({ error: 'Serverfehler' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren