summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-02-14 12:53:53 -0800
committerStan Hu <stanhu@gmail.com>2018-02-14 12:53:53 -0800
commit35b3a0b967399d0b4340325d067592c166f208e5 (patch)
treef15bdfa166b0ea22cdf48063b1a2468d9b74c6c5 /app
parentdd633bc1888453a07474d045eca91a9e66302ce0 (diff)
downloadgitlab-ce-35b3a0b967399d0b4340325d067592c166f208e5.tar.gz
Fix Error 500s loading repositories with no master branch
We removed the exception handling for Rugged errors in !16770, which revealed that the licensee gem attempts to retrieve a license file via Rugged in `refs/heads/master` by default. If that branch did not exist, a Rugged::ReferenceError would be thrown. There were two issues: 1. Not every project uses `master` as the default branch. This change uses the head commit to identify the license. 2. Removing the exception handling caused repositories to fail loading. We can safely catch and ignore any Rugged error because this means we weren't able to load a license file. Closes #43268
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 1cf55fd4332..eef187b623b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -592,8 +592,14 @@ class Repository
def license_key
return unless exists?
+ return unless head_commit
- Licensee.license(path).try(:key)
+ # The licensee gem creates a Rugged object from the path:
+ # https://github.com/benbalter/licensee/blob/v8.7.0/lib/licensee/projects/git_project.rb
+ begin
+ Licensee.project(path, revision: head_commit.sha).license.try(:key)
+ rescue Rugged::Error
+ end
end
cache_method :license_key