libgit2/rugged — Issue #38: Reference.lookup should be kinder about missing refs
Author: quirkey
Created: 2012-01-07 00:30:29+00:00
State: open

Currently if you try to lookup a ref that doesnt exist it raises a generic `RuntimeError`

```
ruby-1.9.2-p290 :003 > Rugged::Reference.lookup(repo, "refs/heads/blah")
RuntimeError: Failed to lookup reference
- Reference not found
(error code -3)
from (irb):3:in `lookup'
from (irb):3
from /Users/aaronquint/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `

'
```

This is problematic as 1) it makes it hard to rescue safely and 2) theres no way to cleanly check for the existence of a ref.

Talking to @brianmario, there are a couple ways to approach:

- Raise a specific error class like `Rugged::RefNotFound` or similar
- Add an `Rugged::Reference.exists(repo, ref)` method that always returns a boolean
- Make `.lookup()` return nil if the reference isn't found