fix(worker): honour targetBranch in MergeAsync by checking out before merge

Add GitService.CheckoutBranchAsync; compare targetBranch to current HEAD
before MergeNoFfAsync and switch when they differ. Returns Blocked if the
branch does not exist. Add three new tests (two service, one GitService).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mika Kuns
2026-04-22 10:25:35 +02:00
parent 1bc7fcc609
commit 953d93179d
4 changed files with 86 additions and 0 deletions

View File

@@ -160,6 +160,13 @@ public sealed class GitService
return stdout.Trim();
}
public async Task CheckoutBranchAsync(string repoDir, string branchName, CancellationToken ct = default)
{
var (exitCode, _, stderr) = await RunGitAsync(repoDir, ["checkout", branchName], ct);
if (exitCode != 0)
throw new InvalidOperationException($"git checkout '{branchName}' failed (exit {exitCode}): {stderr}");
}
public async Task<List<string>> ListLocalBranchesAsync(string repoDir, CancellationToken ct = default)
{
var (exitCode, stdout, stderr) = await RunGitAsync(repoDir,