Class: Nanoc::Deploying::Deployers::Git Private

Inherits:
Nanoc::Deploying::Deployer show all
Defined in:
lib/nanoc/deploying/deployers/git.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A deployer that deploys a site using [Git](git-scm.com).

Examples:

A deployment configuration for GitHub Pages:


deploy:
  default:
    kind:       git
    remote:     [email protected]:myself/myproject.git
    branch:     gh-pages
    forced:     true

Defined Under Namespace

Modules: Errors

Instance Attribute Summary

Attributes inherited from Nanoc::Deploying::Deployer

#config, #dry_run, #source_path

Instance Method Summary collapse

Methods inherited from Nanoc::Deploying::Deployer

#initialize

Constructor Details

This class inherits a constructor from Nanoc::Deploying::Deployer

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/nanoc/deploying/deployers/git.rb', line 49

def run
  unless File.exist?(source_path)
    raise Errors::OutputDirDoesNotExist.new(source_path)
  end

  remote = config.fetch(:remote, 'origin')
  branch = config.fetch(:branch, 'master')
  forced = config.fetch(:forced, false)

  puts "Deploying via Git to branch “#{branch}” on remote “#{remote}”…"

  Dir.chdir(source_path) do
    unless File.exist?('.git')
      raise Errors::OutputDirIsNotAGitRepo.new(source_path)
    end

    # Verify existence of remote, if remote is not a URL
    if remote_is_name?(remote)
      begin
        run_cmd(%W[git config --get remote.#{remote}.url])
      rescue TTY::Command::ExitError
        raise Errors::RemoteDoesNotExist.new(remote)
      end
    end

    # If the branch exists then switch to it, otherwise prompt the user to create one.
    begin
      run_cmd_unless_dry(%W[git checkout #{branch}])
    rescue TTY::Command::ExitError
      raise Errors::BranchDoesNotExist.new(branch)
    end

    return if clean_repo?

    msg = "Automated commit at #{Time.now.utc} by Nanoc #{Nanoc::VERSION}"
    author = 'Nanoc <>'
    run_cmd_unless_dry(%w[git add -A])
    run_cmd_unless_dry(%W[git commit -a --author #{author} -m #{msg}])

    if forced
      run_cmd_unless_dry(%W[git push -f #{remote} #{branch}])
    else
      run_cmd_unless_dry(%W[git push #{remote} #{branch}])
    end
  end
end