Class: Envirobly::Git

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

Direct Known Subclasses

Commit

Defined Under Namespace

Classes: Commit, OUTPUT, Unstaged

Instance Method Summary collapse

Constructor Details

#initialize(working_dir = Dir.getwd) ⇒ Git

Returns a new instance of Git.



4
5
6
# File 'lib/envirobly/git.rb', line 4

def initialize(working_dir = Dir.getwd)
  @working_dir = working_dir
end

Instance Method Details

#current_branchObject



16
17
18
# File 'lib/envirobly/git.rb', line 16

def current_branch
  git("branch --show-current").stdout.strip
end

#git(cmd, chdir: @working_dir) ⇒ Object



9
10
11
12
13
14
# File 'lib/envirobly/git.rb', line 9

def git(cmd, chdir: @working_dir)
  Open3.popen3("git #{cmd}", chdir:) do |stdin, stdout, stderr, thread|
    stdin.close
    OUTPUT.new stdout.read, stderr.read, thread.value.exitstatus, thread.value.success?
  end
end