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]} {
|
2007-07-21 14:21:34 +02:00
|
|
|
info_popup [mc "Cannot merge while amending.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
|
|
|
You must finish amending this commit before starting any type of merge.
|
2007-07-21 14:21:34 +02:00
|
|
|
"]
|
2007-05-08 05:35:48 +02:00
|
|
|
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} {
|
2007-07-21 14:21:34 +02:00
|
|
|
info_popup [mc "Last scanned state does not match repository state.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
|
|
|
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.
|
2007-07-21 14:21:34 +02:00
|
|
|
"]
|
2007-05-08 05:35:48 +02:00
|
|
|
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!
|
|
|
|
}
|
2008-10-08 10:03:54 +02:00
|
|
|
_U -
|
2007-05-08 05:35:48 +02:00
|
|
|
U? {
|
2007-07-21 14:21:34 +02:00
|
|
|
error_popup [mc "You are in the middle of a conflicted merge.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-21 14:21:34 +02:00
|
|
|
File %s has merge conflicts.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
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-07-21 14:21:34 +02:00
|
|
|
" [short_path $path]]
|
2007-05-08 05:35:48 +02:00
|
|
|
unlock_index
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
?? {
|
2007-07-21 14:21:34 +02:00
|
|
|
error_popup [mc "You are in the middle of a change.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-21 14:21:34 +02:00
|
|
|
File %s is modified.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
|
|
|
You should complete the current commit before starting a merge. Doing so will help you abort a failed merge, should the need arise.
|
2007-07-21 14:21:34 +02:00
|
|
|
" [short_path $path]]
|
2007-05-08 05:35:48 +02:00
|
|
|
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
|
2011-02-12 17:44:58 +01:00
|
|
|
global _last_merged_branch
|
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]
|
2007-07-21 14:21:34 +02:00
|
|
|
set stitle [mc "%s of %s" $branch $remote]
|
2007-07-25 10:54:53 +02:00
|
|
|
}
|
|
|
|
regsub ^refs/heads/ $branch {} branch
|
|
|
|
puts $fh "$cmit\t\tbranch '$branch' of $remote"
|
|
|
|
close $fh
|
2011-02-12 17:44:58 +01:00
|
|
|
set _last_merged_branch $branch
|
2007-07-25 10:54:53 +02:00
|
|
|
|
2016-10-04 13:49:05 +02:00
|
|
|
if {[git-version >= "2.5.0"]} {
|
|
|
|
set cmd [list git merge --strategy=recursive FETCH_HEAD]
|
|
|
|
} else {
|
|
|
|
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
|
|
|
|
}
|
2007-07-25 10:54:53 +02:00
|
|
|
|
2008-02-02 10:20:17 +01:00
|
|
|
ui_status [mc "Merging %s and %s..." $current_branch $stitle]
|
2007-07-21 14:21:34 +02:00
|
|
|
set cons [console::new [mc "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} {
|
2007-07-21 14:21:34 +02:00
|
|
|
set msg [mc "Merge completed successfully."]
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
2007-07-21 14:21:34 +02:00
|
|
|
set msg [mc "Merge failed. Conflict resolution is required."]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
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
|
2010-01-26 01:05:31 +01:00
|
|
|
global M1B use_ttk NS
|
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
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
make_dialog top w
|
2016-05-08 12:52:57 +02:00
|
|
|
wm title $top [mc "%s (%s): Merge" [appname] [reponame]]
|
2007-07-18 08:56:44 +02:00
|
|
|
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
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::label $w.header \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc "Merge Into %s" $current_branch] \
|
2007-05-08 05:35:48 +02:00
|
|
|
-font font_uibold
|
|
|
|
pack $w.header -side top -fill x
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w.buttons
|
|
|
|
${NS}::button $w.buttons.visualize \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc Visualize] \
|
2007-07-25 10:32:18 +02:00
|
|
|
-command [cb _visualize]
|
2007-05-08 05:35:48 +02:00
|
|
|
pack $w.buttons.visualize -side left
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w.buttons.merge \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc Merge] \
|
2007-07-25 10:32:18 +02:00
|
|
|
-command $_start
|
|
|
|
pack $w.buttons.merge -side right
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w.buttons.cancel \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc "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-21 14:21:34 +02:00
|
|
|
set w_rev [::choose_rev::new_unmerged $w.rev [mc "Revision To Merge"]]
|
2007-07-25 09:44:50 +02:00
|
|
|
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]} {
|
2007-07-21 14:21:34 +02:00
|
|
|
info_popup [mc "Cannot abort while amending.
|
2007-05-08 05:35:48 +02:00
|
|
|
|
|
|
|
You must finish amending this commit.
|
2007-07-21 14:21:34 +02:00
|
|
|
"]
|
2007-05-08 05:35:48 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {![lock_index abort]} return
|
|
|
|
|
|
|
|
if {[string match *merge* $commit_type]} {
|
2007-07-21 14:21:34 +02:00
|
|
|
set op_question [mc "Abort merge?
|
2007-07-28 22:17:10 +02:00
|
|
|
|
|
|
|
Aborting the current merge will cause *ALL* uncommitted changes to be lost.
|
|
|
|
|
2007-07-21 14:21:34 +02:00
|
|
|
Continue with aborting the current merge?"]
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
2007-07-21 14:21:34 +02:00
|
|
|
set op_question [mc "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-21 14:21:34 +02:00
|
|
|
Continue with resetting the current changes?"]
|
2007-07-28 22:17:10 +02:00
|
|
|
}
|
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]]
|
2008-02-02 10:20:17 +01:00
|
|
|
$::main_status start [mc "Aborting"] [mc "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]}
|
2008-07-12 16:56:59 +02:00
|
|
|
catch {file delete [gitdir MERGE_RR]}
|
2007-05-08 05:35:48 +02:00
|
|
|
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} {
|
2007-07-21 14:21:34 +02:00
|
|
|
warn_popup "[mc "Abort failed."]\n\n$err"
|
2007-07-29 10:06:51 +02:00
|
|
|
}
|
2007-07-21 14:21:34 +02:00
|
|
|
rescan {ui_status [mc "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
|
|
|
|
|
|
|
}
|