Class: GithubBitbucketDeployer::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/github_bitbucket_deployer/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @bitbucket_repo_url = options[:bitbucket_repo_url]
  @git_repo_name = options[:git_repo_name]
  @id_rsa = options[:id_rsa]
  @logger = options[:logger]
  @repo_dir = options[:repo_dir]
end

Instance Attribute Details

#bitbucket_repo_urlObject (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_nameObject (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_rsaObject (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

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/github_bitbucket_deployer/git.rb', line 8

def logger
  @logger
end

#repo_dirObject (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

#cloneObject



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

#folderObject



29
30
31
# File 'lib/github_bitbucket_deployer/git.rb', line 29

def folder
  @folder ||= setup_folder
end

#openObject



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

#pullObject



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

#repoObject



25
26
27
# File 'lib/github_bitbucket_deployer/git.rb', line 25

def repo
  @repo ||= setup_repo
end