summaryrefslogtreecommitdiff
path: root/lib/gitlab/repo_path.rb
blob: 4b1d828c45ca33acb8679ab59a0cf5a5d5468443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Gitlab
  module RepoPath
    NotFoundError = Class.new(StandardError)

    def self.strip_storage_path(repo_path)
      result = nil

      Gitlab.config.repositories.storages.values.each do |params|
        storage_path = params['path']
        if repo_path.start_with?(storage_path)
          result = repo_path.sub(storage_path, '')
          break
        end
      end

      if result.nil?
        raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
      end

      result.sub(/\A\/*/, '')
    end
  end
end