Class: GithubBitbucketDeployer::Git
- Inherits:
-
Object
- Object
- GithubBitbucketDeployer::Git
- Defined in:
- lib/github_bitbucket_deployer/git.rb
Instance Attribute Summary collapse
-
#bitbucket_repo_url ⇒ Object
readonly
Returns the value of attribute bitbucket_repo_url.
-
#git_repo_name ⇒ Object
readonly
Returns the value of attribute git_repo_name.
-
#id_rsa ⇒ Object
readonly
Returns the value of attribute id_rsa.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#repo_dir ⇒ Object
readonly
Returns the value of attribute repo_dir.
Instance Method Summary collapse
- #add_remote(remote = 'bitbucket') ⇒ Object
- #clone ⇒ Object
- #folder ⇒ Object
-
#initialize(options) ⇒ Git
constructor
A new instance of Git.
- #open ⇒ Object
- #pull ⇒ Object
- #push(remote, branch) ⇒ Object
- #push_app_to_bitbucket(remote = 'bitbucket', branch = 'master') ⇒ Object
- #repo ⇒ Object
Constructor Details
#initialize(options) ⇒ Git
Returns a new instance of Git.
10 11 12 13 14 15 16 |
# File 'lib/github_bitbucket_deployer/git.rb', line 10 def initialize() @bitbucket_repo_url = [:bitbucket_repo_url] @git_repo_name = [:git_repo_name] @id_rsa = [:id_rsa] @logger = [:logger] @repo_dir = [:repo_dir] end |
Instance Attribute Details
#bitbucket_repo_url ⇒ Object (readonly)
Returns the value of attribute bitbucket_repo_url.
8 9 10 |
# File 'lib/github_bitbucket_deployer/git.rb', line 8 def bitbucket_repo_url @bitbucket_repo_url end |
#git_repo_name ⇒ Object (readonly)
Returns the value of attribute git_repo_name.
8 9 10 |
# File 'lib/github_bitbucket_deployer/git.rb', line 8 def git_repo_name @git_repo_name end |
#id_rsa ⇒ Object (readonly)
Returns the value of attribute id_rsa.
8 9 10 |
# File 'lib/github_bitbucket_deployer/git.rb', line 8 def id_rsa @id_rsa end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/github_bitbucket_deployer/git.rb', line 8 def logger @logger end |
#repo_dir ⇒ Object (readonly)
Returns the value of attribute repo_dir.
8 9 10 |
# File 'lib/github_bitbucket_deployer/git.rb', line 8 def repo_dir @repo_dir end |
Instance Method Details
#add_remote(remote = 'bitbucket') ⇒ Object
55 56 57 58 59 |
# File 'lib/github_bitbucket_deployer/git.rb', line 55 def add_remote(remote = 'bitbucket') logger.info("git add_remote: #{remote}") repo.remote(remote).remove if repo.remote(remote).url repo.add_remote(remote, bitbucket_repo_url) end |
#clone ⇒ Object
33 34 35 36 |
# File 'lib/github_bitbucket_deployer/git.rb', line 33 def clone logger.info("git clone: cloning #{bitbucket_repo_url} to #{folder}") run { ::Git.clone(bitbucket_repo_url, folder, log: logger) } end |
#folder ⇒ Object
29 30 31 |
# File 'lib/github_bitbucket_deployer/git.rb', line 29 def folder @folder ||= setup_folder end |
#open ⇒ Object
44 45 46 47 |
# File 'lib/github_bitbucket_deployer/git.rb', line 44 def open logger.info('git open') ::Git.open(folder, log: logger) end |
#pull ⇒ Object
38 39 40 41 42 |
# File 'lib/github_bitbucket_deployer/git.rb', line 38 def pull logger.info("git pull: pulling from #{folder}") run { open.pull } open end |
#push(remote, branch) ⇒ Object
49 50 51 52 53 |
# File 'lib/github_bitbucket_deployer/git.rb', line 49 def push(remote, branch) logger.info("git push: deploying #{repo.dir} to " \ "#{repo.remote(remote).url} from branch #{branch}") run { repo.push(remote, branch, force: true) } end |
#push_app_to_bitbucket(remote = 'bitbucket', branch = 'master') ⇒ Object
18 19 20 21 22 23 |
# File 'lib/github_bitbucket_deployer/git.rb', line 18 def push_app_to_bitbucket(remote = 'bitbucket', branch = 'master') logger.info('push_app_to_bitbucket') add_remote(remote) with_ssh { yield(repo) } if block_given? push(remote, branch) end |
#repo ⇒ Object
25 26 27 |
# File 'lib/github_bitbucket_deployer/git.rb', line 25 def repo @repo ||= setup_repo end |