From ae106e2a3569e5ea874852c613ed060d8e232109 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Sun, 23 Mar 2008 13:32:52 -0700 Subject: bug fixes --- lib/git/lib.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index c9c46e0..55191fe 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -181,7 +181,11 @@ module Git data end - + + def mv(file1, file2) + command_lines('mv', [file1, file2]) + end + def full_tree(sha) command_lines('ls-tree', ['-r', sha.to_s]) end @@ -190,29 +194,24 @@ module Git full_tree(sha).size end + def change_head_branch(branch_name) + command('symbolic-ref', ['HEAD', "refs/heads/#{branch_name}"]) + end + def branches_all - head = File.read(File.join(@git_dir, 'HEAD')) arr = [] - - if m = /ref: refs\/heads\/(.*)/.match(head) - current = m[1] + command_lines('branch', '-a').each do |b| + current = false + current = true if b[0, 2] == '* ' + arr << [b.gsub('* ', '').strip, current] end - arr += list_files('heads').map { |f| [f, f == current] } - arr += list_files('remotes').map { |f| [f, false] } - - #command_lines('branch', '-a').each do |b| - # current = false - # current = true if b[0, 2] == '* ' - # arr << [b.gsub('* ', '').strip, current] - #end - arr end def list_files(ref_dir) dir = File.join(@git_dir, 'refs', ref_dir) - files = nil - Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } + files = [] + Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } rescue nil files end -- cgit