# Module Repository

- app/roles/repository.rb

Methods

A
  - archive_repo
B
  - branch_names,
  - branches
C
  - commit,
  - commits,
  - commits_between,
  - commits_since,
  - commits_with_refs
D
  - destroy_repository,
  - discover_default_branch
E
  - empty_repo?
F
  - fresh_commits
H
  - has_commits?,
  - has_post_receive_file?,
  - heads,
  - hook_file,
  - http_url_to_repo
L
  - last_commit_for
N
  - namespace_dir
O
  - open_branches
P
  - path_to_repo,
  - protected_branch?
R
  - ref_names,
  - repo,
  - repo_exists?,
  - root_ref,
  - root_ref?
S
  - satellite,
  - ssh_url_to_repo
T
  - tag_names,
  - tags,
  - tree
U
  - update_repository,
  - url_to_repo
V
  - valid_hook_file,
  - valid_post_receive_file?,
  - valid_repo?

Included Modules

- GitHost

Instance Public methods
archive_repo(ref) Link

Archive Project to .tar.gz

Already packed repo archives stored at app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz

Source: show

    # File app/roles/repository.rb, line 175
    def archive_repo(ref)
      ref = ref || self.root_ref
      commit = self.commit(ref)
      return nil unless commit

      # Build file path
      file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
      storage_path = Rails.root.join("tmp", "repositories", self.path_with_namespace)
      file_path = File.join(storage_path, file_name)

      # Put files into a directory before archiving
      prefix = self.path + "/"

      # Create file if not exists
      unless File.exists?(file_path)
        FileUtils.mkdir_p storage_path
        file = self.repo.archive_to_file(ref, prefix,  file_path)
      end

      file_path
    end

branch_names() Link

Returns an Array of branch names

Source: show

    # File app/roles/repository.rb, line 67
    def branch_names
      repo.branches.collect(&:name).sort
    end

branches() Link

Returns an Array of Branches

Source: show

    # File app/roles/repository.rb, line 72
    def branches
      repo.branches.sort_by(&:name)
    end

commit(commit_id = nil) Link

Source: show

    # File app/roles/repository.rb, line 15
    def commit(commit_id = nil)
      Commit.find_or_first(repo, commit_id, root_ref)
    end

commits(ref, path = nil, limit = nil, offset = nil) Link

Source: show

    # File app/roles/repository.rb, line 31
    def commits(ref, path = nil, limit = nil, offset = nil)
      Commit.commits(repo, ref, path, limit, offset)
    end

commits_between(from, to) Link

Source: show

    # File app/roles/repository.rb, line 39
    def commits_between(from, to)
      Commit.commits_between(repo, from, to)
    end

commits_since(date) Link

Source: show

    # File app/roles/repository.rb, line 27
    def commits_since(date)
      Commit.commits_since(repo, date)
    end

commits_with_refs(n = 20) Link

Source: show

    # File app/roles/repository.rb, line 23
    def commits_with_refs(n = 20)
      Commit.commits_with_refs(repo, n)
    end

destroy_repository() Link

Source: show

    # File app/roles/repository.rb, line 111
    def destroy_repository
      git_host.remove_repository(self)
    end

discover_default_branch() Link

Discovers the default branch based on the repository’s available branches

- If no branches are present, returns nil

- If one branch is present, returns its name

- If two or more branches are present, returns the one that has a name matching #root_ref (default_branch or ‘master’ if default_branch is nil)

Source: show

    # File app/roles/repository.rb, line 146
    def discover_default_branch
      if branch_names.length == 0
        nil
      elsif branch_names.length == 1
        branch_names.first
      else
        branch_names.select { |v| v == root_ref }.first
      end
    end

empty_repo?() Link

Source: show

    # File app/roles/repository.rb, line 11
    def empty_repo?
      !repo_exists? || !has_commits?
    end

fresh_commits(n = 10) Link

Source: show

    # File app/roles/repository.rb, line 19
    def fresh_commits(n = 10)
      Commit.fresh_commits(repo, n)
    end

has_commits?() Link

Source: show

    # File app/roles/repository.rb, line 156
    def has_commits?
      !!commit
    rescue Grit::NoSuchPathError
      false
    end

has_post_receive_file?() Link

