Fixed Repository#exists? to handle errors

Now that Repository#raw_repository no longer sets the autocrlf option it
will also no longer raise any NoRepository errors since it doesn't
access Rugged any more. This also means that Repository#exists? can't
simply return the raw repository as this is no indication of whether or
not the repository actually exists (besides returning a non boolean is
weird in the first place).

To solve this problem Repository#exists? now properly checks if the
repository exists and returns true/false instead of a
Gitlab::Git::Repository or nil object.
This commit is contained in:
Yorick Peterse 2016-02-18 12:19:49 +01:00
parent c475b17111
commit 54aa0969d4
1 changed files with 5 additions and 6 deletions

View File

@ -23,11 +23,7 @@ class Repository
def raw_repository
return nil unless path_with_namespace
@raw_repository ||= begin
Gitlab::Git::Repository.new(path_to_repo)
rescue Gitlab::Git::Repository::NoRepository
nil
end
@raw_repository ||= Gitlab::Git::Repository.new(path_to_repo)
end
def update_autocrlf_option
@ -42,7 +38,10 @@ class Repository
end
def exists?
raw_repository
raw_repository.rugged
true
rescue Gitlab::Git::Repository::NoRepository
false
end
def empty?