Skip to content

Commit

Permalink
better errors for Repo.new
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Oct 20, 2007
1 parent 1fddfab commit 4ea50f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/grit/errors.rb
@@ -1,4 +1,7 @@
module Grit
class InvalidGitRepositoryError < StandardError
end

class NoSuchPathError < StandardError
end
end
4 changes: 3 additions & 1 deletion lib/grit/repo.rb
Expand Up @@ -23,8 +23,10 @@ def initialize(path)
elsif File.exist?(path) && path =~ /\.git$/
self.path = path
@bare = true
elsif File.exist?(path)
raise InvalidGitRepositoryError.new(path)
else
raise InvalidGitRepositoryError.new(path) unless File.exist?(path)
raise NoSuchPathError.new(path)
end

self.git = Git.new(self.path)
Expand Down
8 changes: 7 additions & 1 deletion test/test_repo.rb
Expand Up @@ -9,7 +9,13 @@ def setup

def test_new_should_raise_on_invalid_repo_location
assert_raise(InvalidGitRepositoryError) do
Repo.new("")
Repo.new("/tmp")
end
end

def test_new_should_raise_on_non_existant_path
assert_raise(NoSuchPathError) do
Repo.new("/foobar")
end
end

Expand Down

0 comments on commit 4ea50f4

Please sign in to comment.