Class: GithubHerokuDeployer::Git
- Inherits:
-
Object
- Object
- GithubHerokuDeployer::Git
- Defined in:
- lib/github_heroku_deployer/git.rb
Instance Method Summary collapse
- #clone ⇒ Object
- #clone_or_pull ⇒ Object
- #exists_locally? ⇒ Boolean
- #folder ⇒ Object
- #id_rsa_path ⇒ Object
-
#initialize(options) ⇒ Git
constructor
A new instance of Git.
- #open ⇒ Object
- #pull ⇒ Object
- #push_app_to_heroku(remote = "heroku", branch = "master", &block) ⇒ Object
- #repo ⇒ Object
- #run(command) ⇒ Object
- #setup_folder ⇒ Object
- #setup_repo ⇒ Object
- #ssh_wrapper ⇒ Object
Constructor Details
#initialize(options) ⇒ Git
Returns a new instance of Git.
7 8 9 10 11 12 13 |
# File 'lib/github_heroku_deployer/git.rb', line 7 def initialize() @heroku_repo = [:heroku_repo] @github_repo = [:github_repo] @id_rsa = [:id_rsa] @logger = [:logger] @repo_dir = [:repo_dir] end |
Instance Method Details
#clone ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/github_heroku_deployer/git.rb', line 53 def clone wrapper = ssh_wrapper @logger.info "cloning #{@github_repo} to #{folder}" run "env #{wrapper.git_ssh} git clone #{@github_repo} #{folder}" ensure wrapper.unlink end |
#clone_or_pull ⇒ Object
45 46 47 |
# File 'lib/github_heroku_deployer/git.rb', line 45 def clone_or_pull !exists_locally? ? clone : pull end |
#exists_locally? ⇒ Boolean
49 50 51 |
# File 'lib/github_heroku_deployer/git.rb', line 49 def exists_locally? File.exists?(File.join(folder, ".git", "config")) end |
#folder ⇒ Object
35 36 37 |
# File 'lib/github_heroku_deployer/git.rb', line 35 def folder @folder ||= setup_folder end |
#id_rsa_path ⇒ Object
78 79 80 81 82 83 |
# File 'lib/github_heroku_deployer/git.rb', line 78 def id_rsa_path file = Tempfile.new("id_rsa") file.write(@id_rsa) file.rewind file.path end |
#open ⇒ Object
70 71 72 |
# File 'lib/github_heroku_deployer/git.rb', line 70 def open ::Git.open(folder) end |
#pull ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/github_heroku_deployer/git.rb', line 61 def pull wrapper = ssh_wrapper dir = Dir.pwd # need to cd back to here @logger.info "pulling from #{folder}" run "cd #{folder}; env #{wrapper.git_ssh} git pull; cd #{dir}" ensure wrapper.unlink end |
#push_app_to_heroku(remote = "heroku", branch = "master", &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/github_heroku_deployer/git.rb', line 15 def push_app_to_heroku(remote="heroku", branch="master", &block) wrapper = ssh_wrapper run "cd #{repo.dir}; git remote rm #{remote}" if repo.remote(remote).url repo.add_remote(remote, @heroku_repo) yield(repo) if block_given? @logger.info "deploying #{repo.dir} to #{repo.remote(remote).url} from branch #{branch}" run "cd #{repo.dir}; env #{wrapper.git_ssh} git push -f #{remote} #{branch}" ensure wrapper.unlink end |
#repo ⇒ Object
26 27 28 |
# File 'lib/github_heroku_deployer/git.rb', line 26 def repo @repo ||= setup_repo end |
#run(command) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/github_heroku_deployer/git.rb', line 85 def run(command) result = `#{command} 2>&1` status = $?.exitstatus if status == 0 @logger.info result else raise GithubHerokuDeployer::CommandException, result end end |
#setup_folder ⇒ Object
39 40 41 42 43 |
# File 'lib/github_heroku_deployer/git.rb', line 39 def setup_folder folder = File.join(@repo_dir, Zlib.crc32(@github_repo).to_s) FileUtils.mkdir_p(folder) folder end |
#setup_repo ⇒ Object
30 31 32 33 |
# File 'lib/github_heroku_deployer/git.rb', line 30 def setup_repo clone_or_pull open end |
#ssh_wrapper ⇒ Object
74 75 76 |
# File 'lib/github_heroku_deployer/git.rb', line 74 def ssh_wrapper GitSSHWrapper.new(private_key_path: id_rsa_path) end |