Detect if we didn't create the ref sooner

This commit is contained in:
Lin Jen-Shin 2017-08-09 17:55:53 +08:00
parent cb30868924
commit 029fb98b02
2 changed files with 25 additions and 1 deletions

View file

@ -999,7 +999,7 @@ class Repository
yield(commit(branch_name_or_sha)) yield(commit(branch_name_or_sha))
ensure ensure
rugged.references.delete(tmp_ref) if tmp_ref rugged.references.delete(tmp_ref) if tmp_ref && ref_exists?(tmp_ref)
end end
def add_remote(name, url) def add_remote(name, url)
@ -1022,6 +1022,9 @@ class Repository
def fetch_ref(source_path, source_ref, target_ref) def fetch_ref(source_path, source_ref, target_ref)
args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref}) args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref})
run_git(args) run_git(args)
# Make sure ref was created, and raise Rugged::ReferenceError when not
raise Rugged::ReferenceError unless ref_exists?(target_ref)
end end
def create_ref(ref, ref_path) def create_ref(ref, ref_path)

View file

@ -961,6 +961,27 @@ describe Repository, models: true do
end end
end end
context 'when temporary ref failed to be created from other project' do
let(:target_project) { create(:project, :empty_repo) }
before do
expect(target_project.repository).to receive(:run_git)
end
it 'raises Rugged::ReferenceError' do
raise_reference_error = raise_error(Rugged::ReferenceError) do |err|
expect(err.cause).to be_nil
end
expect do
GitOperationService.new(user, target_project.repository)
.with_branch('feature',
start_project: project,
&:itself)
end.to raise_reference_error
end
end
context 'when the update adds more than one commit' do context 'when the update adds more than one commit' do
let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' } let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' }