class Gitolite::Git::Adapter

Constants

DEFAULT_BRANCH
Git_command__push_mutex

Public Class Methods

new(repo_dir,branch=DEFAULT_BRANCH) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 26
def initialize(repo_dir,branch=DEFAULT_BRANCH)
  @repo_dir = repo_dir
  @branch = branch
  @grit_repo = nil
  begin
    @grit_repo = ::Grit::Repo.new(repo_dir)
   rescue ::Grit::NoSuchPathError
    repo_name = repo_dir.split("/").last.gsub("\.git","")
    #TODO: change to usage error
    raise ::Gitolite::NotFound, "Repo (#{repo_name}) - path '#{repo_dir}' does not exist"
   rescue => e
    raise e
  end
end

Public Instance Methods

branches() click to toggle source
# File lib/gitolite/grit/adapter.rb, line 41
def branches()
  @grit_repo.branches.map{|h|h.name}
end
file_content(path) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 54
def file_content(path)
  tree_or_blob = tree/path
  tree_or_blob && tree_or_blob.kind_of?(::Grit::Blob) && tree_or_blob.data
end
file_content_and_size(path) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 59
def file_content_and_size(path)
  tree_or_blob = tree/path
  return nil unless tree_or_blob
  { :data => tree_or_blob.data, :size => tree_or_blob.size }
end
ls_r(depth=nil,opts={}) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 45
def ls_r(depth=nil,opts={})
  tree_contents = tree.contents
  ls_r_aux(depth,tree_contents,opts)
end
path_exists?(path) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 50
def path_exists?(path)
  not (tree/path).nil?
end
pull() click to toggle source
# File lib/gitolite/grit/adapter.rb, line 77
def pull()
  git_command(:pull,"origin",@branch)
end
push() click to toggle source
# File lib/gitolite/grit/adapter.rb, line 65
def push()
  Git_command__push_mutex.synchronize do
    git_command(:push,"origin", "#{@branch}:refs/heads/#{@branch}")
  end
end
push_to_mirror_repo(mirror_repo) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 71
def push_to_mirror_repo(mirror_repo)
  git_command(:push,"--mirror",mirror_repo)
end

Private Instance Methods

cmd_opts() click to toggle source
# File lib/gitolite/grit/adapter.rb, line 118
def cmd_opts()
  {:raise => true, :timeout => 60}
end
git_command(cmd,*args) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 115
def git_command(cmd,*args)
  @grit_repo.git.send(cmd, cmd_opts(),*args)
end
ls_r_aux(depth,tree_contents,opts={}) click to toggle source
# File lib/gitolite/grit/adapter.rb, line 86
def ls_r_aux(depth,tree_contents,opts={})
  ret = Array.new
  return ret if tree_contents.empty?
  if depth == 1
    ret = tree_contents.map do |tc|
      if opts[:file_only]
        tc.kind_of?(::Grit::Blob) && tc.name
      elsif opts[:directory_only]
        tc.kind_of?(::Grit::Tree) && tc.name
      else
        tc.name
      end
    end.compact
    return ret
  end

  tree_contents.each do |tc|
    if tc.kind_of?(::Grit::Blob)
      unless opts[:directory_only]
        ret << tc.name
      end
    else
      dir_name = tc.name
      ret += ls_r_aux(depth && depth-1,tc.contents).map{|r|"#{dir_name}/#{r}"}
    end
  end
  ret
end
tree() click to toggle source
# File lib/gitolite/grit/adapter.rb, line 82
def tree()
  @grit_repo.tree(@branch)
end