class GitDS::StageIndex
Index
object for the Git staging index.
Attributes
parent_commit[R]
sha[R]
Public Class Methods
new(repo, treeish=nil)
click to toggle source
Calls superclass method
# File lib/git-ds/index.rb, line 156 def initialize(repo, treeish=nil) super(repo) @parent_commit = repo.commits(repo.current_branch, 1).first treeish = (@parent_commit ? @parent_commit.tree.id : 'master') if \ not treeish read_tree(treeish) @sha = self.current_tree.id end
read(repo)
click to toggle source
Read staging index from disk and create a StagingIndex object for it.
This can be used to access index contents created by command-line tools.
# File lib/git-ds/index.rb, line 225 def self.read(repo) sha = repo.exec_in_git_dir{`git write-tree`}.chomp new(repo, sha) end
Public Instance Methods
build()
click to toggle source
Write, read tree. Done when a tree is requested.
# File lib/git-ds/index.rb, line 197 def build return @sha if self.tree.empty? self.read_tree(self.write) end
commit(msg, author=nil)
click to toggle source
Calls superclass method
# File lib/git-ds/index.rb, line 167 def commit(msg, author=nil) parents = @parent_commit ? [@parent_commit] : [] # TODO : why does last_tree cause some commits to fail? # test_transaction(TC_GitDatabaseTest) # transaction commit has wrong message. # <"SUCCESS"> expected but was <"auto-commit on transaction"> # Possible bug in Grit::last_tree? #last_tree = @parent_commit ? @parent_commit.tree.id : nil #sha = super(msg, parents, author, last_tree, @repo.current_branch) sha = super(msg, parents, author, nil, @repo.current_branch) if sha # set index parent_commit to the new commit @parent_commit = @repo.commit(sha) # read tree back into index read_tree(@parent_commit.tree.id) sync end sha end
read_tree(sha)
click to toggle source
Calls superclass method
# File lib/git-ds/index.rb, line 202 def read_tree(sha) super end
sync()
click to toggle source
Sync with staging index. This causes the Git index (used by command-line tools) to be filled with the contents of this index.
This can be instead of a commit to ensure that command-line tools can access the index contents.
# File lib/git-ds/index.rb, line 213 def sync self.build @repo.exec_in_git_dir { `git read-tree #{@sha}` } end
Also aliased as: force_sync
write()
click to toggle source
Write tree object for index to object database.
Calls superclass method
GitDS::Index#write
# File lib/git-ds/index.rb, line 190 def write @sha = super end