diff --git a/features/step_definitions/git_steps.rb b/features/step_definitions/git_steps.rb index 0a50ed5d..b68705eb 100644 --- a/features/step_definitions/git_steps.rb +++ b/features/step_definitions/git_steps.rb @@ -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 diff --git a/features/update.feature b/features/update.feature index f264bee9..c04f1dfe 100644 --- a/features/update.feature +++ b/features/update.feature @@ -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" diff --git a/lib/modulesync/repository.rb b/lib/modulesync/repository.rb index 0d919c4c..48a0ce40 100644 --- a/lib/modulesync/repository.rb +++ b/lib/modulesync/repository.rb @@ -70,7 +70,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) diff --git a/spec/helpers/faker/puppet_module_remote_repo.rb b/spec/helpers/faker/puppet_module_remote_repo.rb index 81660402..5e59e4a4 100644 --- a/spec/helpers/faker/puppet_module_remote_repo.rb +++ b/spec/helpers/faker/puppet_module_remote_repo.rb @@ -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