rugged
rugged copied to clipboard
Repository#head throws exception, but documentation seems to imply it should return nil?
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!
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