MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / TestDetectOrphanedWorktrees

Function TestDetectOrphanedWorktrees

internal/git/worktree_test.go:393–470  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

391}
392
393func TestDetectOrphanedWorktrees(t *testing.T) {
394 t.Run("returns nil when worktrees directory does not exist", func(t *testing.T) {
395 dir := t.TempDir()
396 result := DetectOrphanedWorktrees(dir)
397 if result != nil {
398 t.Errorf("expected nil, got %v", result)
399 }
400 })
401
402 t.Run("returns empty map when worktrees directory is empty", func(t *testing.T) {
403 dir := t.TempDir()
404 worktreesDir := filepath.Join(dir, ".chief", "worktrees")
405 if err := os.MkdirAll(worktreesDir, 0755); err != nil {
406 t.Fatalf("failed to create worktrees dir: %v", err)
407 }
408 result := DetectOrphanedWorktrees(dir)
409 if len(result) != 0 {
410 t.Errorf("expected empty map, got %v", result)
411 }
412 })
413
414 t.Run("detects worktree directories on disk", func(t *testing.T) {
415 dir := t.TempDir()
416 worktreesDir := filepath.Join(dir, ".chief", "worktrees")
417
418 // Create some worktree directories
419 for _, name := range []string{"auth", "payments"} {
420 if err := os.MkdirAll(filepath.Join(worktreesDir, name), 0755); err != nil {
421 t.Fatalf("failed to create dir: %v", err)
422 }
423 }
424
425 result := DetectOrphanedWorktrees(dir)
426 if len(result) != 2 {
427 t.Fatalf("expected 2 entries, got %d: %v", len(result), result)
428 }
429
430 authPath, ok := result["auth"]
431 if !ok {
432 t.Error("expected 'auth' in result")
433 }
434 if authPath != filepath.Join(worktreesDir, "auth") {
435 t.Errorf("expected auth path %q, got %q", filepath.Join(worktreesDir, "auth"), authPath)
436 }
437
438 paymentsPath, ok := result["payments"]
439 if !ok {
440 t.Error("expected 'payments' in result")
441 }
442 if paymentsPath != filepath.Join(worktreesDir, "payments") {
443 t.Errorf("expected payments path %q, got %q", filepath.Join(worktreesDir, "payments"), paymentsPath)
444 }
445 })
446
447 t.Run("ignores files in worktrees directory", func(t *testing.T) {
448 dir := t.TempDir()
449 worktreesDir := filepath.Join(dir, ".chief", "worktrees")
450 if err := os.MkdirAll(worktreesDir, 0755); err != nil {

Callers

nothing calls this directly

Calls 2

DetectOrphanedWorktreesFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected