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
22 foreach spec
$tracking_branches {
23 set name
[lindex $spec 0]
24 if {[string range
$name end-1 end
] eq
{/*}} {
25 lappend cmd
[string range
$name 0 end-2
]
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 some_heads_tracking
48 set some_heads_tracking
0
49 set all_remotes
[list]
52 set rh_str refs
/heads
/
53 set rh_len
[string length
$rh_str]
54 set rm_dir
[gitdir remotes
]
55 if {[file isdirectory
$rm_dir]} {
56 set all_remotes
[glob \
62 foreach name
$all_remotes {
64 set fd
[open [file join $rm_dir $name] r
]
65 while {[gets $fd line
] >= 0} {
66 if {![regexp {^Pull
:[ ]*([^
:]+):(.
+)$} \
67 $line line src dst
]} continue
68 if {![string equal
-length 5 refs
/ $src]} {
71 if {![string equal
-length 5 refs
/ $dst]} {
74 if {[string equal
-length $rh_len $rh_str $dst]} {
75 set some_heads_tracking
1
77 lappend trck
[list $dst $name $src]
84 foreach line
[array names repo_config remote.
*.url
] {
85 if {![regexp ^remote
\.
(.
*)\.url
\$ $line line name
]} continue
86 lappend all_remotes
$name
88 if {[catch {set fl
$repo_config(remote.
$name.fetch
)}]} {
92 if {![regexp {^
([^
:]+):(.
+)$} $line line src dst
]} continue
93 if {![string equal
-length 5 refs
/ $src]} {
96 if {![string equal
-length 5 refs
/ $dst]} {
99 if {[string equal
-length $rh_len $rh_str $dst]} {
100 set some_heads_tracking
1
102 lappend trck
[list $dst $name $src]
106 set tracking_branches
[lsort -index 0 -unique $trck]
107 set all_remotes
[lsort -unique $all_remotes]
110 proc populate_fetch_menu
{} {
111 global all_remotes repo_config
114 set prune_list
[list]
115 foreach r
$all_remotes {
117 if {![catch {set a
$repo_config(remote.
$r.url
)}]} {
118 if {![catch {set a
$repo_config(remote.
$r.fetch
)}]} {
123 set fd
[open [gitdir remotes
$r] r
]
124 while {[gets $fd n
] >= 0} {
125 if {[regexp {^Pull
:[ \t]*([^
:]+):} $n]} {
135 lappend prune_list
$r
137 -label "Fetch from $r..." \
138 -command [list fetch_from
$r]
142 if {$prune_list ne
{}} {
145 foreach r
$prune_list {
147 -label "Prune from $r..." \
148 -command [list prune_from
$r]
152 proc populate_push_menu
{} {
153 global all_remotes repo_config
157 foreach r
$all_remotes {
159 if {![catch {set a
$repo_config(remote.
$r.url
)}]} {
160 if {![catch {set a
$repo_config(remote.
$r.push
)}]} {
165 set fd
[open [gitdir remotes
$r] r
]
166 while {[gets $fd n
] >= 0} {
167 if {[regexp {^Push
:[ \t]*([^
:]+):} $n]} {
181 -label "Push to $r..." \
182 -command [list push_to
$r]