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
17
# 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]
  @force = options.fetch(:force, true)
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

#forceObject (readonly)

Returns the value of attribute force.



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

def force
  @force
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



56
57
58
59
60
# File 'lib/github_bitbucket_deployer/git.rb', line 56

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



34
35
36
37
# File 'lib/github_bitbucket_deployer/git.rb', line 34

def clone
  logger.info("git clone: cloning #{bitbucket_repo_url} to #{folder}")
  run { ::Git.clone(bitbucket_repo_url, folder, log: logger) }
end

#folderObject



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

def folder
  @folder ||= setup_folder
end

#openObject



45
46
47
48
# File 'lib/github_bitbucket_deployer/git.rb', line 45

def open
  logger.info('git open')
  ::Git.open(folder, log: logger)
end

#pullObject



39
40
41
42
43
# File 'lib/github_bitbucket_deployer/git.rb', line 39

def pull
  logger.info("git pull: pulling from #{folder}")
  run { open.pull }
  open
end

#push(remote, branch) ⇒ Object



50
51
52
53
54
# File 'lib/github_bitbucket_deployer/git.rb', line 50

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: force) }
end

#push_app_to_bitbucket(remote = 'bitbucket', branch = 'master') ⇒ Object



19
20
21
22
23
24
# File 'lib/github_bitbucket_deployer/git.rb', line 19

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



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

def repo
  @repo ||= setup_repo
end