Class: RubyLLM::Toolbox::Tools::GitCommit

Inherits:
Base
  • Object
show all
Includes:
GitHelpers
Defined in:
lib/ruby_llm/toolbox/tools/git_commit.rb

Overview

EXEC. Commits staged changes in the repo at fs_root. The message is passed as a single argv element (-m), so it is never parsed by a shell.

Constant Summary

Constants included from GitHelpers

RubyLLM::Toolbox::Tools::GitHelpers::GIT_ENV, RubyLLM::Toolbox::Tools::GitHelpers::REF_RE

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from GitHelpers

#git_result, #repo_relative, #run_git, #valid_ref?

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(message:, all: false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby_llm/toolbox/tools/git_commit.rb', line 25

def execute(message:, all: false)
  msg = message.to_s
  return error("commit message must not be empty", code: :empty_message) if msg.strip.empty?

  args = ["commit"]
  args << "-a" if all
  args += ["-m", msg]

  out, err, status = run_git(*args)
  result = git_result(out, err, status)
  if result.is_a?(Hash)
    combined = "#{out}\n#{err}"
    return error("nothing to commit (stage changes first)", code: :nothing_to_commit) if combined.match?(/nothing to commit/i)

    return result
  end

  truncate(out.strip)
end