diff --git a/features/update.feature b/features/update.feature index d51475b3..d9f282fc 100644 --- a/features/update.feature +++ b/features/update.feature @@ -97,6 +97,40 @@ Feature: update Given I run `cat modules/puppet-test/test` Then the output should contain "aruba" + Scenario: Adding 2 files, with the same basename + Given a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + git_base: https://github.com/ + """ + And a file named "config_defaults.yml" with: + """ + --- + test.erb: + name: aruba + """ + And a directory named "moduleroot" + And a file named "moduleroot/test" with: + """ + <%= @configs['name'] %> + """ + And a file named "moduleroot/test.erb" with: + """ + <%= @configs['name'] %> + """ + When I run `msync update --noop` + Then the exit status should be 0 + And the output should match: + """ + Collision: You cannot have 2 files in ./moduleroot/ with the same basename + """ + Scenario: Adding a new file using global values Given a file named "managed_modules.yml" with: """ diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 2aadf1c2..e54dc991 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -31,8 +31,14 @@ def self.module_file(project_root, puppet_module, file) def self.local_files(path) if File.exist?(path) - # only select *.erb files, and strip the extension. This way all the code will only have to handle bare paths, except when reading the actual ERB text - local_files = Find.find(path).find_all { |p| p =~ /.erb$/ && !File.directory?(p) }.collect { |p| p.chomp('.erb') }.to_a + # select all files. *.erb files strip the extension. This way all the code will only have to handle bare paths, except when reading the actual ERB text + local_files = Find.find(path).find_all { |p| !File.directory?(p) }.collect { |p| p.chomp('.erb') }.to_a + duplicates = local_files.find_all { |e| local_files.rindex(e) != local_files.index(e) }.uniq + unless duplicates.empty? + puts "Collision: You cannot have 2 files in #{path} with the same basename eg '#{path}example.erb' and '#{path}example'. The offending basenames: #{duplicates}." + exit + end + local_files else puts "#{path} does not exist. Check that you are working in your module configs directory or that you have passed in the correct directory with -c." exit