Code

git-gui: Format tracking branch merges as though they were pulls
[git.git] / lib / merge.tcl
index f8d92b320e2ec6ed50b235a429e9e4dee785bc28..c8b486710aa66afce100219a1167618a0103cd87 100644 (file)
@@ -81,17 +81,41 @@ method _visualize {} {
 }
 
 method _start {} {
-       global HEAD current_branch
+       global HEAD current_branch remote_url
 
        set name [_rev $this]
        if {$name eq {}} {
                return
        }
 
-       set cmd [list git merge $name]
-       set msg "Merging $current_branch and $name"
+       set spec [$w_rev get_tracking_branch]
+       set cmit [$w_rev get_commit]
+       set cmd [list git]
+       lappend cmd merge
+       lappend cmd --strategy=recursive
+
+       set fh [open [gitdir FETCH_HEAD] w]
+       fconfigure $fh -translation lf
+       if {$spec eq {}} {
+               set remote .
+               set branch $name
+               set stitle $branch
+       } else {
+               set remote $remote_url([lindex $spec 1])
+               set branch [lindex $spec 2]
+               set stitle "$branch of $remote"
+       }
+       regsub ^refs/heads/ $branch {} branch
+       puts $fh "$cmit\t\tbranch '$branch' of $remote"
+       close $fh
+
+       lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
+       lappend cmd HEAD
+       lappend cmd $cmit
+
+       set msg "Merging $current_branch and $stitle"
        ui_status "$msg..."
-       set cons [console::new "Merge" $cmd]
+       set cons [console::new "Merge" "merge $stitle"]
        console::exec $cons $cmd [cb _finish $cons]
 
        wm protocol $w WM_DELETE_WINDOW {}
@@ -125,7 +149,6 @@ constructor dialog {} {
                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
        }
 
-       set _visualize [cb _visualize]
        set _start [cb _start]
 
        label $w.header \
@@ -134,10 +157,14 @@ constructor dialog {} {
        pack $w.header -side top -fill x
 
        frame $w.buttons
-       button $w.buttons.visualize -text Visualize -command $_visualize
+       button $w.buttons.visualize \
+               -text Visualize \
+               -command [cb _visualize]
        pack $w.buttons.visualize -side left
-       button $w.buttons.create -text Merge -command $_start
-       pack $w.buttons.create -side right
+       button $w.buttons.merge \
+               -text Merge \
+               -command $_start
+       pack $w.buttons.merge -side right
        button $w.buttons.cancel \
                -text {Cancel} \
                -command [cb _cancel]
@@ -149,9 +176,10 @@ constructor dialog {} {
 
        bind $w <$M1B-Key-Return> $_start
        bind $w <Key-Return> $_start
-       bind $w <Visibility> [cb _visible]
        bind $w <Key-Escape> [cb _cancel]
        wm protocol $w WM_DELETE_WINDOW [cb _cancel]
+
+       bind $w.buttons.merge <Visibility> [cb _visible]
        tkwait window $w
 }