Skip to content

Commit

Permalink
Fix issue #81
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Oct 8, 2021
1 parent 98fe295 commit aa98927
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions features/step_definitions/git_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.tags).not_to include(tag)
end

Given 'the branch {string} of the puppet module {string} from {string} is deleted' do |branch, name, namespace|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.delete_branch(branch)
end
22 changes: 22 additions & 0 deletions features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -755,3 +755,25 @@ Feature: update
workdir: modules/fakenamespace/puppet-test
"""
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"

# This reproduces the issue: https://github.com/voxpupuli/modulesync/issues/81
Scenario: Resync repositories after upstream branch deletion
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a directory named "moduleroot"
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update -m "No changes!" --branch delete-me`
Then the exit status should be 0
And the puppet module "puppet-test" from "fakenamespace" should have 1 commit made by "Aruba" in branch "delete-me"
When the branch "delete-me" of the puppet module "puppet-test" from "fakenamespace" is deleted
And I run `msync update -m "No changes!" --branch delete-me`
Then the exit status should be 0
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"
2 changes: 1 addition & 1 deletion lib/modulesync/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def prepare_workspace(branch)
Dir.chdir(@directory) do
puts "Overriding any local changes to repository in '#{@directory}'"
@git = Git.open('.')
repo.fetch
repo.fetch 'origin', prune: true
repo.reset_hard
switch_branch(branch)
git.pull('origin', branch) if remote_branch_exists?(branch)
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/faker/puppet_module_remote_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def tags
end
end

def delete_branch(branch)
FileUtils.chdir(bare_repo_dir) do
run %W{git branch -D #{branch}}
end
end

def remote_url
"file://#{bare_repo_dir}"
end
Expand Down

0 comments on commit aa98927

Please sign in to comment.