Class: Coppy::Steps::Git

Inherits:
Object
  • Object
show all
Extended by:
DSL::Module
Defined in:
lib/coppy/steps/git.rb

Instance Method Summary collapse

Methods included from DSL::Module

dsl, step

Constructor Details

#initialize(&block) ⇒ Git

Returns a new instance of Git.



15
16
17
# File 'lib/coppy/steps/git.rb', line 15

def initialize(&block)
  @manifesto = Manifesto.load(self.class.dsl, &block)
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coppy/steps/git.rb', line 19

def call(env)
  source_hash = Dir.chdir(env.source) { `git rev-parse HEAD` }
  source_origin = Dir.chdir(env.source) do
    `git remote -v`.each_line
      .map {|line| line.split("\t") }
      .find {|remote, src, fetch_or_push| remote == "origin" && fetch_or_push == "fetch" }
  end

  Dir.chdir(env.target) do
    system "git init", out: File::NULL
    git_env = Environment.new(
      source: Environment.new(
        hash: source_hash,
        remote: source_origin
      )
    )

    @manifesto.execute!(git_env)
  end
end