Class: RubynCode::Tools::GitDiff

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/git_diff.rb

Constant Summary collapse

TOOL_NAME =
'git_diff'
DESCRIPTION =
'Show git diff for staged, unstaged, or between branches/commits.'
PARAMETERS =
{
  target: { type: :string, required: false, default: 'unstaged',
            description: 'What to diff: "staged", "unstaged", or a branch/commit ref (default: "unstaged")' }
}.freeze
RISK_LEVEL =
:read
REQUIRES_CONFIRMATION =
false
MAX_DIFF_LENGTH =
80_000

Instance Attribute Summary

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Instance Method Details

#execute(target: 'unstaged') ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyn_code/tools/git_diff.rb', line 21

def execute(target: 'unstaged')
  validate_git_repo!

  cmd = build_diff_command(target.to_s.strip)
  stdout, stderr, status = safe_capture3(*cmd, chdir: project_root)

  raise Error, "git diff failed: #{stderr.strip}" unless status.success?

  if stdout.strip.empty?
    "No differences found for target: #{target}"
  else
    header = "git diff (#{target}):\n\n"
    truncate("#{header}#{stdout}", max: MAX_DIFF_LENGTH)
  end
end