diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b3325a..6b8a1198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ https://github.com/capistrano/capistrano/compare/v3.7.2...HEAD * [#1846](https://github.com/capistrano/capistrano/pull/1846): add_host will add a new host in a case where it used to incorrectly update an existing one (potentially breaking) [(@dbenamy)](https://github.com/dbenamy) * [capistrano-harrow#4](https://github.com/harrowio/capistrano-harrow/issues/4): Drop dependency on `capistrano-harrow` gem. Gem can still be installed separately [(@leehambley)](https://github.com/leehambley) * Run `svn switch` to work with svn branches if repo_url is changed +* [#1856](https://github.com/capistrano/capistrano/pull/1856): Fix hg repo_tree implementation - [@mattbrictson](https://github.com/mattbrictson) * Your contribution here! ## `3.7.2` (2017-01-27) diff --git a/lib/capistrano/scm/hg.rb b/lib/capistrano/scm/hg.rb index 3754e427..24709cd8 100644 --- a/lib/capistrano/scm/hg.rb +++ b/lib/capistrano/scm/hg.rb @@ -1,4 +1,5 @@ require "capistrano/scm/plugin" +require "securerandom" class Capistrano::SCM::Hg < Capistrano::SCM::Plugin def register_hooks @@ -36,7 +37,13 @@ class Capistrano::SCM::Hg < Capistrano::SCM::Plugin if (tree = fetch(:repo_tree)) tree = tree.slice %r#^/?(.*?)/?$#, 1 components = tree.split("/").size - hg "archive --type tgz -p . -I", tree, "--rev", fetch(:branch), "| tar -x --strip-components #{components} -f - -C", release_path + temp_tar = "#{fetch(:tmp_dir)}/#{SecureRandom.hex(10)}.tar" + + hg "archive -p . -I", tree, "--rev", fetch(:branch), temp_tar + + backend.execute :mkdir, "-p", release_path + backend.execute :tar, "-x --strip-components #{components} -f", temp_tar, "-C", release_path + backend.execute :rm, temp_tar else hg "archive", release_path, "--rev", fetch(:branch) end diff --git a/spec/lib/capistrano/scm/hg_spec.rb b/spec/lib/capistrano/scm/hg_spec.rb index c43fae3c..482d0867 100644 --- a/spec/lib/capistrano/scm/hg_spec.rb +++ b/spec/lib/capistrano/scm/hg_spec.rb @@ -85,8 +85,13 @@ module Capistrano env.set(:repo_tree, "tree") env.set(:branch, :branch) env.set(:release_path, "path") + env.set(:tmp_dir, "/tmp") - backend.expects(:execute).with(:hg, "archive --type tgz -p . -I", "tree", "--rev", :branch, "| tar -x --strip-components 1 -f - -C", "path") + SecureRandom.stubs(:hex).with(10).returns("random") + backend.expects(:execute).with(:hg, "archive -p . -I", "tree", "--rev", :branch, "/tmp/random.tar") + backend.expects(:execute).with(:mkdir, "-p", "path") + backend.expects(:execute).with(:tar, "-x --strip-components 1 -f", "/tmp/random.tar", "-C", "path") + backend.expects(:execute).with(:rm, "/tmp/random.tar") subject.archive_to_release_path end