Source: show

    # File app/roles/repository.rb, line 47
    def has_post_receive_file?
      !!hook_file
    end

heads() Link

Source: show

    # File app/roles/repository.rb, line 121
    def heads
      @heads ||= repo.heads
    end

hook_file() Link

Source: show

    # File app/roles/repository.rb, line 59
    def hook_file
      @hook_file ||= begin
                       hook_path = File.join(path_to_repo, 'hooks', 'post-receive')
                       File.read(hook_path) if File.exists?(hook_path)
                     end
    end

http_url_to_repo() Link

Source: show

    # File app/roles/repository.rb, line 201
    def http_url_to_repo
      http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('')
    end

last_commit_for(ref, path = nil) Link

Source: show

    # File app/roles/repository.rb, line 35
    def last_commit_for(ref, path = nil)
      commits(ref, path, 1).first
    end

namespace_dir() Link

Source: show

    # File app/roles/repository.rb, line 103
    def namespace_dir
      namespace.try(:path) || ''
    end

open_branches() Link

Source: show

    # File app/roles/repository.rb, line 131
    def open_branches
      if protected_branches.empty?
        self.repo.heads
      else
        pnames = protected_branches.map(&:name)
        self.repo.heads.reject { |h| pnames.include?(h.name) }
      end.sort_by(&:name)
    end

path_to_repo() Link

Source: show

    # File app/roles/repository.rb, line 99
    def path_to_repo
      File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git")
    end

protected_branch?(branch_name) Link

Check if current branch name is marked as protected in the system

Source: show

    # File app/roles/repository.rb, line 206
    def protected_branch? branch_name
      protected_branches.map(&:name).include?(branch_name)
    end

ref_names() Link

Returns an Array of branch and tag names

Source: show

    # File app/roles/repository.rb, line 87
    def ref_names
      [branch_names + tag_names].flatten
    end

repo() Link

Source: show

    # File app/roles/repository.rb, line 91
    def repo
      @repo ||= Grit::Repo.new(path_to_repo)
    end

repo_exists?() Link

Source: show

    # File app/roles/repository.rb, line 115
    def repo_exists?
      @repo_exists ||= (repo && !repo.branches.empty?)
    rescue
      @repo_exists = false
    end

root_ref() Link

Source: show

    # File app/roles/repository.rb, line 162
    def root_ref
      default_branch || "master"
    end

root_ref?(branch) Link

Source: show

    # File app/roles/repository.rb, line 166
    def root_ref?(branch)
      root_ref == branch
    end

satellite() Link

Source: show

    # File app/roles/repository.rb, line 43
    def satellite
      @satellite ||= Gitlab::Satellite::Satellite.new(self)
    end

ssh_url_to_repo() Link

Source: show

    # File app/roles/repository.rb, line 197
    def ssh_url_to_repo
      url_to_repo
    end

tag_names() Link

Returns an Array of tag names

Source: show

    # File app/roles/repository.rb, line 77
    def tag_names
      repo.tags.collect(&:name).sort.reverse
    end

tags() Link

Returns an Array of Tags

Source: show

    # File app/roles/repository.rb, line 82
    def tags
      repo.tags.sort_by(&:name).reverse
    end

tree(fcommit, path = nil) Link

Source: show

    # File app/roles/repository.rb, line 125
    def tree(fcommit, path = nil)
      fcommit = commit if fcommit == :head
      tree = fcommit.tree
      path ? (tree / path) : tree
    end

update_repository() Link

Source: show

    # File app/roles/repository.rb, line 107
    def update_repository
      git_host.update_repository(self)
    end

url_to_repo() Link

Source: show

    # File app/roles/repository.rb, line 95
    def url_to_repo
      git_host.url_to_repo(path_with_namespace)
    end

valid_hook_file() Link

Source: show

    # File app/roles/repository.rb, line 55
    def valid_hook_file
      @valid_hook_file ||= File.read(Rails.root.join('lib', 'hooks', 'post-receive'))
    end

valid_post_receive_file?() Link

Source: show

    # File app/roles/repository.rb, line 51
    def valid_post_receive_file?
      valid_hook_file == hook_file
    end

valid_repo?() Link

Source: show

    # File app/roles/repository.rb, line 4
    def valid_repo?
      repo
    rescue
      errors.add(:path, "Invalid repository path")
      false
    end