@@ -425,7 +425,28 @@ def merge(branch, message = nil)
425
425
arr_opts << branch . to_a . join ( ' ' )
426
426
command ( 'merge' , arr_opts )
427
427
end
428
-
428
+
429
+ def unmerged
430
+ unmerged = [ ]
431
+ command_lines ( 'diff' , [ "--cached" ] ) . each do |line |
432
+ unmerged << $1 if line =~ /^\* Unmerged path (.*)/
433
+ end
434
+ unmerged
435
+ end
436
+
437
+ def conflicts #yields :file, :your, :their
438
+ self . unmerged . each do |f |
439
+ your = Tempfile . new ( "YOUR-#{ File . basename ( f ) } " ) . path
440
+ arr_opts = [ ":2:#{ f } " , ">#{ your } " ]
441
+ command ( 'show' , arr_opts )
442
+
443
+ their = Tempfile . new ( "THEIR-#{ File . basename ( f ) } " ) . path
444
+ arr_opts = [ ":3:#{ f } " , ">#{ their } " ]
445
+ command ( 'show' , arr_opts )
446
+ yield ( f , your , their )
447
+ end
448
+ end
449
+
429
450
def remote_add ( name , url , opts = { } )
430
451
arr_opts = [ 'add' ]
431
452
arr_opts << '-f' if opts [ :with_fetch ]
@@ -549,11 +570,11 @@ def archive(sha, file = nil, opts = {})
549
570
550
571
private
551
572
552
- def command_lines ( cmd , opts = { } , chdir = true )
573
+ def command_lines ( cmd , opts = [ ] , chdir = true )
553
574
command ( cmd , opts , chdir ) . split ( "\n " )
554
575
end
555
576
556
- def command ( cmd , opts = { } , chdir = true )
577
+ def command ( cmd , opts = [ ] , chdir = true )
557
578
ENV [ 'GIT_DIR' ] = @git_dir if ( @git_dir != ENV [ 'GIT_DIR' ] )
558
579
ENV [ 'GIT_INDEX_FILE' ] = @git_index_file if ( @git_index_file != ENV [ 'GIT_INDEX_FILE' ] )
559
580
ENV [ 'GIT_WORK_TREE' ] = @git_work_dir if ( @git_work_dir != ENV [ 'GIT_WORK_TREE' ] )
@@ -564,9 +585,9 @@ def command(cmd, opts = {}, chdir = true)
564
585
565
586
out = nil
566
587
if chdir && ( Dir . getwd != path )
567
- Dir . chdir ( path ) { out = `git #{ cmd } #{ opts } 2>&1` . chomp }
588
+ Dir . chdir ( path ) { out = `#{ git_cmd } 2>&1` . chomp }
568
589
else
569
- out = `git #{ cmd } #{ opts } 2>&1` . chomp
590
+ out = `#{ git_cmd } 2>&1` . chomp
570
591
end
571
592
572
593
if @logger
@@ -584,4 +605,4 @@ def command(cmd, opts = {}, chdir = true)
584
605
end
585
606
586
607
end
587
- end
608
+ end
0 commit comments