Skip to content

Commit ae106e2

Browse files
committed
bug fixes
1 parent 6c4af60 commit ae106e2

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lib/git/lib.rb

+15-16
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ def ls_tree(sha)
181181

182182
data
183183
end
184-
184+
185+
def mv(file1, file2)
186+
command_lines('mv', [file1, file2])
187+
end
188+
185189
def full_tree(sha)
186190
command_lines('ls-tree', ['-r', sha.to_s])
187191
end
@@ -190,29 +194,24 @@ def tree_depth(sha)
190194
full_tree(sha).size
191195
end
192196

197+
def change_head_branch(branch_name)
198+
command('symbolic-ref', ['HEAD', "refs/heads/#{branch_name}"])
199+
end
200+
193201
def branches_all
194-
head = File.read(File.join(@git_dir, 'HEAD'))
195202
arr = []
196-
197-
if m = /ref: refs\/heads\/(.*)/.match(head)
198-
current = m[1]
203+
command_lines('branch', '-a').each do |b|
204+
current = false
205+
current = true if b[0, 2] == '* '
206+
arr << [b.gsub('* ', '').strip, current]
199207
end
200-
arr += list_files('heads').map { |f| [f, f == current] }
201-
arr += list_files('remotes').map { |f| [f, false] }
202-
203-
#command_lines('branch', '-a').each do |b|
204-
# current = false
205-
# current = true if b[0, 2] == '* '
206-
# arr << [b.gsub('* ', '').strip, current]
207-
#end
208-
209208
arr
210209
end
211210

212211
def list_files(ref_dir)
213212
dir = File.join(@git_dir, 'refs', ref_dir)
214-
files = nil
215-
Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } }
213+
files = []
214+
Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } rescue nil
216215
files
217216
end
218217

0 commit comments

Comments
 (0)