Module: Coaster::Git

Extended by:
Git
Included in:
Git, Repository
Defined in:
lib/coaster/git.rb,
lib/coaster/git/options.rb,
lib/coaster/git/repository.rb

Defined Under Namespace

Classes: Options, Repository

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(path) ⇒ Object



21
22
23
24
25
# File 'lib/coaster/git.rb', line 21

def create(path)
  run_cmd(path.split('/')[0..-2].join('/'), "git init #{path}")
  run_cmd(path, "git commit --allow-empty -m 'initial commit'")
  Repository.new(path)
end

Instance Method Details

#run_cmd(path, command) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/coaster/git.rb', line 7

def run_cmd(path, command)
  puts "#{path}: #{command}"
  stdout, stderr, status = Open3.capture3(command, chdir: path)
  if status.success?
    puts "  ↳ success: #{stdout.split("\n").join("\n             ")}"
    stdout
  else
    raise "Error executing command\nPATH: #{path}\nCMD: #{command}\nSTDERR:\n  ↳ #{stderr.split("\n").join("\n    ")}\nSTDOUT:\n  ↳ #{stdout.split("\n").join("\n    ")}"
  end
end