fix(worker): stop sibling worktrees from landing inside the repo tree
Path.GetDirectoryName returned workingDir itself instead of its parent whenever list.WorkingDir ended in a directory separator, placing .claudedo-worktrees inside the target repo's own working tree. Add WorktreeRootResolver to normalize the trailing separator before deriving the sibling root and to guard that the resulting worktree path never lands inside workingDir, used by both WorktreeManager and PlanningSessionManager. Add a startup sweep (LegacyWorktreeFolderRecovery) that warns when a list's working dir already contains a leftover .claudedo-worktrees folder from before the fix.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
|
||||
/// <summary>
|
||||
/// Startup-only sweep: warns when a list's working directory already contains a
|
||||
/// <c>.claudedo-worktrees</c> folder inside its own tree — the symptom of the sibling-worktree
|
||||
/// path bug (see <see cref="ClaudeDo.Worker.Git.WorktreeRootResolver"/>) from before it was
|
||||
/// fixed. Detection only; moving or ignoring existing folders is left to the user.
|
||||
/// </summary>
|
||||
public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
||||
{
|
||||
private const string LegacyFolderName = ".claudedo-worktrees";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly ILogger<LegacyWorktreeFolderRecovery> _logger;
|
||||
|
||||
public LegacyWorktreeFolderRecovery(
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||
ILogger<LegacyWorktreeFolderRecovery> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await using var ctx = await _dbFactory.CreateDbContextAsync(cancellationToken);
|
||||
var lists = await new ListRepository(ctx).GetAllAsync(cancellationToken);
|
||||
|
||||
var affected = FindAffectedListNames(lists);
|
||||
|
||||
if (affected.Count > 0)
|
||||
_logger.LogWarning(
|
||||
"Legacy worktree folder recovery: found '{Folder}' inside the working tree of {Count} list(s): {Lists}. " +
|
||||
"This was previously caused by a trailing separator on the list's working directory; existing worktrees were not moved.",
|
||||
LegacyFolderName, affected.Count, string.Join(", ", affected));
|
||||
else
|
||||
_logger.LogInformation("Legacy worktree folder recovery: no lists affected");
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
/// <summary>Names of lists whose working dir already contains a <c>.claudedo-worktrees</c> folder.</summary>
|
||||
public static List<string> FindAffectedListNames(IEnumerable<ListEntity> lists) =>
|
||||
lists
|
||||
.Where(l => !string.IsNullOrWhiteSpace(l.WorkingDir))
|
||||
.Where(l => Directory.Exists(Path.Combine(l.WorkingDir!, LegacyFolderName)))
|
||||
.Select(l => l.Name)
|
||||
.ToList();
|
||||
}
|
||||
Reference in New Issue
Block a user