@@ -66,7 +66,7 @@ def log_commits(opts = {})
66
66
arr_opts << opts [ :object ] if opts [ :object ] . is_a? String
67
67
arr_opts << '-- ' + opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
68
68
69
- command_lines ( 'log' , arr_opts ) . map { |l | l . split . first }
69
+ command_lines ( 'log' , arr_opts , true ) . map { |l | l . split . first }
70
70
end
71
71
72
72
def revparse ( string )
@@ -422,34 +422,37 @@ def archive(sha, file = nil, opts = {})
422
422
423
423
private
424
424
425
- def command_lines ( cmd , opts = { } )
426
- command ( cmd , opts ) . split ( "\n " )
425
+ def command_lines ( cmd , opts = { } , chdir = true )
426
+ command ( cmd , opts , chdir ) . split ( "\n " )
427
427
end
428
428
429
- def command ( cmd , opts = { } )
429
+ def command ( cmd , opts = { } , chdir = true )
430
430
ENV [ 'GIT_DIR' ] = @git_dir if ( @git_dir != ENV [ 'GIT_DIR' ] )
431
431
ENV [ 'GIT_INDEX_FILE' ] = @git_index_file if ( @git_index_file != ENV [ 'GIT_INDEX_FILE' ] )
432
- ENV [ 'GIT_WORK_DIR' ] = @git_work_dir if ( @git_work_dir != ENV [ 'GIT_WORK_DIR' ] )
433
- #path = @git_work_dir || @git_dir || @path
434
- #Dir.chdir(path) do
435
- opts = opts . to_a . join ( ' ' )
436
- git_cmd = "git #{ cmd } #{ opts } "
432
+ ENV [ 'GIT_WORK_TREE' ] = @git_work_dir if ( @git_work_dir != ENV [ 'GIT_WORK_TREE' ] )
433
+ path = @git_work_dir || @git_dir || @path
434
+
435
+ opts = opts . to_a . join ( ' ' )
436
+ git_cmd = "git #{ cmd } #{ opts } "
437
+
438
+ out = nil
439
+ if chdir && ( Dir . getwd != path )
440
+ Dir . chdir ( path ) { out = `git #{ cmd } #{ opts } 2>&1` . chomp }
441
+ else
437
442
out = `git #{ cmd } #{ opts } 2>&1` . chomp
438
- #puts path
439
- #puts "gd: #{@git_work_dir}"
440
- #puts "gi: #{@git_index_file}"
441
- #puts "pp: #{@path}"
442
- #puts git_cmd
443
- #puts out
444
- #puts
445
- if $?. exitstatus > 0
446
- if $?. exitstatus == 1 && out == ''
447
- return ''
448
- end
449
- raise Git ::GitExecuteError . new ( git_cmd + ':' + out . to_s )
443
+ end
444
+
445
+ #puts git_cmd
446
+ #puts out
447
+ #puts
448
+
449
+ if $?. exitstatus > 0
450
+ if $?. exitstatus == 1 && out == ''
451
+ return ''
450
452
end
451
- out
452
- #end
453
+ raise Git ::GitExecuteError . new ( git_cmd + ':' + out . to_s )
454
+ end
455
+ out
453
456
end
454
457
455
458
end
0 commit comments