Module: Carson::Runtime::Housekeep

Included in:
Carson::Runtime
Defined in:
lib/carson/runtime/housekeep.rb

Instance Method Summary collapse

Instance Method Details

#housekeep!(json_output: false, dry_run: false) ⇒ Object

Serves the current repo: sync + prune. Resolves to the canonical main worktree root so the command works correctly when invoked from inside an agent worktree.



15
16
17
18
19
20
21
22
23
24
# File 'lib/carson/runtime/housekeep.rb', line 15

def housekeep!( json_output: false, dry_run: false )
	canonical = main_worktree_root

	if dry_run
		scoped = Runtime.new( repo_root: canonical, tool_root: tool_root, output: output, error: error, verbose: verbose? )
		return scoped.housekeep_one_dry_run
	end

	housekeep_one( repo_path: canonical, json_output: json_output )
end

#housekeep_one_dry_runObject

Prints a dry-run plan for this repo without making any changes. Calls reap_dead_worktrees_plan and prune_plan on self (already scoped to the repo).



28
29
30
31
32
33
34
# File 'lib/carson/runtime/housekeep.rb', line 28

def housekeep_one_dry_run
	repo_name = File.basename( repo_root )
	worktree_plan = reap_dead_worktrees_plan
	branch_plan = prune_plan( dry_run: true )
	print_housekeep_dry_run( repo_name: repo_name, worktree_plan: worktree_plan, branch_plan: branch_plan )
	EXIT_OK
end

#reap_dead_worktrees!Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/carson/runtime/housekeep.rb', line 53

def reap_dead_worktrees!
	worktree_list.each do |worktree|
		next if worktree.path == main_worktree_root

		classification = classify_worktree_cleanup( worktree: worktree )
		if classification.fetch( :action ) == :skip
			puts_line "Kept worktree: #{worktree_housekeep_label( worktree: worktree )}#{classification.fetch( :reason )}" unless verbose?
			next
		end

		reap_one_worktree!(
			worktree: worktree,
			reason: classification.fetch( :reason ),
			force: classification.fetch( :force, false )
		)
	end

	reap_integrated_delivery_worktrees!
end

#reap_dead_worktrees_planObject

Returns a plan array describing what reap_dead_worktrees! would do for each non-main worktree, without executing any mutations. Each item: { name:, branch:, action: :reap|:skip, reason: }



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/carson/runtime/housekeep.rb', line 39

def reap_dead_worktrees_plan
	worktree_list.filter_map do |worktree|
		next if worktree.path == main_worktree_root

		classification = classify_worktree_cleanup( worktree: worktree )
		{
			name: File.basename( worktree.path ),
			branch: worktree.branch,
			action: classification.fetch( :action ),
			reason: classification.fetch( :reason )
		}
	end
end