From a50a4fc6c66deea830dc76419674c36ff380019c Mon Sep 17 00:00:00 2001 From: Edward Anderson Date: Thu, 22 Sep 2011 23:11:29 -0400 Subject: [PATCH] Check for git submodule --recursive support git submodule x --recursive is only supported after git 1.6.5. --- lib/capistrano/recipes/deploy/scm/git.rb | 6 ++++-- test/deploy/scm/git_test.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/capistrano/recipes/deploy/scm/git.rb b/lib/capistrano/recipes/deploy/scm/git.rb index 2ac2f4386..eac80477d 100644 --- a/lib/capistrano/recipes/deploy/scm/git.rb +++ b/lib/capistrano/recipes/deploy/scm/git.rb @@ -151,7 +151,8 @@ def checkout(revision, destination) if false == variable(:git_submodules_recursive) execute << "#{git} submodule #{verbose} update --init" else - execute << "#{git} submodule #{verbose} update --init --recursive" + execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive)) + execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE" end end @@ -194,7 +195,8 @@ def sync(revision, destination) if false == variable(:git_submodules_recursive) execute << "#{git} submodule #{verbose} update --init" else - execute << "#{git} submodule #{verbose} update --init --recursive" + execute << %Q(export GIT_RECURSIVE=$([ ! "`#{git} --version`" \\< "git version 1.6.5" ] && echo --recursive)) + execute << "#{git} submodule #{verbose} update --init $GIT_RECURSIVE" end end diff --git a/test/deploy/scm/git_test.rb b/test/deploy/scm/git_test.rb index fb55907d9..3ea7ecd35 100644 --- a/test/deploy/scm/git_test.rb +++ b/test/deploy/scm/git_test.rb @@ -40,7 +40,7 @@ def test_checkout # with submodules @config[:git_enable_submodules] = true - assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev} && #{git} submodule -q init && #{git} submodule -q sync && #{git} submodule -q update --init --recursive", @source.checkout(rev, dest).gsub(/\s+/, ' ') + assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev} && #{git} submodule -q init && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE", @source.checkout(rev, dest).gsub(/\s+/, ' ') end def test_checkout_with_verbose_should_not_use_q_switch @@ -118,7 +118,7 @@ def test_sync # 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 && #{git} submodule -q update --init --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 @@ -155,7 +155,7 @@ def test_remote_clone_with_submodules @config[:git_enable_submodules] = true dest = "/var/www" rev = 'c2d9e79' - assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && git submodule -q update --init --recursive", @source.checkout(rev, dest) + assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule -q update --init $GIT_RECURSIVE", @source.checkout(rev, dest) end # Tests from base_test.rb, makin' sure we didn't break anything up there!