feat(worktree): base improvement-child worktree on parent HEAD
This commit is contained in:
@@ -32,7 +32,7 @@ public sealed class WorktreeManager
|
||||
if (!await _git.IsGitRepoAsync(workingDir, ct))
|
||||
throw new InvalidOperationException($"working_dir is not a git repository: {workingDir}");
|
||||
|
||||
var baseCommit = await _git.RevParseHeadAsync(workingDir, ct);
|
||||
var baseCommit = await ResolveBaseCommitAsync(task, workingDir, ct);
|
||||
// Use the full task id (dashes stripped) in the branch name so
|
||||
// two GUIDs sharing an 8-char prefix cannot collide on the same branch.
|
||||
var idForBranch = task.Id.Replace("-", "");
|
||||
@@ -184,4 +184,25 @@ public sealed class WorktreeManager
|
||||
|
||||
_logger.LogInformation("Discarded worktree for task {TaskId} (branch {Branch})", wt.TaskId, wt.BranchName);
|
||||
}
|
||||
|
||||
// Improvement children (parent is a non-planning task with its own worktree) branch
|
||||
// from the parent's recorded HEAD so they build on the parent's not-yet-merged work.
|
||||
// Planning children and standalone tasks base off the list's current HEAD.
|
||||
private async Task<string> ResolveBaseCommitAsync(TaskEntity task, string workingDir, CancellationToken ct)
|
||||
{
|
||||
if (task.ParentTaskId is not null)
|
||||
{
|
||||
using var ctx = _dbFactory.CreateDbContext();
|
||||
var parent = await ctx.Tasks.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == task.ParentTaskId, ct);
|
||||
if (parent is not null && parent.PlanningPhase == PlanningPhase.None)
|
||||
{
|
||||
var parentWt = await new WorktreeRepository(ctx).GetByTaskIdAsync(task.ParentTaskId, ct);
|
||||
var parentHead = parentWt?.HeadCommit ?? parentWt?.BaseCommit;
|
||||
if (parentHead is not null)
|
||||
return parentHead;
|
||||
}
|
||||
}
|
||||
return await _git.RevParseHeadAsync(workingDir, ct);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user