Class: Flo::Provider::GitFlo

Inherits:
Base
  • Object
show all
Defined in:
lib/flo/provider/git_flo.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ GitFlo

Returns a new instance of GitFlo.



18
19
20
21
22
# File 'lib/flo/provider/git_flo.rb', line 18

def initialize(opts={})
  @repo_location = opts[:repo_location] || '.'

  @credentials = opts[:credentials]
end

Instance Method Details

#check_out_or_create_branch(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flo/provider/git_flo.rb', line 24

def check_out_or_create_branch(opts={})
  name = opts[:name]
  ref = opts[:source] || 'master'
  remote = opts[:remote] || 'origin'

  validate_branch_exists(ref)

  if repo.remotes[remote]
    repo.fetch(remote, credentials: credentials)
  end

  if repo.branches.exist? name
    # noop
  elsif repo.branches.exist? "origin/#{name}"
    repo.create_branch(name, "origin/#{name}")
  else
    repo.create_branch(name, ref)
  end

  repo.checkout(name)
  OpenStruct.new(success?: true)
end

#push(opts = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/flo/provider/git_flo.rb', line 47

def push(opts={})
  remote = opts[:remote] || 'origin'
  branch_name = repo.branches[opts[:branch]].canonical_name
  repo.push(remote, branch_name)

  OpenStruct.new(success?: true)
end