Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Find the repo more magically
  • Loading branch information
judofyr committed Sep 30, 2008
1 parent 082930f commit b307b9c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/gash.rb
Expand Up @@ -327,12 +327,10 @@ def __getobj__ #:nodoc:
attr_accessor :branch, :repository

# Opens the +repo+ with the specified +branch+.
#
# <b>Please note:</b> The +repo+ must link to the actual repo,
# not the working directory!
def initialize(repo = ".git", branch = "master")
def initialize(repo = ".", branch = "master")
@branch = branch
@repository = File.expand_path(repo)
@repository = repo
@repository = find_repo(repo)
__setobj__(Tree.new(:parent => self))
update!
end
Expand Down Expand Up @@ -396,6 +394,14 @@ def inspect #:nodoc:

private

def find_repo(dir)
Dir.chdir(dir) do
File.expand_path(git('rev-parse', '--git-dir', :git_dir => false))
end
rescue Errno::ENOENT, Gash::Errors::Git
raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
end

def cat_file(blob)
git('cat-file', 'blob', blob)
end
Expand Down Expand Up @@ -469,11 +475,7 @@ def git(cmd, *rest, &block)
result, status = run_git(cmd, *rest, &block)

if status != 0
if result =~ /Not a git repository/
raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
else
raise Errors::Git.new("Error: #{cmd} returned #{status}. Result: #{result}")
end
raise Errors::Git.new("Error: #{cmd} returned #{status}. Result: #{result}")
end
result
end
Expand Down

0 comments on commit b307b9c

Please sign in to comment.