libgit2 / libgit2/rugged

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

Open
#754 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
2.3k
Forks
293
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/relaxo/database.rb:48 and the failing example in spec/relaxo/database_spec.rb, then compare Rugged::Repository#head with the linked API documentation for a newly created repository. Done means the empty-repository behavior is defined and the clear! expectation no longer raises unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.