Class: Rralph::Git

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

Instance Method Summary collapse

Constructor Details

#initializeGit

Returns a new instance of Git.



5
# File 'lib/rralph/git.rb', line 5

def initialize; end

Instance Method Details

#commit_changes(message) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
# File 'lib/rralph/git.rb', line 12

def commit_changes(message)
  add_result = `git add . 2>&1`
  raise GitError, "Failed to stage files: #{add_result}" unless $?.success?

  commit_result = `git commit -m #{message.shellescape} 2>&1`
  raise GitError, "Failed to commit: #{commit_result}" unless $?.success?

  `git rev-parse --short HEAD 2>/dev/null`.strip
end

#has_changes?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/rralph/git.rb', line 26

def has_changes?
  status = `git status --porcelain 2>/dev/null`
  !status.empty?
end

#in_git_repo?Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/rralph/git.rb', line 7

def in_git_repo?
  `git rev-parse --git-dir 2>/dev/null`
  $?.success?
end

#statusObject



22
23
24
# File 'lib/rralph/git.rb', line 22

def status
  `git status --short 2>/dev/null`
end