class Flo::Provider::GitFlo
Attributes
credentials[R]
remote[R]
Public Class Methods
new(opts={})
click to toggle source
# File lib/flo/provider/git_flo.rb, line 18 def initialize(opts={}) @repo_location = opts[:repo_location] || '.' @credentials = opts[:credentials] end
Public Instance Methods
check_out_or_create_branch(opts={})
click to toggle source
# 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={})
click to toggle source
# 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, credentials: credentials) OpenStruct.new(success?: true) end
Private Instance Methods
repo()
click to toggle source
# File lib/flo/provider/git_flo.rb, line 59 def repo @repo ||= Rugged::Repository.discover(@repo_location) end
validate_branch_exists(branch)
click to toggle source
# File lib/flo/provider/git_flo.rb, line 63 def validate_branch_exists(branch) unless repo.branches.exist?(branch) raise ::GitFlo::MissingRefError.new("Cannot create branch, as source branch #{branch} does not exist") end end