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 error when git upstream branch is deleted #240

Merged
merged 1 commit into from
Oct 8, 2021
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
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