Update Gitea-Sektion:

Branch-Auswahl
Dieser Commit ist enthalten in:
Claude Project Manager
2025-12-29 19:02:44 +00:00
Ursprung 8da6ad83f0
Commit 627beb1353
30 geänderte Dateien mit 3953 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -443,7 +443,7 @@ function hasRemote(localPath, remoteName = 'origin') {
/**
* Initialen Push mit Upstream-Tracking
*/
function pushWithUpstream(localPath, branch = null, remoteName = 'origin') {
function pushWithUpstream(localPath, targetBranch = null, remoteName = 'origin', force = false) {
if (!isGitRepository(localPath)) {
return { success: false, error: 'Kein Git-Repository' };
}
@ -477,11 +477,12 @@ function pushWithUpstream(localPath, branch = null, remoteName = 'origin') {
}
}
// Aktuellen Branch ermitteln NACH dem Commit
// Aktuellen (lokalen) Branch ermitteln NACH dem Commit
let localBranch = null;
const branchResult = execGitCommand('git branch --show-current', localPath);
if (branchResult.success && branchResult.output) {
branch = branchResult.output;
logger.info(`Aktueller Branch: ${branch}`);
localBranch = branchResult.output;
logger.info(`Lokaler Branch: ${localBranch}`);
} else {
// Fallback: Branch aus git branch auslesen
const branchListResult = execGitCommand('git branch', localPath);
@ -491,29 +492,46 @@ function pushWithUpstream(localPath, branch = null, remoteName = 'origin') {
const lines = branchListResult.output.split('\n');
for (const line of lines) {
if (line.includes('*')) {
branch = line.replace('*', '').trim();
localBranch = line.replace('*', '').trim();
break;
}
}
}
if (!branch) {
if (!localBranch) {
// Letzter Fallback: Versuche den Branch zu erstellen
logger.info('Kein Branch gefunden, erstelle main');
execGitCommand('git checkout -b main', localPath);
branch = 'main';
localBranch = 'main';
}
}
logger.info(`Push auf Branch: ${branch}`);
// Wenn kein Ziel-Branch angegeben, verwende lokalen Branch-Namen
const remoteBranch = targetBranch || localBranch;
logger.info(`Push: lokaler Branch '${localBranch}' → Remote Branch '${remoteBranch}'${force ? ' (FORCE)' : ''}`);
// Push mit -u für Upstream-Tracking
const pushResult = execGitCommand(`git push -u ${remoteName} ${branch}`, localPath, { timeout: 120000 });
// Format: git push -u origin localBranch:remoteBranch
const forceFlag = force ? ' --force' : '';
let pushCommand;
if (localBranch === remoteBranch) {
pushCommand = `git push -u${forceFlag} ${remoteName} ${localBranch}`;
} else {
// Branch-Mapping: lokalen Branch auf anderen Remote-Branch pushen
pushCommand = `git push -u${forceFlag} ${remoteName} ${localBranch}:${remoteBranch}`;
}
const pushResult = execGitCommand(pushCommand, localPath, { timeout: 120000 });
if (!pushResult.success) {
logger.error(`Push fehlgeschlagen: ${pushResult.error}`);
}
// Branch-Namen im Ergebnis inkludieren für Default-Branch Aktualisierung
pushResult.localBranch = localBranch;
pushResult.branch = remoteBranch; // Remote-Branch für Gitea Default-Branch
return pushResult;
}
@ -561,6 +579,39 @@ function prepareForGitea(localPath, remoteUrl, options = {}) {
return { success: true, message: 'Repository für Gitea vorbereitet' };
}
/**
* Branch umbenennen
*/
function renameBranch(localPath, oldName, newName) {
if (!isGitRepository(localPath)) {
return { success: false, error: 'Kein Git-Repository' };
}
// Validiere neuen Branch-Namen
if (!newName || !/^[a-zA-Z0-9_\-]+$/.test(newName)) {
return { success: false, error: 'Ungültiger Branch-Name. Nur Buchstaben, Zahlen, Unterstriche und Bindestriche erlaubt.' };
}
// Prüfe ob wir auf dem zu umbenennenden Branch sind
const branchResult = execGitCommand('git branch --show-current', localPath);
const currentBranch = branchResult.success ? branchResult.output : null;
if (currentBranch !== oldName) {
return { success: false, error: `Bitte wechsle zuerst zum Branch "${oldName}" bevor du ihn umbenennst.` };
}
// Branch umbenennen
const renameResult = execGitCommand(`git branch -m ${oldName} ${newName}`, localPath);
if (!renameResult.success) {
logger.error(`Branch umbenennen fehlgeschlagen: ${renameResult.error}`);
return renameResult;
}
logger.info(`Branch umbenannt: ${oldName}${newName}`);
return { success: true, oldName, newName, message: `Branch "${oldName}" zu "${newName}" umbenannt` };
}
module.exports = {
windowsToContainerPath,
containerToWindowsPath,
@ -581,5 +632,6 @@ module.exports = {
setRemote,
hasRemote,
pushWithUpstream,
prepareForGitea
prepareForGitea,
renameBranch
};