Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #41 from nkammah/git_clone_fix
Browse files Browse the repository at this point in the history
use the real checkout_path for git clone and fix the cmd for all methods
  • Loading branch information
juliettepaul committed Feb 23, 2015
2 parents 3e11ccc + 613ea5d commit 585e88b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/deployinator/helpers/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ module GitHelpers
# How many seconds the head rev cache is good for
@@rev_head_cache_ttl = 15

def build_git_cmd(cmd, extra_cmd)
unless extra_cmd.nil? or extra_cmd.empty?
"#{extra_cmd} '#{cmd}'"
else
cmd
end
end

# Public: method to get the short rev of a git commit and create a
# version tag from it. The tag is then dumped into a version text file.
#
Expand All @@ -39,7 +47,7 @@ def git_bump_version(stack, version_dir, extra_cmd="", path=nil, rev="HEAD", tee
path ||= git_checkout_path(checkout_root, stack)

cmd = "cd #{path} && git rev-parse --short=#{Deployinator.git_sha_length} #{rev}"
cmd = "#{extra_cmd} '#{cmd}'" if extra_cmd
cmd = build_git_cmd(cmd, extra_cmd)
sha1 = run_cmd(cmd)[:stdout]

version = "#{sha1.chomp}-#{ts}"
Expand All @@ -53,7 +61,7 @@ def git_bump_version(stack, version_dir, extra_cmd="", path=nil, rev="HEAD", tee
log_and_stream "Setting #{fullpaths} to #{version}"

cmd = "cd #{path} && echo #{version} | #{tee_cmd} #{fullpaths}"
cmd = "#{extra_cmd} '#{cmd}'" if extra_cmd
cmd = build_git_cmd(cmd, extra_cmd)
run_cmd cmd

return version
Expand Down Expand Up @@ -88,7 +96,7 @@ def git_checkout_path(checkout_root, stack)
def git_freshen_clone(stack, extra_cmd="", path=nil, branch="master")
path ||= git_checkout_path(checkout_root, stack)
cmd = "cd #{path} && git fetch --quiet origin +refs/heads/#{branch}:refs/remotes/origin/#{branch} && git reset --hard origin/#{branch} 2>&1"
cmd = "#{extra_cmd} '#{cmd}'" if extra_cmd
cmd = build_git_cmd(cmd, extra_cmd)
run_cmd cmd
yield "#{path}" if block_given?
end
Expand Down Expand Up @@ -140,7 +148,7 @@ def git_filter_shas(stack, extra_cmd, old_rev, new_rev, path=nil, filter_files=[
including_shas = []
excluding_shas = []
cmd = "cd #{path} && git log --no-merges --name-only --pretty=format:%H #{old_rev}..#{new_rev}"
cmd = "#{extra_cmd} '#{cmd}'" if extra_cmd
cmd = build_git_cmd(cmd, extra_cmd)
committers = run_cmd(cmd)[:stdout]
committers.split(/\n\n/).each { |commit|
lines = commit.split(/\n/)
Expand Down Expand Up @@ -213,8 +221,9 @@ def get_git_head_rev(stack, branch='master', protocol='git')
#
# Returns nothing
def git_clone(stack, repo_url, extra_cmd="", checkout_root=checkout_root, branch='master')
cmd = "cd #{checkout_root} && git clone #{repo_url} -b #{branch} #{stack}"
cmd = "#{extra_cmd} '#{cmd}'" if extra_cmd
path = git_checkout_path(checkout_root, stack)
cmd = "git clone #{repo_url} -b #{branch} #{path}"
cmd = build_git_cmd(cmd, extra_cmd)
run_cmd cmd
end

Expand Down

0 comments on commit 585e88b

Please sign in to comment.