1 # git-gui remote management
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 proc is_tracking_branch {name} {
5 global tracking_branches
7 if {![catch {set info $tracking_branches($name)}]} {
10 foreach t [array names tracking_branches] {
11 if {[string match {*/\*} $t] && [string match $t $name]} {
18 proc all_tracking_branches {} {
19 global tracking_branches
23 foreach name [array names tracking_branches] {
24 if {[regsub {/\*$} $name {} name]} {
27 regsub ^refs/(heads|remotes)/ $name {} name
28 lappend all_trackings $name
33 set fd [open "| git for-each-ref --format=%(refname) $cmd" r]
34 while {[gets $fd name] > 0} {
35 regsub ^refs/(heads|remotes)/ $name {} name
36 lappend all_trackings $name
41 return [lsort -unique $all_trackings]
44 proc load_all_remotes {} {
46 global all_remotes tracking_branches
48 set all_remotes [list]
49 array unset tracking_branches
51 set rm_dir [gitdir remotes]
52 if {[file isdirectory $rm_dir]} {
53 set all_remotes [glob \
59 foreach name $all_remotes {
61 set fd [open [file join $rm_dir $name] r]
62 while {[gets $fd line] >= 0} {
63 if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
64 $line line src dst]} continue
65 if {![regexp ^refs/ $dst]} {
66 set dst "refs/heads/$dst"
68 set tracking_branches($dst) [list $name $src]
75 foreach line [array names repo_config remote.*.url] {
76 if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
77 lappend all_remotes $name
79 if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
83 if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
84 if {![regexp ^refs/ $dst]} {
85 set dst "refs/heads/$dst"
87 set tracking_branches($dst) [list $name $src]
91 set all_remotes [lsort -unique $all_remotes]
94 proc populate_fetch_menu {} {
95 global all_remotes repo_config
98 foreach r $all_remotes {
100 if {![catch {set a $repo_config(remote.$r.url)}]} {
101 if {![catch {set a $repo_config(remote.$r.fetch)}]} {
106 set fd [open [gitdir remotes $r] r]
107 while {[gets $fd n] >= 0} {
108 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
119 -label "Fetch from $r..." \
120 -command [list fetch_from $r]
125 proc populate_push_menu {} {
126 global all_remotes repo_config
130 foreach r $all_remotes {
132 if {![catch {set a $repo_config(remote.$r.url)}]} {
133 if {![catch {set a $repo_config(remote.$r.push)}]} {
138 set fd [open [gitdir remotes $r] r]
139 while {[gets $fd n] >= 0} {
140 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
154 -label "Push to $r..." \
155 -command [list push_to $r]