Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete feature #90

Merged
merged 3 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
test
"""
Given I run `cat modules/puppet-test/test`
Expand Down Expand Up @@ -89,7 +89,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files changed:\s+
Files changed:
+diff --git a/Gemfile b/Gemfile
"""
Given I run `cat modules/puppet-test/Gemfile`
Expand Down Expand Up @@ -124,7 +124,7 @@ Feature: update
When I run `msync update --noop`
Then the output should not match:
"""
Files changed:\s+
Files changed:
+diff --git a/Gemfile b/Gemfile
"""
And the output should match:
Expand All @@ -138,6 +138,38 @@ Feature: update
source 'https://rubygems.org'
"""

Scenario: Setting an existing file to deleted
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:
"""
---
Gemfile:
delete: true
"""
And a directory named "moduleroot"
And a file named "moduleroot/Gemfile" with:
"""
source '<%= @configs['gem_source'] %>'
"""
When I run `msync update --noop`
Then the output should match:
"""
Files changed:
diff --git a/Gemfile b/Gemfile
deleted file mode 100644
"""
And the exit status should be 0

Scenario: Setting a directory to unmanaged
Given a file named "managed_modules.yml" with:
"""
Expand Down Expand Up @@ -207,7 +239,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
spec/spec_helper.rb
"""
Given I run `cat modules/puppet-test/spec/spec_helper.rb`
Expand Down Expand Up @@ -287,7 +319,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
spec/spec_helper.rb
"""

Expand All @@ -306,9 +338,7 @@ Feature: update
And a directory named "moduleroot"
When I run `msync update --noop`
Then the exit status should be 0
And the output should not match /Files changed\s+/
And the output should not match /Files added\s+/
And the output should not match /Files deleted\s+/
And the output should not match /diff/

Scenario: When specifying configurations in managed_modules.yml
Given a file named "managed_modules.yml" with:
Expand Down Expand Up @@ -338,7 +368,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
test
"""
Given I run `cat modules/puppet-test/test`
Expand Down Expand Up @@ -373,7 +403,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
test
"""
Given I run `cat modules/puppet-test/test`
Expand Down Expand Up @@ -409,7 +439,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
test
"""
Given I run `cat modules/puppet-test/test`
Expand Down Expand Up @@ -495,7 +525,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files added:\s+
Files added:
test
"""
Given I run `cat modules/puppet-test/.git/config`
Expand Down Expand Up @@ -529,7 +559,7 @@ Feature: update
Then the exit status should be 0
And the output should match:
"""
Files changed:\s+
Files changed:
+diff --git a/README.md b/README.md
"""
Given I run `cat modules/puppet-test/README.md`
Expand Down
4 changes: 2 additions & 2 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def self.manage_file(filename, settings, options)
module_name = settings.additional_settings[:puppet_module]
configs = settings.build_file_configs(filename)
if configs['delete']
Renderer.remove(module_file(options['project_root'], module_name, filename))
Renderer.remove(module_file(options[:project_root], module_name, filename))
else
templatename = local_file(options[:configs], filename)
begin
erb = Renderer.build(templatename)
template = Renderer.render(erb, configs)
Renderer.sync(template, "#{options[:project_root]}/#{module_name}/#{filename}")
Renderer.sync(template, module_file(options[:project_root], module_name, filename))
rescue
STDERR.puts "Error while rendering #{filename}"
raise
Expand Down
4 changes: 2 additions & 2 deletions lib/modulesync/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def self.update_noop(name, options)
repo = ::Git.open("#{options[:project_root]}/#{name}")
repo.branch(options[:branch]).checkout

puts 'Files changed: '
puts 'Files changed:'
repo.diff('HEAD', '--').each do |diff|
puts diff.patch
end

puts 'Files added: '
puts 'Files added:'
untracked_unignored_files(repo).each do |file, _|
puts file
end
Expand Down