Permalink
Browse files

Added :git_upload_pack parameter

When using a repository server with SSH where the git command is not in
the path, the command fails.

This patch adds the configuration option :git_upload_pack which adds
the --upload-pack parameter for all relevant commands.
  • Loading branch information...
1 parent e82de1c commit 4de5d1dd18e3dd422b5c137cad7a695d129255d7 Gabriel Birke committed Jun 14, 2012
Showing with 15 additions and 6 deletions.
  1. +11 −2 lib/capistrano/recipes/deploy/scm/git.rb
  2. +4 −4 test/deploy/scm/git_test.rb
@@ -138,6 +138,7 @@ def checkout(revision, destination)
if depth = variable(:git_shallow_clone)
args << "--depth #{depth}"
end
+ args << upload_pack if upload_pack
execute = []
execute << "#{git} clone #{verbose} #{args.join(' ')} #{variable(:repository)} #{destination}"
@@ -186,7 +187,7 @@ def sync(revision, destination)
end
# since we're in a local branch already, just reset to specified revision rather than merge
- execute << "#{git} fetch #{verbose} #{remote} && #{git} fetch --tags #{verbose} #{remote} && #{git} reset #{verbose} --hard #{revision}"
+ execute << "#{git} fetch #{upload_pack} #{verbose} #{remote} && #{git} fetch --tags #{upload_pack} #{verbose} #{remote} && #{git} reset #{verbose} --hard #{revision}"
if variable(:git_enable_submodules)
execute << "#{git} submodule #{verbose} init"
@@ -223,7 +224,11 @@ def log(from, to=nil)
def query_revision(revision)
raise ArgumentError, "Deploying remote branches is no longer supported. Specify the remote branch as a local branch for the git repository you're deploying from (ie: '#{revision.gsub('origin/', '')}' rather than '#{revision}')." if revision =~ /^origin\//
return revision if revision =~ /^[0-9a-f]{40}$/
- command = scm('ls-remote', repository, revision)
+ remote_args = [repository, revision]
+ if upload_pack
+ remote_args.unshift(upload_pack)
+ end
+ command = scm('ls-remote', *remote_args)
result = yield(command)
revdata = result.split(/[\t\n]/)
newrev = nil
@@ -284,6 +289,10 @@ def handle_data(state, stream, text)
def verbose
variable(:scm_verbose) ? nil : "-q"
end
+
+ def upload_pack
+ variable(:git_upload_pack) ? "--upload-pack=#{variable(:git_upload_pack)}" : nil
+ end
end
end
end
@@ -118,16 +118,16 @@ def test_command_should_be_backwards_compatible
def test_sync
dest = "/var/www"
rev = 'c2d9e79'
- assert_equal "cd #{dest} && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
+ assert_equal "cd #{dest} && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
# With :scm_command
git = "/opt/local/bin/git"
@config[:scm_command] = git
- assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} clean -q -d -x -f", @source.sync(rev, dest)
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} clean -q -d -x -f", @source.sync(rev, dest)
# with submodules
@config[:git_enable_submodules] = true
- assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && for mod in `#{git} submodule status | awk '{ print $2 }'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE && #{git} clean -q -d -x -f", @source.sync(rev, dest)
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && for mod in `#{git} submodule status | awk '{ print $2 }'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE && #{git} clean -q -d -x -f", @source.sync(rev, dest)
end
def test_sync_with_remote
@@ -139,7 +139,7 @@ def test_sync_with_remote
@config[:repository] = repository
@config[:remote] = remote
- assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch -q #{remote} && git fetch --tags -q username && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
+ assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch -q #{remote} && git fetch --tags -q username && git reset -q --hard #{rev} && git clean -q -d -x -f", @source.sync(rev, dest)
end
def test_shallow_clone

0 comments on commit 4de5d1d

Please sign in to comment.