Class: DTK::Common::GritAdapter::ObjectAccess

Inherits:
DTK::Common::GritAdapter show all
Defined in:
lib/grit_adapter/object_access.rb

Constant Summary

Constants inherited from DTK::Common::GritAdapter

Git_command__push_mutex

Instance Attribute Summary

Attributes inherited from DTK::Common::GritAdapter

#branch, #repo_dir

Instance Method Summary collapse

Methods inherited from DTK::Common::GritAdapter

#add_or_update_remote, #add_remote, #add_remote?, #branches, clone, #file_content, #ls_r, #path_exists?, #push, #remotes

Constructor Details

#initialize(repo_dir, branch = nil) ⇒ ObjectAccess

Returns a new instance of ObjectAccess.



3
4
5
6
# File 'lib/grit_adapter/object_access.rb', line 3

def initialize(repo_dir,branch=nil)
  super
  @grit_index = @grit_repo.index
end

Instance Method Details

#add_or_replace_file(file_path, content) ⇒ Object



12
13
14
# File 'lib/grit_adapter/object_access.rb', line 12

def add_or_replace_file(file_path,content)
  @grit_index.add(file_path,content)
end

#commit(commit_msg) ⇒ Object



28
29
30
31
# File 'lib/grit_adapter/object_access.rb', line 28

def commit(commit_msg)
  @grit_index.commit(commit_msg,@grit_repo.commits,nil,nil,@branch)
  git_command("write-tree".to_sym)
end

#commit_context(commit_msg, &block) ⇒ Object



33
34
35
36
37
# File 'lib/grit_adapter/object_access.rb', line 33

def commit_context(commit_msg,&block)
  read_tree()
  yield
  commit(commit_msg)
end

#create_branch(new_branch) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/grit_adapter/object_access.rb', line 20

def create_branch(new_branch)
  if branches().include?(new_branch)
    raise Error.new("Branch (#{new_branch}) already exists")
  end
  commit_msg = "adding new branch (#{new_branch})"
  @grit_index.commit(commit_msg,@grit_repo.commits,nil,nil,new_branch)
end

#delete_file(file_path) ⇒ Object



16
17
18
# File 'lib/grit_adapter/object_access.rb', line 16

def delete_file(file_path)
  @grit_index.delete(file_path)
end

#read_treeObject



8
9
10
# File 'lib/grit_adapter/object_access.rb', line 8

def read_tree()
  @grit_index.read_tree(@branch)
end