Module: Heroploy::Commands::Git
- Included in:
- Tasks::CheckTaskLib, Tasks::DeployTaskLib, Tasks::EnvTaskLib
- Defined in:
- lib/heroploy/commands/git.rb
Instance Method Summary collapse
- #current_branch ⇒ Object
- #git_clone(repository, destination) ⇒ Object
- #git_fetch ⇒ Object
- #git_push_tag(tag) ⇒ Object
- #git_push_to_master(remote, local_branch) ⇒ Object
- #git_remote_behind?(remote, remote_branch_name, local_branch_name = nil) ⇒ Boolean
- #git_remote_exists?(name) ⇒ Boolean
- #git_remote_has_branch?(remote, branch_name) ⇒ Boolean
- #git_staged?(remote, local_branch) ⇒ Boolean
- #git_tag(tag, message) ⇒ Object
Instance Method Details
#current_branch ⇒ Object
10 11 12 13 |
# File 'lib/heroploy/commands/git.rb', line 10 def current_branch branch = Shell.eval "git rev-parse --abbrev-ref HEAD" branch.strip end |
#git_clone(repository, destination) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/heroploy/commands/git.rb', line 47 def git_clone(repository, destination) Dir.mktmpdir do |dir| Dir.chdir(dir) do Shell.exec("git clone #{repository} #{destination}") if block_given? yield end end end end |
#git_fetch ⇒ Object
6 7 8 |
# File 'lib/heroploy/commands/git.rb', line 6 def git_fetch Shell.exec "git fetch" end |
#git_push_tag(tag) ⇒ Object
43 44 45 |
# File 'lib/heroploy/commands/git.rb', line 43 def git_push_tag(tag) Shell.exec("git push origin #{tag}") end |
#git_push_to_master(remote, local_branch) ⇒ Object
15 16 17 18 |
# File 'lib/heroploy/commands/git.rb', line 15 def git_push_to_master(remote, local_branch) if ENV['force'] == 'true' then opts = "--force " end Shell.exec "git push #{opts}#{remote} #{local_branch}:master" end |
#git_remote_behind?(remote, remote_branch_name, local_branch_name = nil) ⇒ Boolean
30 31 32 33 |
# File 'lib/heroploy/commands/git.rb', line 30 def git_remote_behind?(remote, remote_branch_name, local_branch_name = nil) if local_branch_name.nil? then local_branch_name = remote_branch_name end !Shell.eval("git log #{remote}/#{remote_branch_name}..#{local_branch_name}").empty? end |
#git_remote_exists?(name) ⇒ Boolean
20 21 22 23 |
# File 'lib/heroploy/commands/git.rb', line 20 def git_remote_exists?(name) remotes = Shell.eval("git remote").strip.split(/\s+/) remotes.include?(name) end |
#git_remote_has_branch?(remote, branch_name) ⇒ Boolean
25 26 27 28 |
# File 'lib/heroploy/commands/git.rb', line 25 def git_remote_has_branch?(remote, branch_name) branches = Shell.eval("git branch -r").strip.split(/\s+/) branches.include?("#{remote}/#{branch_name}") end |
#git_staged?(remote, local_branch) ⇒ Boolean
35 36 37 |
# File 'lib/heroploy/commands/git.rb', line 35 def git_staged?(remote, local_branch) !git_remote_behind?(remote, 'master', local_branch) end |