@matheusbsbs / matheus-bagliano / commits / ead49f5a4f
Fork 0

git-gui: Format tracking branch merges as though they were pulls

If we are merging a tracking branch we know exactly what remote URL that branch is fetched from, and what its name is on that remote repository. In this case we can setup a merge message that looks just like a standard `git-pull $remote $branch` operation by filling out FETCH_HEAD before we start git-merge, and then run git-merge just like git-pull does. I think the result of this behavior is that merges look a lot nicer when the came off of local tracking branches, because they no longer say "commit 'origin/...'" to describe the commit being merged but instead now mention the specific repository we fetched those commits from. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 25, 2007 at 04:54 UTC ead49f5a4f6c87e5dc61ed5daaeda1bae7644d05
1 file changed +28 -4
lib/merge.tcl
+28 -4
@@ -81,17 +81,41 @@ method _visualize {} {
81 }
82
83 method _start {} {
84 - global HEAD current_branch
84 + global HEAD current_branch remote_url
85
86 set name [_rev $this]
87 if {$name eq {}} {
88 return
89 }
90
91 - set cmd [list git merge $name]
92 - set msg "Merging $current_branch and $name"
91 + set spec [$w_rev get_tracking_branch]
92 + set cmit [$w_rev get_commit]
93 + set cmd [list git]
94 + lappend cmd merge
95 + lappend cmd --strategy=recursive
96 +
97 + set fh [open [gitdir FETCH_HEAD] w]
98 + fconfigure $fh -translation lf
99 + if {$spec eq {}} {
100 + set remote .
101 + set branch $name
102 + set stitle $branch
103 + } else {
104 + set remote $remote_url([lindex $spec 1])
105 + set branch [lindex $spec 2]
106 + set stitle "$branch of $remote"
107 + }
108 + regsub ^refs/heads/ $branch {} branch
109 + puts $fh "$cmit\t\tbranch '$branch' of $remote"
110 + close $fh
111 +
112 + lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
113 + lappend cmd HEAD
114 + lappend cmd $cmit
115 +
116 + set msg "Merging $current_branch and $stitle"
117 ui_status "$msg..."
94 - set cons [console::new "Merge" $cmd]
118 + set cons [console::new "Merge" "merge $stitle"]
119 console::exec $cons $cmd [cb _finish $cons]
120
121 wm protocol $w WM_DELETE_WINDOW {}