repository.rb 1.4 KB
Newer Older
1 2 3 4 5 6 7 8
module Gitlab
  module BareRepositoryImport
    class Repository
      attr_reader :group_path, :project_name, :repo_path

      def initialize(root_path, repo_path)
        @root_path = root_path
        @repo_path = repo_path
S
Stan Hu 已提交
9 10
        @root_path << '/' unless root_path.ends_with?('/')

11 12 13 14 15 16 17
        full_path =
          if hashed? && !wiki?
            repository.config.get('gitlab.fullpath')
          else
            repo_relative_path
          end

18
        # Split path into 'all/the/namespaces' and 'project_name'
19
        @group_path, _, @project_name = full_path.to_s.rpartition('/')
20 21 22 23 24 25 26 27 28 29 30 31 32 33
      end

      def wiki_exists?
        File.exist?(wiki_path)
      end

      def wiki_path
        @wiki_path ||= repo_path.sub(/\.git$/, '.wiki.git')
      end

      def project_full_path
        @project_full_path ||= "#{group_path}/#{project_name}"
      end

34 35
      def processable?
        return false if wiki?
36
        return false if hashed? && (group_path.blank? || project_name.blank?)
37

38
        true
39 40
      end

41 42
      private

43 44 45 46 47 48 49 50
      def wiki?
        @wiki ||= repo_path.end_with?('.wiki.git')
      end

      def hashed?
        @hashed ||= repo_relative_path.include?('@hashed')
      end

51 52
      def repo_relative_path
        # Remove root path and `.git` at the end
S
Stan Hu 已提交
53
        repo_path[@root_path.size...-4]
54
      end
55 56 57 58

      def repository
        @repository ||= Rugged::Repository.new(repo_path)
      end
59 60 61
    end
  end
end