Commit 029fb98b authored by Lin Jen-Shin's avatar Lin Jen-Shin

Detect if we didn't create the ref sooner

parent cb308689
......@@ -999,7 +999,7 @@ class Repository
yield(commit(branch_name_or_sha))
ensure
rugged.references.delete(tmp_ref) if tmp_ref
rugged.references.delete(tmp_ref) if tmp_ref && ref_exists?(tmp_ref)
end
def add_remote(name, url)
......@@ -1022,6 +1022,9 @@ class Repository
def fetch_ref(source_path, source_ref, target_ref)
args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref})
run_git(args)
# Make sure ref was created, and raise Rugged::ReferenceError when not
raise Rugged::ReferenceError unless ref_exists?(target_ref)
end
def create_ref(ref, ref_path)
......
......@@ -961,6 +961,27 @@ describe Repository, models: true do
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
let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment