rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Repository#head throws exception, but documentation seems to imply it should return nil?

Open ioquatix opened this issue 7 years ago • 1 comments

I have to do the following

		# Completely clear out the database.
		def clear!
			if head = @repository.head
				@repository.references.delete(head)
			end
		rescue Rugged::ReferenceError
			return nil
		end

@repository.head on a newly created repo throws:

 1) Relaxo::Database can clear database
     Failure/Error:
       expect do
       	database.clear!
       end.to_not raise_error
     
       expected no Exception, got #<Rugged::ReferenceError: reference 'refs/heads/master' not found> with backtrace:
         # ./lib/relaxo/database.rb:48:in `head'
         # ./lib/relaxo/database.rb:48:in `clear!'
         # ./spec/relaxo/database_spec.rb:20:in `block (3 levels) in <top (required)>'

The documentation seems to imply this should return nil?

https://www.rubydoc.info/github/libgit2/rugged/Rugged%2FRepository:head

Thanks!

ioquatix avatar Jun 30 '18 05:06 ioquatix

This implementation seemed to work more robustly for me and my use case:

		# Completely clear out the database.
		def clear!
			if head = @repository.branches[@branch]
				@repository.references.delete(head)
			end
		end

ioquatix avatar Jun 30 '18 08:06 ioquatix