Class: Roger::Release::Finalizers::GitBranch

Inherits:
Base
  • Object
show all
Defined in:
lib/roger/release/finalizers/git_branch.rb

Overview

Finalizes the release into a specific branch of a repository and pushes it

Instance Method Summary collapse

Constructor Details

#initializeGitBranch

Returns a new instance of GitBranch.

Parameters:

  • Hash

    options The options

  • options (Hash)

    a customizable set of options



14
15
16
17
18
19
20
21
# File 'lib/roger/release/finalizers/git_branch.rb', line 14

def initialize
  @options = {
    remote: nil,
    branch: "gh-pages",
    cleanup: true,
    push: true
  }
end

Instance Method Details

#call(release, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/roger/release/finalizers/git_branch.rb', line 23

def call(release, options = {})
  @options = @options.dup.update(options)
  remote = find_git_remote(release.project.path)
  branch = @options[:branch]

  tmp_dir = Pathname.new(::Dir.mktmpdir)
  clone_dir = tmp_dir + "clone"

  # Check if remote already has branch
  if remote_has_branch?(remote, branch)
    release.log(self, "Cloning existing repo")
    clone_branch(clone_dir, remote, branch)
  else
    release.log(self, "Creating empty branch")
    create_empty_branch(clone_dir, remote, branch)
  end

  release.log(self, "Working git magic in #{clone_dir}")

  commit_and_push_release(clone_dir, release, branch, @options)

  if @options[:cleanup]
    FileUtils.rm_rf(tmp_dir)
  else
    tmp_dir
  end
end