diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index 1fe42b884..8c739e67b 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -39,21 +39,23 @@ module VagrantPlugins excludes += Array(opts[:exclude]).map(&:to_s) if opts[:exclude] excludes.uniq! + # Get the command-line arguments + args = nil + args = Array(opts[:args]) if opts[:args] + args ||= ["--verbose", "--archive", "--delete", "-z"] + # Build up the actual command to execute command = [ "rsync", - "--verbose", - "--archive", - "--delete", - "-z", - excludes.map { |e| ["--exclude", e] }, + args, "-e", rsh, + excludes.map { |e| ["--exclude", e] }, hostpath, - "#{username}@#{host}:#{guestpath}" + "#{username}@#{host}:#{guestpath}", ].flatten - command_opts = {} # The working directory should be the root path + command_opts = {} command_opts[:workdir] = machine.env.root_path.to_s machine.ui.info(I18n.t( diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 0230bf343..9f84d754f 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -151,5 +151,34 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do subject.rsync_single(machine, ssh_info, opts) end end + + context "custom arguments" do + it "uses the default arguments if not given" do + Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(args[1]).to eq("--verbose") + expect(args[2]).to eq("--archive") + expect(args[3]).to eq("--delete") + + expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s + expect(args[args.length - 3]).to eql("#{expected}/") + end + + subject.rsync_single(machine, ssh_info, opts) + end + + it "uses the custom arguments if given" do + opts[:args] = ["--verbose", "-z"] + + Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + expect(args[1]).to eq("--verbose") + expect(args[2]).to eq("-z") + + expected = Vagrant::Util::Platform.fs_real_path("/foo").to_s + expect(args[args.length - 3]).to eql("#{expected}/") + end + + subject.rsync_single(machine, ssh_info, opts) + end + end end end diff --git a/website/docs/source/v2/synced-folders/rsync.html.md b/website/docs/source/v2/synced-folders/rsync.html.md index 4f3e1db4a..0d99c5364 100644 --- a/website/docs/source/v2/synced-folders/rsync.html.md +++ b/website/docs/source/v2/synced-folders/rsync.html.md @@ -39,6 +39,9 @@ it will tell you. The rsync synced folder type accepts the following options: +* `rsync__args` (string or array of strings) - A list of arguments to supply + to `rsync`. By default this is "--verbose --archive --delete -z". + * `rsync__exclude` (string or array of strings) - A list of files or directories to exclude from the sync. The values can be any acceptable rsync exclude pattern. By default, the ".vagrant/" directory is excluded. We recommend