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

View file

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