feat(worker): add WorktreeManager.DiscardAsync for task reset
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -140,4 +140,32 @@ public sealed class WorktreeManager
|
||||
_logger.LogInformation("Committed changes for task {TaskId}: {Head}", task.Id, head);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task DiscardAsync(WorktreeEntity wt, string workingDir, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _git.WorktreeRemoveAsync(workingDir, wt.Path, force: true, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "git worktree remove failed for {Path}", wt.Path);
|
||||
throw;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _git.BranchDeleteAsync(workingDir, wt.BranchName, force: true, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "git branch -D {Branch} failed after worktree removal; continuing", wt.BranchName);
|
||||
}
|
||||
|
||||
using var context = _dbFactory.CreateDbContext();
|
||||
var wtRepo = new WorktreeRepository(context);
|
||||
await wtRepo.SetStateAsync(wt.TaskId, WorktreeState.Discarded, ct);
|
||||
|
||||
_logger.LogInformation("Discarded worktree for task {TaskId} (branch {Branch})", wt.TaskId, wt.BranchName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user