1 # git-gui remote management
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 set some_heads_tracking 0; # assume not
6 proc is_tracking_branch {name} {
7 global tracking_branches
8 foreach spec $tracking_branches {
10 if {$t eq $name || [string match $t $name]} {
17 proc all_tracking_branches {} {
18 global tracking_branches
24 foreach spec $tracking_branches {
25 set dst [lindex $spec 0]
26 if {[string range $dst end-1 end] eq {/*}} {
28 lappend cmd [string range $dst 0 end-2]
35 set fd [open "| git for-each-ref --format=%(refname) $cmd" r]
36 while {[gets $fd n] > 0} {
38 set dst [string range [lindex $spec 0] 0 end-2]
39 set len [string length $dst]
40 if {[string equal -length $len $dst $n]} {
41 set src [string range [lindex $spec 2] 0 end-2]
45 $src[string range $n $len end] \
54 return [lsort -index 0 -unique $all]
57 proc load_all_remotes {} {
59 global all_remotes tracking_branches some_heads_tracking
61 set some_heads_tracking 0
62 set all_remotes [list]
65 set rh_str refs/heads/
66 set rh_len [string length $rh_str]
67 set rm_dir [gitdir remotes]
68 if {[file isdirectory $rm_dir]} {
69 set all_remotes [glob \
75 foreach name $all_remotes {
77 set fd [open [file join $rm_dir $name] r]
78 while {[gets $fd line] >= 0} {
79 if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
80 $line line src dst]} continue
81 if {[string index $src 0] eq {+}} {
82 set src [string range $src 1 end]
84 if {![string equal -length 5 refs/ $src]} {
87 if {![string equal -length 5 refs/ $dst]} {
90 if {[string equal -length $rh_len $rh_str $dst]} {
91 set some_heads_tracking 1
93 lappend trck [list $dst $name $src]
100 foreach line [array names repo_config remote.*.url] {
101 if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
102 lappend all_remotes $name
104 if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
108 if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
109 if {[string index $src 0] eq {+}} {
110 set src [string range $src 1 end]
112 if {![string equal -length 5 refs/ $src]} {
115 if {![string equal -length 5 refs/ $dst]} {
118 if {[string equal -length $rh_len $rh_str $dst]} {
119 set some_heads_tracking 1
121 lappend trck [list $dst $name $src]
125 set tracking_branches [lsort -index 0 -unique $trck]
126 set all_remotes [lsort -unique $all_remotes]
129 proc populate_fetch_menu {} {
130 global all_remotes repo_config
133 set prune_list [list]
134 foreach r $all_remotes {
136 if {![catch {set a $repo_config(remote.$r.url)}]} {
137 if {![catch {set a $repo_config(remote.$r.fetch)}]} {
142 set fd [open [gitdir remotes $r] r]
143 while {[gets $fd n] >= 0} {
144 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
154 lappend prune_list $r
156 -label "Fetch from $r..." \
157 -command [list fetch_from $r]
161 if {$prune_list ne {}} {
164 foreach r $prune_list {
166 -label "Prune from $r..." \
167 -command [list prune_from $r]
171 proc populate_push_menu {} {
172 global all_remotes repo_config
176 foreach r $all_remotes {
178 if {![catch {set a $repo_config(remote.$r.url)}]} {
179 if {![catch {set a $repo_config(remote.$r.push)}]} {
184 set fd [open [gitdir remotes $r] r]
185 while {[gets $fd n] >= 0} {
186 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
200 -label "Push to $r..." \
201 -command [list push_to $r]