@@ -321,46 +321,76 @@ def config_remote(name)
321
321
end
322
322
323
323
def config_get ( name )
324
- config_list [ name ]
325
- #command('config', ['--get', name])
324
+ do_get = lambda do
325
+ command ( 'config' , [ '--get' , name ] )
326
+ end
327
+
328
+ if @git_dir
329
+ Dir . chdir ( @git_dir , &do_get )
330
+ else
331
+ build_list . call
332
+ end
333
+ end
334
+
335
+ def global_config_get ( name )
336
+ command ( 'config' , [ '--global' , '--get' , name ] , false )
326
337
end
327
338
328
339
def config_list
329
- config = { }
330
- config . merge! ( parse_config ( '~/.gitconfig' ) )
331
- config . merge! ( parse_config ( File . join ( @git_dir , 'config' ) ) )
332
- #hsh = {}
333
- #command_lines('config', ['--list']).each do |line|
334
- # (key, value) = line.split('=')
335
- # hsh[key] = value
336
- #end
337
- #hsh
340
+ build_list = lambda do
341
+ parse_config_list command_lines ( 'config' , [ '--list' ] )
342
+ end
343
+
344
+ if @git_dir
345
+ Dir . chdir ( @git_dir , &build_list )
346
+ else
347
+ build_list . call
348
+ end
349
+ end
350
+
351
+ def global_config_list
352
+ parse_config_list command_lines ( 'config' , [ '--global' , '--list' ] , false )
338
353
end
339
354
340
- def parse_config ( file )
355
+ def parse_config_list ( lines )
341
356
hsh = { }
342
- file = File . expand_path ( file )
343
- if File . file? ( file )
344
- current_section = nil
345
- File . readlines ( file ) . each do |line |
346
- if m = /\[ (\w +)\] / . match ( line )
347
- current_section = m [ 1 ]
348
- elsif m = /\[ (\w +?) "(.*?)"\] / . match ( line )
349
- current_section = "#{ m [ 1 ] } .#{ m [ 2 ] } "
350
- elsif m = /(\w +?) = (.*)/ . match ( line )
351
- key = "#{ current_section } .#{ m [ 1 ] } "
352
- hsh [ key ] = m [ 2 ]
353
- end
354
- end
357
+ lines . each do |line |
358
+ ( key , *values ) = line . split ( '=' )
359
+ hsh [ key ] = values . join ( '=' )
355
360
end
356
361
hsh
357
362
end
363
+
364
+ def parse_config ( file )
365
+ hsh = { }
366
+ parse_config_list command_lines ( 'config' , [ '--list' , '--file' , file ] , false )
367
+ #hsh = {}
368
+ #file = File.expand_path(file)
369
+ #if File.file?(file)
370
+ # current_section = nil
371
+ # File.readlines(file).each do |line|
372
+ # if m = /\[(\w+)\]/.match(line)
373
+ # current_section = m[1]
374
+ # elsif m = /\[(\w+?) "(.*?)"\]/.match(line)
375
+ # current_section = "#{m[1]}.#{m[2]}"
376
+ # elsif m = /(\w+?) = (.*)/.match(line)
377
+ # key = "#{current_section}.#{m[1]}"
378
+ # hsh[key] = m[2]
379
+ # end
380
+ # end
381
+ #end
382
+ #hsh
383
+ end
358
384
359
385
## WRITE COMMANDS ##
360
386
361
387
def config_set ( name , value )
362
388
command ( 'config' , [ name , value ] )
363
389
end
390
+
391
+ def global_config_set ( name , value )
392
+ command ( 'config' , [ '--global' , name , value ] , false )
393
+ end
364
394
365
395
def add ( path = '.' )
366
396
arr_opts = [ '--' ]
0 commit comments