Class: Gitolite::Git::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitolite/grit/adapter.rb

Direct Known Subclasses

FileAccess

Constant Summary collapse

DEFAULT_BRANCH =
'master'
Git_command__push_mutex =
Mutex.new

Instance Method Summary collapse

Constructor Details

#initialize(repo_dir, branch = DEFAULT_BRANCH) ⇒ Adapter

Returns a new instance of Adapter.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#branchesObject



41
42
43
# File 'lib/gitolite/grit/adapter.rb', line 41

def branches()
  @grit_repo.branches.map{|h|h.name}
end

#file_content(path) ⇒ Object



54
55
56
57
# 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) ⇒ Object



59
60
61
62
63
# 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 = {}) ⇒ Object



45
46
47
48
# 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) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/gitolite/grit/adapter.rb', line 50

def path_exists?(path)
  not (tree/path).nil?
end

#pullObject



77
78
79
# File 'lib/gitolite/grit/adapter.rb', line 77

def pull()
  git_command(:pull,"origin",@branch)
end

#pushObject



65
66
67
68
69
# 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) ⇒ Object



71
72
73
# File 'lib/gitolite/grit/adapter.rb', line 71

def push_to_mirror_repo(mirror_repo)
  git_command(:push,"--mirror",mirror_repo)
end