From 54aa0969d40549014bee6e4e500276405fb055ee Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 18 Feb 2016 12:19:49 +0100 Subject: 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. --- app/models/repository.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 381b1db3758..631a248258f 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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? -- cgit v1.2.1