summaryrefslogtreecommitdiffstats
path: root/lib/git/base.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-16 11:23:24 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-16 11:23:24 -0800
commitde071dcd8dee3d853291a5077b9dcdec07dd5362 (patch)
treebd335c0a79ed4da9fc4c05b2f44542a03a2d3b5d /lib/git/base.rb
parent3687e45effe8ad433da31712149b424d46effe64 (diff)
downloadthird_party-ruby-git-de071dcd8dee3d853291a5077b9dcdec07dd5362.tar.gz
third_party-ruby-git-de071dcd8dee3d853291a5077b9dcdec07dd5362.tar.xz
third_party-ruby-git-de071dcd8dee3d853291a5077b9dcdec07dd5362.zip
added some low level tree operations and tests
Diffstat (limited to 'lib/git/base.rb')
-rw-r--r--lib/git/base.rb72
1 files changed, 71 insertions, 1 deletions
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 4e1e125..6372beb 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -90,6 +90,17 @@ module Git
@index
end
+
+ def set_working(work_dir, check = true)
+ @lib = nil
+ @working_directory = Git::WorkingDirectory.new(work_dir.to_s, check)
+ end
+
+ def set_index(index_file, check = true)
+ @lib = nil
+ @index = Git::Index.new(index_file.to_s, check)
+ end
+
# changes current working directory for a block
# to the git working directory
#
@@ -186,7 +197,7 @@ module Git
# actual 'git' forked system calls. At some point I hope to replace the Git::Lib
# class with one that uses native methods or libgit C bindings
def lib
- Git::Lib.new(self)
+ @lib ||= Git::Lib.new(self)
end
# will run a grep for 'string' on the HEAD of the git repository
@@ -330,6 +341,65 @@ module Git
self.lib.repack
end
+
+ ## LOWER LEVEL INDEX OPERATIONS ##
+
+ def with_index(new_index)
+ old_index = @index
+ set_index(new_index, false)
+ return_value = yield @index
+ set_index(old_index)
+ return_value
+ end
+
+ def with_temp_index &blk
+ tempfile = Tempfile.new('temp-index')
+ temp_path = tempfile.path
+ tempfile.unlink
+ with_index(temp_path, &blk)
+ end
+
+ def read_tree(treeish, opts = {})
+ self.lib.read_tree(treeish, opts)
+ end
+
+ def write_tree
+ self.lib.write_tree
+ end
+
+ def commit_tree(tree = nil, opts = {})
+ Git::Object::Commit.new(self, self.lib.commit_tree(tree, opts))
+ end
+
+ def write_and_commit_tree(opts = {})
+ tree = write_tree
+ commit_tree(tree, opts)
+ end
+
+ def ls_files
+ self.lib.ls_files
+ end
+
+ def with_working(work_dir)
+ return_value = false
+ old_working = @working_directory
+ set_working(work_dir)
+ Dir.chdir work_dir do
+ return_value = yield @working_directory
+ end
+ set_working(old_working)
+ return_value
+ end
+
+ def with_temp_working &blk
+ tempfile = Tempfile.new("temp-workdir")
+ temp_dir = tempfile.path
+ tempfile.unlink
+ Dir.mkdir(temp_dir, 0700)
+ with_working(temp_dir, &blk)
+ end
+
+
# runs git rev-parse to convert the objectish to a full sha
#
# @git.revparse("HEAD^^")