Skip to content

Commit

Permalink
added checkout_index
Browse files Browse the repository at this point in the history
  • Loading branch information
scott Chacon committed Nov 16, 2007
1 parent 613757c commit be47ad8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,20 @@ Some examples of more low-level index and tree operations
end
end

g.set_index('/path/to/index')
g.set_index('/path/to/index')


g.with_index(path) do
# calls set_index, then switches back after
end

g.with_working(dir) do
# calls set_working, then switches back after
end

g.with_temp_working(dir) do
g.checkout_index(:prefix => dir, :path_limiter => path)
# do file work
g.commit # commits to index
end

5 changes: 5 additions & 0 deletions lib/git/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ def with_temp_index &blk
with_index(temp_path, &blk)
end

def checkout_index(opts = {})
self.lib.checkout_index(opts)
end

def read_tree(treeish, opts = {})
self.lib.read_tree(treeish, opts)
end
Expand All @@ -382,6 +386,7 @@ def update_ref(branch, commit)
branch(branch).update_ref(commit)
end


def ls_files
self.lib.ls_files
end
Expand Down
8 changes: 8 additions & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ def update_ref(branch, commit)
command('update-ref', [branch.to_s, commit.to_s])
end

def checkout_index(opts = {})
arr_opts = []
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
arr_opts << "--force" if opts[:force]
arr_opts << "--all" if opts[:all]
arr_opts << ('-- ' + opts[:path_limiter]) if opts[:path_limiter].is_a? String
command('checkout-index', arr_opts)
end

# creates an archive file
#
Expand Down
8 changes: 8 additions & 0 deletions tests/units/test_tree_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def test_read_tree

assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)

g.with_temp_working do
assert(!File.directory?('b1'))
g.checkout_index
assert(!File.directory?('b1'))
g.checkout_index(:all => true)
assert(File.directory?('b1'))
end

end
end
end
Expand Down

0 comments on commit be47ad8

Please sign in to comment.