feat(worker): add AbortMergeAsync to cancel a conflicted merge
This commit is contained in:
@@ -22,6 +22,7 @@ public sealed class TaskMergeService
|
||||
public const string StatusMerged = "merged";
|
||||
public const string StatusConflict = "conflict";
|
||||
public const string StatusBlocked = "blocked";
|
||||
public const string StatusAborted = "aborted";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly GitService _git;
|
||||
@@ -195,6 +196,32 @@ public sealed class TaskMergeService
|
||||
return new MergeResult(StatusMerged, Array.Empty<string>(), null);
|
||||
}
|
||||
|
||||
public async Task<MergeResult> AbortMergeAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
ListEntity list;
|
||||
WorktreeEntity? wt;
|
||||
|
||||
using (var ctx = _dbFactory.CreateDbContext())
|
||||
{
|
||||
var task = await new TaskRepository(ctx).GetByIdAsync(taskId, ct)
|
||||
?? throw new KeyNotFoundException($"Task '{taskId}' not found.");
|
||||
list = await new ListRepository(ctx).GetByIdAsync(task.ListId, ct)
|
||||
?? throw new InvalidOperationException("List not found.");
|
||||
wt = await new WorktreeRepository(ctx).GetByTaskIdAsync(taskId, ct);
|
||||
}
|
||||
|
||||
if (wt is null) return Blocked("task has no worktree");
|
||||
if (wt.State != WorktreeState.Active) return Blocked($"worktree state is {wt.State}");
|
||||
if (string.IsNullOrWhiteSpace(list.WorkingDir)) return Blocked("list has no working directory");
|
||||
if (!await _git.IsMidMergeAsync(list.WorkingDir, ct))
|
||||
return Blocked("repo is not mid-merge");
|
||||
|
||||
await _git.MergeAbortAsync(list.WorkingDir, ct);
|
||||
_logger.LogInformation("Aborted merge of task {TaskId}", taskId);
|
||||
|
||||
return new MergeResult(StatusAborted, Array.Empty<string>(), null);
|
||||
}
|
||||
|
||||
public async Task<MergeTargets> GetTargetsAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
TaskEntity task;
|
||||
|
||||
Reference in New Issue
Block a user