@@ -181,7 +181,11 @@ def ls_tree(sha)
181
181
182
182
data
183
183
end
184
-
184
+
185
+ def mv ( file1 , file2 )
186
+ command_lines ( 'mv' , [ file1 , file2 ] )
187
+ end
188
+
185
189
def full_tree ( sha )
186
190
command_lines ( 'ls-tree' , [ '-r' , sha . to_s ] )
187
191
end
@@ -190,29 +194,24 @@ def tree_depth(sha)
190
194
full_tree ( sha ) . size
191
195
end
192
196
197
+ def change_head_branch ( branch_name )
198
+ command ( 'symbolic-ref' , [ 'HEAD' , "refs/heads/#{ branch_name } " ] )
199
+ end
200
+
193
201
def branches_all
194
- head = File . read ( File . join ( @git_dir , 'HEAD' ) )
195
202
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 ]
199
207
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
-
209
208
arr
210
209
end
211
210
212
211
def list_files ( ref_dir )
213
212
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
216
215
files
217
216
end
218
217
0 commit comments