]> asedeno.scripts.mit.edu Git - git.git/blobdiff - lib/merge.tcl
git-gui: show unstaged symlinks in diff viewer
[git.git] / lib / merge.tcl
index f8d92b320e2ec6ed50b235a429e9e4dee785bc28..0e50919d4c272e1e071e08c58b30d2c688c8d111 100644 (file)
@@ -45,7 +45,7 @@ The rescan will be automatically started now.
 
 File [short_path $path] has merge conflicts.
 
-You must resolve them, add the file, and commit to complete the current merge.  Only then can you begin another merge.
+You must resolve them, stage the file, and commit to complete the current merge.  Only then can you begin another merge.
 "
                        unlock_index
                        return 0
@@ -81,17 +81,44 @@ 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 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])
+               if {[regexp {^[^:@]*@[^:]*:/} $remote]} {
+                       regsub {^[^:@]*@} $remote {} remote
+               }
+               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
+
+       set cmd [list git]
+       lappend cmd merge
+       lappend cmd --strategy=recursive
+       lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
+       lappend cmd HEAD
+       lappend cmd $name
+
+       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 +152,6 @@ constructor dialog {} {
                wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
        }
 
-       set _visualize [cb _visualize]
        set _start [cb _start]
 
        label $w.header \
@@ -134,10 +160,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 +179,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
 }
 
@@ -188,20 +219,24 @@ You must finish amending this commit.
        if {![lock_index abort]} return
 
        if {[string match *merge* $commit_type]} {
-               set op merge
+               set op_question "Abort merge?
+
+Aborting the current merge will cause *ALL* uncommitted changes to be lost.
+
+Continue with aborting the current merge?"
        } else {
-               set op commit
-       }
+               set op_question "Reset changes?
 
-       if {[ask_popup "Abort $op?
+Resetting the changes will cause *ALL* uncommitted changes to be lost.
 
-Aborting the current $op will cause *ALL* uncommitted changes to be lost.
+Continue with resetting the current changes?"
+       }
 
-Continue with aborting the current $op?"] eq {yes}} {
-               set fd [git_read read-tree --reset -u HEAD]
+       if {[ask_popup $op_question] eq {yes}} {
+               set fd [git_read --stderr read-tree --reset -u -v HEAD]
                fconfigure $fd -blocking 0 -translation binary
                fileevent $fd readable [namespace code [list _reset_wait $fd]]
-               ui_status {Aborting... please wait...}
+               $::main_status start {Aborting} {files reset}
        } else {
                unlock_index
        }
@@ -210,9 +245,12 @@ Continue with aborting the current $op?"] eq {yes}} {
 proc _reset_wait {fd} {
        global ui_comm
 
-       read $fd
+       $::main_status update_meter [read $fd]
+
+       fconfigure $fd -blocking 1
        if {[eof $fd]} {
-               close $fd
+               set fail [catch {close $fd} err]
+               $::main_status stop
                unlock_index
 
                $ui_comm delete 0.0 end
@@ -224,7 +262,12 @@ proc _reset_wait {fd} {
                catch {file delete [gitdir MERGE_MSG]}
                catch {file delete [gitdir GITGUI_MSG]}
 
+               if {$fail} {
+                       warn_popup "Abort failed.\n\n$err"
+               }
                rescan {ui_status {Abort completed.  Ready.}}
+       } else {
+               fconfigure $fd -blocking 0
        }
 }