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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/legion/cli/commit_command.rb', line 27
def generate
out = formatter
stage_all if options[:all]
diff = staged_diff
if diff.strip.empty?
out.error('Nothing staged to commit. Use -a to stage all changes, or git add files first.')
raise SystemExit, 1
end
stat = staged_stat
log = recent_commits
setup_connection
out.('Generating commit message...')
message = generate_message(diff, stat, log)
if options[:json]
out.json({ message: message, stat: stat })
return
end
puts
puts out.colorize(message, :green)
puts
puts out.dim(stat)
puts
unless options[:yes]
$stderr.print "#{out.colorize('Commit with this message?', :yellow)} [Y/n/e(dit)] "
response = $stdin.gets&.strip&.downcase
case response
when 'n', 'no'
out.warn('Commit aborted.')
return
when 'e', 'edit'
message = edit_message(message)
return out.warn('Commit aborted (empty message).') if message.strip.empty?
end
end
run_commit(message, amend: options[:amend])
out.success(options[:amend] ? 'Commit amended.' : 'Committed.')
rescue CLI::Error => e
out.error(e.message)
raise SystemExit, 1
ensure
Connection.shutdown
end
|