2007-05-08 05:35:48 +02:00
|
|
|
# git-gui branch merge support
|
|
|
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
class merge {
|
|
|
|
|
|
|
|
field w ; # top level window
|
2007-07-25 09:44:50 +02:00
|
|
|
field w_rev ; # mega-widget to pick the revision to merge
|
2007-05-02 19:56:27 +02:00
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
method _can_merge {} {
|
2007-05-08 05:35:48 +02:00
|
|
|
global HEAD commit_type file_states
|
|
|
|
|
|
|
|
if {[string match amend* $commit_type]} {
|
|
|
|
info_popup {Cannot merge while amending.
|
|
|
|
|
|
|
|
You must finish amending this commit before starting any type of merge.
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[committer_ident] eq {}} {return 0}
|
|
|
|
if {![lock_index merge]} {return 0}
|
|
|
|
|
|
|
|
# -- Our in memory state should match the repository.
|
|
|
|
#
|
|
|
|
repository_state curType curHEAD curMERGE_HEAD
|
|
|
|
if {$commit_type ne $curType || $HEAD ne $curHEAD} {
|
|
|
|
info_popup {Last scanned state does not match repository state.
|
|
|
|
|
|
|
|
Another Git program has modified this repository since the last scan. A rescan must be performed before a merge can be performed.
|
|
|
|
|
|
|
|
The rescan will be automatically started now.
|
|
|
|
}
|
|
|
|
unlock_index
|
2007-07-06 05:16:13 +02:00
|
|
|
rescan ui_ready
|
2007-05-08 05:35:48 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach path [array names file_states] {
|
|
|
|
switch -glob -- [lindex $file_states($path) 0] {
|
|
|
|
_O {
|
|
|
|
continue; # and pray it works!
|
|
|
|
}
|
|
|
|
U? {
|
|
|
|
error_popup "You are in the middle of a conflicted merge.
|
|
|
|
|
|
|
|
File [short_path $path] has merge conflicts.
|
|
|
|
|
2007-07-28 22:17:10 +02:00
|
|
|
You must resolve them, stage the file, and commit to complete the current merge. Only then can you begin another merge.
|
2007-05-08 05:35:48 +02:00
|
|
|
"
|
|
|
|
unlock_index
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
?? {
|
|
|
|
error_popup "You are in the middle of a change.
|
|
|
|
|
|
|
|
File [short_path $path] is modified.
|
|
|
|
|
|
|
|
You should complete the current commit before starting a merge. Doing so will help you abort a failed merge, should the need arise.
|
|
|
|
"
|
|
|
|
unlock_index
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:24:25 +02:00
|
|
|
method _rev {} {
|
2007-07-25 09:44:50 +02:00
|
|
|
if {[catch {$w_rev commit_or_die}]} {
|
|
|
|
return {}
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2007-07-25 09:44:50 +02:00
|
|
|
return [$w_rev get]
|
2007-05-04 00:21:39 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
method _visualize {} {
|
2007-07-19 08:24:25 +02:00
|
|
|
set rev [_rev $this]
|
|
|
|
if {$rev ne {}} {
|
|
|
|
do_gitk [list $rev --not HEAD]
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
method _start {} {
|
2007-07-25 10:54:53 +02:00
|
|
|
global HEAD current_branch remote_url
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-19 08:24:25 +02:00
|
|
|
set name [_rev $this]
|
|
|
|
if {$name eq {}} {
|
2007-05-08 05:35:48 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2007-07-25 10:54:53 +02:00
|
|
|
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])
|
2007-07-25 11:02:38 +02:00
|
|
|
if {[regexp {^[^:@]*@[^:]*:/} $remote]} {
|
|
|
|
regsub {^[^:@]*@} $remote {} remote
|
|
|
|
}
|
2007-07-25 10:54:53 +02:00
|
|
|
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
|
|
|
|
|
2007-07-30 02:21:54 +02:00
|
|
|
set cmd [list git]
|
|
|
|
lappend cmd merge
|
|
|
|
lappend cmd --strategy=recursive
|
2007-07-25 10:54:53 +02:00
|
|
|
lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
|
|
|
|
lappend cmd HEAD
|
|
|
|
lappend cmd $cmit
|
|
|
|
|
|
|
|
set msg "Merging $current_branch and $stitle"
|
2007-07-06 05:16:13 +02:00
|
|
|
ui_status "$msg..."
|
2007-07-25 10:54:53 +02:00
|
|
|
set cons [console::new "Merge" "merge $stitle"]
|
2007-07-19 08:24:25 +02:00
|
|
|
console::exec $cons $cmd [cb _finish $cons]
|
2007-06-12 05:52:43 +02:00
|
|
|
|
|
|
|
wm protocol $w WM_DELETE_WINDOW {}
|
2007-05-08 05:35:48 +02:00
|
|
|
destroy $w
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:24:25 +02:00
|
|
|
method _finish {cons ok} {
|
2007-07-18 08:56:44 +02:00
|
|
|
console::done $cons $ok
|
2007-05-08 05:35:48 +02:00
|
|
|
if {$ok} {
|
|
|
|
set msg {Merge completed successfully.}
|
|
|
|
} else {
|
|
|
|
set msg {Merge failed. Conflict resolution is required.}
|
|
|
|
}
|
|
|
|
unlock_index
|
2007-07-06 05:16:13 +02:00
|
|
|
rescan [list ui_status $msg]
|
2007-07-18 08:56:44 +02:00
|
|
|
delete_this
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
constructor dialog {} {
|
2007-05-08 05:35:48 +02:00
|
|
|
global current_branch
|
2007-05-05 08:28:41 +02:00
|
|
|
global M1B
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
if {![_can_merge $this]} {
|
|
|
|
delete_this
|
|
|
|
return
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
make_toplevel top w
|
|
|
|
wm title $top "[appname] ([reponame]): Merge"
|
|
|
|
if {$top ne {.}} {
|
|
|
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
set _start [cb _start]
|
2007-05-05 08:28:41 +02:00
|
|
|
|
2007-05-08 05:35:48 +02:00
|
|
|
label $w.header \
|
|
|
|
-text "Merge Into $current_branch" \
|
|
|
|
-font font_uibold
|
|
|
|
pack $w.header -side top -fill x
|
|
|
|
|
|
|
|
frame $w.buttons
|
2007-07-25 10:32:18 +02:00
|
|
|
button $w.buttons.visualize \
|
|
|
|
-text Visualize \
|
|
|
|
-command [cb _visualize]
|
2007-05-08 05:35:48 +02:00
|
|
|
pack $w.buttons.visualize -side left
|
2007-07-25 10:32:18 +02:00
|
|
|
button $w.buttons.merge \
|
|
|
|
-text Merge \
|
|
|
|
-command $_start
|
|
|
|
pack $w.buttons.merge -side right
|
2007-07-04 08:29:32 +02:00
|
|
|
button $w.buttons.cancel \
|
|
|
|
-text {Cancel} \
|
2007-07-18 08:56:44 +02:00
|
|
|
-command [cb _cancel]
|
2007-05-08 05:35:48 +02:00
|
|
|
pack $w.buttons.cancel -side right -padx 5
|
|
|
|
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
|
|
|
|
|
2007-07-25 09:44:50 +02:00
|
|
|
set w_rev [::choose_rev::new_unmerged $w.rev {Revision To Merge}]
|
|
|
|
pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
|
2007-05-05 08:28:41 +02:00
|
|
|
|
|
|
|
bind $w <$M1B-Key-Return> $_start
|
2007-07-25 09:44:50 +02:00
|
|
|
bind $w <Key-Return> $_start
|
2007-07-18 08:56:44 +02:00
|
|
|
bind $w <Key-Escape> [cb _cancel]
|
|
|
|
wm protocol $w WM_DELETE_WINDOW [cb _cancel]
|
2007-07-25 10:32:18 +02:00
|
|
|
|
|
|
|
bind $w.buttons.merge <Visibility> [cb _visible]
|
2007-05-08 05:35:48 +02:00
|
|
|
tkwait window $w
|
|
|
|
}
|
|
|
|
|
2007-07-18 08:56:44 +02:00
|
|
|
method _visible {} {
|
|
|
|
grab $w
|
2007-07-25 09:44:50 +02:00
|
|
|
if {[is_config_true gui.matchtrackingbranch]} {
|
|
|
|
$w_rev pick_tracking_branch
|
|
|
|
}
|
|
|
|
$w_rev focus_filter
|
2007-07-18 08:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
method _cancel {} {
|
|
|
|
wm protocol $w WM_DELETE_WINDOW {}
|
|
|
|
unlock_index
|
|
|
|
destroy $w
|
|
|
|
delete_this
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace eval merge {
|
|
|
|
|
2007-05-02 19:56:27 +02:00
|
|
|
proc reset_hard {} {
|
2007-05-08 05:35:48 +02:00
|
|
|
global HEAD commit_type file_states
|
|
|
|
|
|
|
|
if {[string match amend* $commit_type]} {
|
|
|
|
info_popup {Cannot abort while amending.
|
|
|
|
|
|
|
|
You must finish amending this commit.
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![lock_index abort]} return
|
|
|
|
|
|
|
|
if {[string match *merge* $commit_type]} {
|
2007-07-28 22:17:10 +02:00
|
|
|
set op_question "Abort merge?
|
|
|
|
|
|
|
|
Aborting the current merge will cause *ALL* uncommitted changes to be lost.
|
|
|
|
|
|
|
|
Continue with aborting the current merge?"
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
2007-07-28 22:17:10 +02:00
|
|
|
set op_question "Reset changes?
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-28 22:17:10 +02:00
|
|
|
Resetting the changes will cause *ALL* uncommitted changes to be lost.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-28 22:17:10 +02:00
|
|
|
Continue with resetting the current changes?"
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-28 22:17:10 +02:00
|
|
|
if {[ask_popup $op_question] eq {yes}} {
|
2007-07-29 10:06:51 +02:00
|
|
|
set fd [git_read --stderr read-tree --reset -u -v HEAD]
|
2007-05-08 05:35:48 +02:00
|
|
|
fconfigure $fd -blocking 0 -translation binary
|
2007-05-02 19:56:27 +02:00
|
|
|
fileevent $fd readable [namespace code [list _reset_wait $fd]]
|
2007-07-29 10:06:51 +02:00
|
|
|
$::main_status start {Aborting} {files reset}
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
|
|
|
unlock_index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-02 19:56:27 +02:00
|
|
|
proc _reset_wait {fd} {
|
2007-05-08 05:35:48 +02:00
|
|
|
global ui_comm
|
|
|
|
|
2007-07-29 10:06:51 +02:00
|
|
|
$::main_status update_meter [read $fd]
|
|
|
|
|
|
|
|
fconfigure $fd -blocking 1
|
2007-05-08 05:35:48 +02:00
|
|
|
if {[eof $fd]} {
|
2007-07-29 10:06:51 +02:00
|
|
|
set fail [catch {close $fd} err]
|
|
|
|
$::main_status stop
|
2007-05-08 05:35:48 +02:00
|
|
|
unlock_index
|
|
|
|
|
|
|
|
$ui_comm delete 0.0 end
|
|
|
|
$ui_comm edit modified false
|
|
|
|
|
|
|
|
catch {file delete [gitdir MERGE_HEAD]}
|
|
|
|
catch {file delete [gitdir rr-cache MERGE_RR]}
|
|
|
|
catch {file delete [gitdir SQUASH_MSG]}
|
|
|
|
catch {file delete [gitdir MERGE_MSG]}
|
|
|
|
catch {file delete [gitdir GITGUI_MSG]}
|
|
|
|
|
2007-07-29 10:06:51 +02:00
|
|
|
if {$fail} {
|
|
|
|
warn_popup "Abort failed.\n\n$err"
|
|
|
|
}
|
2007-07-06 05:16:13 +02:00
|
|
|
rescan {ui_status {Abort completed. Ready.}}
|
2007-07-29 10:06:51 +02:00
|
|
|
} else {
|
|
|
|
fconfigure $fd -blocking 0
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
2007-05-02 19:56:27 +02:00
|
|
|
|
|
|
|
}
|