14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/worktrees/commands/switch.rb', line 14
def call(name:, **options)
begin
manager = WorktreeManager.new
target_worktree = manager.find_worktree(name)
unless target_worktree
raise ValidationError, "Worktree '#{name}' not found"
end
current = manager.current_worktree
if current && current.dirty? && !options[:force]
warn "Warning: Previous worktree '#{current.name}' has uncommitted changes"
end
switched_worktree = manager.switch_to_worktree(name)
puts "Switched to worktree: #{switched_worktree.name}"
puts " Path: #{switched_worktree.path}"
puts " Branch: #{switched_worktree.branch}"
puts " Status: #{switched_worktree.status}"
if current && current.dirty?
puts "\nWarning: Previous worktree '#{current.name}' has uncommitted changes"
end
rescue ValidationError => e
warn "ERROR: Validation: #{e.message}"
exit(2)
rescue StateError => e
warn "ERROR: State: #{e.message}"
exit(3)
rescue StandardError => e
warn "ERROR: #{e.message}"
exit(1)
end
end
|