Read about our upcoming Code of Conduct on this issue

repository.rb 1.52 KB
Newer Older
1
2
3
module Gitlab
  module BareRepositoryImport
    class Repository
4
5
      include ::Gitlab::Utils::StrongMemoize

6
7
8
9
10
      attr_reader :group_path, :project_name, :repo_path

      def initialize(root_path, repo_path)
        @root_path = root_path
        @repo_path = repo_path
Stan Hu's avatar
Stan Hu committed
11
12
        @root_path << '/' unless root_path.ends_with?('/')

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

20
        # Split path into 'all/the/namespaces' and 'project_name'
21
        @group_path, _, @project_name = full_path.to_s.rpartition('/')
22
23
24
25
26
27
28
29
30
31
32
33
34
35
      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

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

40
        true
41
42
      end

43
44
      private

45
      def wiki?
46
47
48
        strong_memoize(:wiki) do
          repo_path.end_with?('.wiki.git')
        end
49
50
51
      end

      def hashed?
52
53
54
        strong_memoize(:hashed) do
          repo_relative_path.include?('@hashed')
        end
55
56
      end

57
58
      def repo_relative_path
        # Remove root path and `.git` at the end
Stan Hu's avatar
Stan Hu committed
59
        repo_path[@root_path.size...-4]
60
      end
61
62
63
64

      def repository
        @repository ||= Rugged::Repository.new(repo_path)
      end
65
66
67
    end
  end
end