Merge pull request #711 from cpdata/fix/worktree-health-check-redundancy
Reviewed by dave (beads crew worker)
This commit is contained in:
@@ -62,23 +62,13 @@ func syncBranchCommitAndPushWithOptions(ctx context.Context, store storage.Stora
|
|||||||
// Initialize worktree manager
|
// Initialize worktree manager
|
||||||
wtMgr := git.NewWorktreeManager(repoRoot)
|
wtMgr := git.NewWorktreeManager(repoRoot)
|
||||||
|
|
||||||
// Ensure worktree exists
|
// Ensure worktree exists and is healthy
|
||||||
|
// CreateBeadsWorktree now performs a full health check internally and
|
||||||
|
// automatically repairs unhealthy worktrees by removing and recreating them
|
||||||
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
||||||
return false, fmt.Errorf("failed to create worktree: %w", err)
|
return false, fmt.Errorf("failed to create worktree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check worktree health and repair if needed
|
|
||||||
if err := wtMgr.CheckWorktreeHealth(worktreePath); err != nil {
|
|
||||||
log.log("Worktree health check failed, attempting repair: %v", err)
|
|
||||||
// Try to recreate worktree
|
|
||||||
if err := wtMgr.RemoveBeadsWorktree(worktreePath); err != nil {
|
|
||||||
log.log("Failed to remove unhealthy worktree: %v", err)
|
|
||||||
}
|
|
||||||
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
|
||||||
return false, fmt.Errorf("failed to recreate worktree after health check: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync JSONL file to worktree
|
// Sync JSONL file to worktree
|
||||||
// Get the actual JSONL path (could be issues.jsonl, beads.base.jsonl, etc.)
|
// Get the actual JSONL path (could be issues.jsonl, beads.base.jsonl, etc.)
|
||||||
jsonlPath := findJSONLPath()
|
jsonlPath := findJSONLPath()
|
||||||
|
|||||||
@@ -35,11 +35,20 @@ func (wm *WorktreeManager) CreateBeadsWorktree(branch, worktreePath string) erro
|
|||||||
if _, err := os.Stat(worktreePath); err == nil {
|
if _, err := os.Stat(worktreePath); err == nil {
|
||||||
// Worktree path exists, check if it's a valid worktree
|
// Worktree path exists, check if it's a valid worktree
|
||||||
if valid, err := wm.isValidWorktree(worktreePath); err == nil && valid {
|
if valid, err := wm.isValidWorktree(worktreePath); err == nil && valid {
|
||||||
return nil // Already exists and is valid
|
// Worktree exists and is in git worktree list, verify full health
|
||||||
}
|
if err := wm.CheckWorktreeHealth(worktreePath); err == nil {
|
||||||
// Path exists but isn't a valid worktree, remove it
|
return nil // Already exists and is fully healthy
|
||||||
if err := os.RemoveAll(worktreePath); err != nil {
|
}
|
||||||
return fmt.Errorf("failed to remove invalid worktree path: %w", err)
|
// Health check failed, try to repair by removing and recreating
|
||||||
|
if err := wm.RemoveBeadsWorktree(worktreePath); err != nil {
|
||||||
|
// Log but continue - we'll try to recreate anyway
|
||||||
|
_ = os.RemoveAll(worktreePath)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Path exists but isn't a valid worktree, remove it
|
||||||
|
if err := os.RemoveAll(worktreePath); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove invalid worktree path: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,23 +83,13 @@ func CommitToSyncBranch(ctx context.Context, repoRoot, syncBranch, jsonlPath str
|
|||||||
// Initialize worktree manager
|
// Initialize worktree manager
|
||||||
wtMgr := git.NewWorktreeManager(repoRoot)
|
wtMgr := git.NewWorktreeManager(repoRoot)
|
||||||
|
|
||||||
// Ensure worktree exists
|
// Ensure worktree exists and is healthy
|
||||||
|
// CreateBeadsWorktree performs a full health check internally and
|
||||||
|
// automatically repairs unhealthy worktrees by removing and recreating them
|
||||||
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create worktree: %w", err)
|
return nil, fmt.Errorf("failed to create worktree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check worktree health and repair if needed
|
|
||||||
if err := wtMgr.CheckWorktreeHealth(worktreePath); err != nil {
|
|
||||||
// Try to recreate worktree
|
|
||||||
if err := wtMgr.RemoveBeadsWorktree(worktreePath); err != nil {
|
|
||||||
// Log but continue - removal might fail but recreation might work
|
|
||||||
_ = err
|
|
||||||
}
|
|
||||||
if err := wtMgr.CreateBeadsWorktree(syncBranch, worktreePath); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to recreate worktree after health check: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get remote name
|
// Get remote name
|
||||||
remote := getRemoteForBranch(ctx, worktreePath, syncBranch)
|
remote := getRemoteForBranch(ctx, worktreePath, syncBranch)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user