Class: Ai::Commit::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/ai/commit/git.rb

Class Method Summary collapse

Class Method Details

.has_staged_changes?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ai/commit/git.rb', line 24

def self.has_staged_changes?
  !`git diff --cached --name-only`.strip.empty?
end

.in_git_repo?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ai/commit/git.rb', line 20

def self.in_git_repo?
  system('git rev-parse --git-dir', out: File::NULL, err: File::NULL)
end

.staged_diffObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ai/commit/git.rb', line 6

def self.staged_diff
  result = `git diff --cached`
  
  if $?.exitstatus != 0
    raise Error, "Failed to get git diff. Are you in a git repository?"
  end
  
  if result.empty?
    raise Error, "No staged changes found. Stage your changes with 'git add' first."
  end
  
  result
end