feat(merge): read conflict stages and write user resolutions
This commit is contained in:
@@ -23,6 +23,16 @@ public sealed record MergePreviewResult(
|
||||
IReadOnlyList<string> ConflictFiles,
|
||||
int ChangedFileCount);
|
||||
|
||||
public sealed record MergeConflicts(
|
||||
string TaskId,
|
||||
IReadOnlyList<ConflictFileContent> Files);
|
||||
|
||||
public sealed record ConflictFileContent(
|
||||
string Path,
|
||||
string Ours,
|
||||
string Theirs,
|
||||
string? Base);
|
||||
|
||||
public sealed class TaskMergeService
|
||||
{
|
||||
public const string StatusMerged = "merged";
|
||||
@@ -217,6 +227,35 @@ public sealed class TaskMergeService
|
||||
return new MergeResult(StatusAborted, Array.Empty<string>(), null);
|
||||
}
|
||||
|
||||
public async Task<MergeConflicts> GetConflictsAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (_, list, _) = await LoadMergeContextAsync(taskId, ct);
|
||||
if (string.IsNullOrWhiteSpace(list.WorkingDir))
|
||||
throw new InvalidOperationException("list has no working directory");
|
||||
|
||||
var files = await _git.ListConflictedFilesAsync(list.WorkingDir, ct);
|
||||
var result = new List<ConflictFileContent>(files.Count);
|
||||
foreach (var path in files)
|
||||
{
|
||||
var ours = await _git.ShowStageAsync(list.WorkingDir, 2, path, ct) ?? "";
|
||||
var theirs = await _git.ShowStageAsync(list.WorkingDir, 3, path, ct) ?? "";
|
||||
var @base = await _git.ShowStageAsync(list.WorkingDir, 1, path, ct);
|
||||
result.Add(new ConflictFileContent(path, ours, theirs, @base));
|
||||
}
|
||||
return new MergeConflicts(taskId, result);
|
||||
}
|
||||
|
||||
public async Task WriteResolutionAsync(string taskId, string path, string content, CancellationToken ct)
|
||||
{
|
||||
var (_, list, _) = await LoadMergeContextAsync(taskId, ct);
|
||||
if (string.IsNullOrWhiteSpace(list.WorkingDir))
|
||||
throw new InvalidOperationException("list has no working directory");
|
||||
|
||||
var full = Path.Combine(list.WorkingDir, path.Replace('/', Path.DirectorySeparatorChar));
|
||||
await File.WriteAllTextAsync(full, content, ct);
|
||||
await _git.AddPathAsync(list.WorkingDir, path, ct);
|
||||
}
|
||||
|
||||
public async Task<MergeTargets> GetTargetsAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (_, list, _) = await LoadMergeContextAsync(taskId, ct);
|
||||
|
||||
Reference in New Issue
Block a user