Class: Awestruct::Deploy::GitHubPagesDeploy

Inherits:
Base
  • Object
show all
Defined in:
lib/awestruct/deploy/github_pages_deploy.rb

Constant Summary

Constants inherited from Base

Base::UNCOMMITTED_CHANGES

Instance Method Summary collapse

Methods inherited from Base

#compress_site, #existing_changes, #gzip_file, #gzip_site, #init_scm, #is_gzipped, #run

Constructor Details

#initialize(site_config, deploy_config) ⇒ GitHubPagesDeploy

Returns a new instance of GitHubPagesDeploy.



8
9
10
11
12
# File 'lib/awestruct/deploy/github_pages_deploy.rb', line 8

def initialize(site_config, deploy_config)
  super
  @branch = deploy_config['branch'] || 'gh-pages'
  @repo = deploy_config['repository'] || 'origin'
end

Instance Method Details

#publish_siteObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/awestruct/deploy/github_pages_deploy.rb', line 14

def publish_site
  tmp_branch = '__awestruct_deploy__'
  detached_branch = nil

  original_branch = git.current_branch

  # detect a detached state
  # values include (no branch), (detached from x), etc
  if original_branch.start_with? '('
    detached_branch = git.log(1).first.sha
    git.branch(original_branch = tmp_branch).checkout
  end

  # work in a branch, then revert to current branch
  git.branch(@branch).checkout
  add_and_commit_site @site_path
  git.push(@repo, @branch)

  if detached_branch
    git.checkout detached_branch
    git.branch(original_branch).delete
  else
    git.checkout original_branch
  end
end