Skip to content

Commit 15e3505

Browse files
angavrilovpaulusmack
authored andcommitted
gitk: Make cherry-pick call git-citool on conflicts
Now that git-gui has facilities to help users resolve conflicts, it makes sense to launch it from other GUI tools when they happen. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 84a76f1 commit 15e3505

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

gitk

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8088,6 +8088,32 @@ proc mkbrgo {top} {
80888088
}
80898089
}
80908090

8091+
proc exec_citool {tool_args {baseid {}}} {
8092+
global commitinfo env
8093+
8094+
set save_env [array get env GIT_AUTHOR_*]
8095+
8096+
if {$baseid ne {}} {
8097+
if {![info exists commitinfo($baseid)]} {
8098+
getcommit $baseid
8099+
}
8100+
set author [lindex $commitinfo($baseid) 1]
8101+
set date [lindex $commitinfo($baseid) 2]
8102+
if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
8103+
$author author name email]
8104+
&& $date ne {}} {
8105+
set env(GIT_AUTHOR_NAME) $name
8106+
set env(GIT_AUTHOR_EMAIL) $email
8107+
set env(GIT_AUTHOR_DATE) $date
8108+
}
8109+
}
8110+
8111+
eval exec git citool $tool_args &
8112+
8113+
array unset env GIT_AUTHOR_*
8114+
array set env $save_env
8115+
}
8116+
80918117
proc cherrypick {} {
80928118
global rowmenuid curview
80938119
global mainhead mainheadid
@@ -8106,7 +8132,19 @@ proc cherrypick {} {
81068132
# no error occurs, and exec takes that as an indication of error...
81078133
if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
81088134
notbusy cherrypick
8109-
error_popup $err
8135+
if {[regexp -line \
8136+
{Entry '(.*)' would be overwritten by merge} $err msg fname]} {
8137+
error_popup [mc "Cherry-pick failed:
8138+
file '%s' had local modifications.
8139+
8140+
Please commit, reset or stash your changes." $fname]
8141+
} elseif {[regexp -line {^CONFLICT \(.*\):} $err msg]} {
8142+
# Force citool to read MERGE_MSG
8143+
file delete [file join [gitdir] "GITGUI_MSG"]
8144+
exec_citool {} $rowmenuid
8145+
} else {
8146+
error_popup $err
8147+
}
81108148
return
81118149
}
81128150
set newhead [exec git rev-parse HEAD]

0 commit comments

Comments
 (0)