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 = 'master') ⇒ Adapter

Returns a new instance of Adapter.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitolite/grit/adapter.rb', line 9

def initialize(repo_dir,branch='master')
  @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 Error::NotFound, "Repo (#{repo_name}) - path '#{repo_dir}' does not exist"
   rescue => e
    raise e
  end
end

Instance Method Details

#branchesObject



24
25
26
# File 'lib/gitolite/grit/adapter.rb', line 24

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

#file_content(path) ⇒ Object



37
38
39
40
# File 'lib/gitolite/grit/adapter.rb', line 37

def file_content(path)
  tree_or_blob = tree/path
  tree_or_blob && tree_or_blob.kind_of?(::Grit::Blob) && tree_or_blob.data
end

#ls_r(depth = nil, opts = {}) ⇒ Object



28
29
30
31
# File 'lib/gitolite/grit/adapter.rb', line 28

def ls_r(depth=nil,opts={})
  tree_contents = tree.contents
  ls_r_aux(depth,tree_contents,opts)
end

#path_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gitolite/grit/adapter.rb', line 33

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

#pullObject



54
55
56
# File 'lib/gitolite/grit/adapter.rb', line 54

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

#pushObject



42
43
44
45
46
# File 'lib/gitolite/grit/adapter.rb', line 42

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



48
49
50
# File 'lib/gitolite/grit/adapter.rb', line 48

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