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

git-gui: Added support for pulling from default branch of a remote.

We now create one menu entry per remote listing the first Pull: or fetch entry associated with that remote as the branch to pull into the current branch. This is actually quite incorrect as we should be using the default remote branch name listed in branch.<name>.merge for a new-style remote described in the config file. But its a good default to get started with. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 7, 2006 at 05:02 UTC d33ba5fa809be1714c7f31f128a7a72461a96d96
1 file changed +70 -9
git-gui
+70 -9
@@ -592,16 +592,31 @@ proc fetch_from {remote} {
592 set w [new_console "fetch $remote" \
593 "Fetching new changes from $remote"]
594 set cmd [list git fetch]
595 - lappend cmd -v
595 lappend cmd $remote
596 console_exec $w $cmd
597 }
598
599 +proc pull_remote {remote branch} {
600 + set w [new_console "pull $remote $branch" \
601 + "Pulling new changes from branch $branch in $remote"]
602 + set cmd [list git pull]
603 + lappend cmd $remote
604 + lappend cmd $branch
605 + console_exec $w $cmd [list post_pull_remote $remote $branch]
606 +}
607 +
608 +proc post_pull_remote {remote branch success} {
609 + if {$success} {
610 + update_status "Successfully pulled $branch from $remote."
611 + } else {
612 + update_status "Conflicts detected while pulling $branch from $remote."
613 + }
614 +}
615 +
616 proc push_to {remote} {
617 set w [new_console "push $remote" \
618 "Pushing changes to $remote"]
619 set cmd [list git push]
604 - lappend -v
620 lappend cmd $remote
621 console_exec $w $cmd
622 }
@@ -829,7 +844,7 @@ proc load_all_remotes {} {
844 }
845
846 proc populate_remote_menu {m pfx op} {
832 - global gitdir all_remotes mainfont
847 + global all_remotes mainfont
848
849 foreach remote $all_remotes {
850 $m add command -label "$pfx $remote..." \
@@ -838,6 +853,40 @@ proc populate_remote_menu {m pfx op} {
853 }
854 }
855
856 +proc populate_pull_menu {m} {
857 + global gitdir repo_config all_remotes mainfont
858 +
859 + foreach remote $all_remotes {
860 + set rb {}
861 + if {[array get repo_config remote.$remote.url] != {}} {
862 + if {[array get repo_config remote.$remote.fetch] != {}} {
863 + regexp {^([^:]+):} \
864 + [lindex $repo_config(remote.$remote.fetch) 0] \
865 + line rb
866 + }
867 + } else {
868 + catch {
869 + set fd [open [file join $gitdir remotes $remote] r]
870 + while {[gets $fd line] >= 0} {
871 + if {[regexp {^Pull:[ \t]*([^:]+):} $line line rb]} {
872 + break
873 + }
874 + }
875 + close $fd
876 + }
877 + }
878 +
879 + set rb_short $rb
880 + regsub ^refs/heads/ $rb {} rb_short
881 + if {$rb_short != {}} {
882 + $m add command \
883 + -label "Branch $rb_short from $remote..." \
884 + -command [list pull_remote $remote $rb] \
885 + -font $mainfont
886 + }
887 + }
888 +}
889 +
890 ######################################################################
891 ##
892 ## icons
@@ -966,7 +1015,9 @@ proc show_msg {w top msg} {
1015 pack $w.ok -side bottom
1016 bind $top <Visibility> "grab $top; focus $top"
1017 bind $top <Key-Return> "destroy $top"
969 - wm title $top "error: $appname ([file normalize [file dirname $gitdir]])"
1018 + wm title $w "$appname ([lindex [file split \
1019 + [file normalize [file dirname $gitdir]]] \
1020 + end]): error"
1021 tkwait window $top
1022 }
1023
@@ -1011,7 +1062,9 @@ proc hook_failed_popup {hook msg} {
1062
1063 bind $w <Visibility> "grab $w; focus $w"
1064 bind $w <Key-Return> "destroy $w"
1014 - wm title $w "error: $appname ([file normalize [file dirname $gitdir]])"
1065 + wm title $w "$appname ([lindex [file split \
1066 + [file normalize [file dirname $gitdir]]] \
1067 + end]): error"
1068 tkwait window $w
1069 }
1070
@@ -1060,11 +1113,13 @@ proc console_init {w} {
1113 pack $w.ok -side bottom
1114
1115 bind $w <Visibility> "focus $w"
1063 - wm title $w "$appname ([file dirname [file normalize [file dirname $gitdir]]]): [lindex $console_data($w) 0]"
1116 + wm title $w "$appname ([lindex [file split \
1117 + [file normalize [file dirname $gitdir]]] \
1118 + end]): [lindex $console_data($w) 0]"
1119 return $w
1120 }
1121
1067 -proc console_exec {w cmd} {
1122 +proc console_exec {w cmd {after {}}} {
1123 global tcl_platform
1124
1125 # -- Windows tosses the enviroment when we exec our child.
@@ -1081,10 +1136,10 @@ proc console_exec {w cmd} {
1136
1137 set fd_f [open $cmd r]
1138 fconfigure $fd_f -blocking 0 -translation binary
1084 - fileevent $fd_f readable [list console_read $w $fd_f]
1139 + fileevent $fd_f readable [list console_read $w $fd_f $after]
1140 }
1141
1087 -proc console_read {w fd} {
1142 +proc console_read {w fd after} {
1143 global console_cr console_data
1144
1145 set buf [read $fd]
@@ -1123,13 +1178,18 @@ proc console_read {w fd} {
1178 $w.m.s conf -background red -text {Error: Command Failed}
1179 $w.ok conf -text Close
1180 $w.ok conf -state normal
1181 + set ok 0
1182 } elseif {[winfo exists $w]} {
1183 $w.m.s conf -background green -text {Success}
1184 $w.ok conf -text Close
1185 $w.ok conf -state normal
1186 + set ok 1
1187 }
1188 array unset console_cr $w
1189 array unset console_data $w
1190 + if {$after != {}} {
1191 + uplevel #0 $after $ok
1192 + }
1193 return
1194 }
1195 fconfigure $fd -blocking 0
@@ -1558,4 +1618,5 @@ load_repo_config
1618 load_all_remotes
1619 populate_remote_menu .mbar.fetch From fetch_from
1620 populate_remote_menu .mbar.push To push_to
1621 +populate_pull_menu .mbar.pull
1622 update_status