From 60f3d224c93b79e8205b889e6a4b1861f16dcbe0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Jan 2014 18:01:38 -0800 Subject: [PATCH] synced_folders/rsync: can exclude files --- plugins/synced_folders/rsync/synced_folder.rb | 3 +- .../rsync/synced_folder_test.rb | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/plugins/synced_folders/rsync/synced_folder.rb b/plugins/synced_folders/rsync/synced_folder.rb index b8eba169a..c75c610d8 100644 --- a/plugins/synced_folders/rsync/synced_folder.rb +++ b/plugins/synced_folders/rsync/synced_folder.rb @@ -49,8 +49,9 @@ module VagrantPlugins # Exclude some files by default, and any that might be configured # by the user. - # TODO(mitchellh): allow the user to configure it excludes = ['.vagrant/'] + excludes += Array(opts[:exclude]) if opts[:exclude] + excludes.uniq! # Build up the actual command to execute command = [ diff --git a/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb b/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb index 61990b3ae..f544e5b44 100644 --- a/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb +++ b/test/unit/plugins/synced_folders/rsync/synced_folder_test.rb @@ -107,5 +107,35 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do subject.rsync_single(machine, ssh_info, opts) end + + context "excluding files" do + it "excludes files if given as a string" do + opts[:exclude] = "foo" + + Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + index = args.find_index("foo") + expect(index).to be > 0 + expect(args[index-1]).to eql("--exclude") + end + + subject.rsync_single(machine, ssh_info, opts) + end + + it "excludes multiple files" do + opts[:exclude] = ["foo", "bar"] + + Vagrant::Util::Subprocess.should_receive(:execute).with do |*args| + index = args.find_index("foo") + expect(index).to be > 0 + expect(args[index-1]).to eql("--exclude") + + index = args.find_index("bar") + expect(index).to be > 0 + expect(args[index-1]).to eql("--exclude") + end + + subject.rsync_single(machine, ssh_info, opts) + end + end end end