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
99 foreach r $all_remotes {
101 if {![catch {set a $repo_config(remote.$r.url)}]} {
102 if {![catch {set a $repo_config(remote.$r.fetch)}]} {
107 set fd [open [gitdir remotes $r] r]
108 while {[gets $fd n] >= 0} {
109 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
119 lappend prune_list $r
121 -label "Fetch from $r..." \
122 -command [list fetch_from $r]
126 if {$prune_list ne {}} {
129 foreach r $prune_list {
131 -label "Prune from $r..." \
132 -command [list prune_from $r]
136 proc populate_push_menu {} {
137 global all_remotes repo_config
141 foreach r $all_remotes {
143 if {![catch {set a $repo_config(remote.$r.url)}]} {
144 if {![catch {set a $repo_config(remote.$r.push)}]} {
149 set fd [open [gitdir remotes $r] r]
150 while {[gets $fd n] >= 0} {
151 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
165 -label "Push to $r..." \
166 -command [list push_to $r]