Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

raise ArgumentError if specified path is not a Git repository

  • Loading branch information...
commit 738dfa6fb3eafc48529f78acebb2a8c0b0e48fc2 1 parent f1b6cdd
Nick Plante authored
Showing with 15 additions and 1 deletion.
  1. +7 −0 lib/git_store.rb
  2. +8 −1 test/git_store_spec.rb
7 lib/git_store.rb
View
@@ -45,10 +45,16 @@ def initialize(path, branch = 'master')
@root = Tree.new(self)
@packs = {}
+ raise(ArgumentError, "first argument must be a valid Git repository") unless valid?
+
load_packs("#{path}/.git/objects/pack")
load
end
+ def valid?
+ File.exists?("#{path}/.git")
+ end
+
# The path to the current head file.
def head_path
"#{path}/.git/refs/heads/#{branch}"
@@ -284,6 +290,7 @@ class FileStore < GitStore
def initialize(path)
@mtime = {}
super
+ rescue ArgumentError
end
def load
9 test/git_store_spec.rb
View
@@ -2,7 +2,8 @@
describe GitStore do
- REPO = File.expand_path(File.dirname(__FILE__) + '/repo')
+ #REPO = File.expand_path(File.dirname(__FILE__) + '/repo')
+ REPO = '/tmp/git_store_test'
before(:each) do
FileUtils.rm_rf REPO
@@ -200,4 +201,10 @@ def file(file, data)
it_should_behave_like 'all stores'
end
+
+ it 'should fail to initialize without a valid git repository' do
+ lambda {
+ GitStore.new(REPO)
+ }.should raise_error(ArgumentError)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.