2007-05-08 05:35:48 +02:00
|
|
|
# git-gui remote management
|
|
|
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set some_heads_tracking 0; # assume not
|
|
|
|
|
2007-05-08 05:35:48 +02:00
|
|
|
proc is_tracking_branch {name} {
|
|
|
|
global tracking_branches
|
2007-07-04 06:15:41 +02:00
|
|
|
foreach spec $tracking_branches {
|
|
|
|
set t [lindex $spec 0]
|
|
|
|
if {$t eq $name || [string match $t $name]} {
|
2007-05-08 05:35:48 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
proc all_tracking_branches {} {
|
|
|
|
global tracking_branches
|
|
|
|
|
2007-07-04 07:10:41 +02:00
|
|
|
set all [list]
|
|
|
|
set pat [list]
|
|
|
|
set cmd [list]
|
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
foreach spec $tracking_branches {
|
2007-07-04 07:10:41 +02:00
|
|
|
set dst [lindex $spec 0]
|
|
|
|
if {[string range $dst end-1 end] eq {/*}} {
|
|
|
|
lappend pat $spec
|
|
|
|
lappend cmd [string range $dst 0 end-2]
|
2007-05-08 05:35:48 +02:00
|
|
|
} else {
|
2007-07-04 07:10:41 +02:00
|
|
|
lappend all $spec
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 07:10:41 +02:00
|
|
|
if {$pat ne {}} {
|
2007-07-09 07:17:09 +02:00
|
|
|
set fd [eval git_read for-each-ref --format=%(refname) $cmd]
|
2007-07-04 07:10:41 +02:00
|
|
|
while {[gets $fd n] > 0} {
|
|
|
|
foreach spec $pat {
|
|
|
|
set dst [string range [lindex $spec 0] 0 end-2]
|
|
|
|
set len [string length $dst]
|
|
|
|
if {[string equal -length $len $dst $n]} {
|
|
|
|
set src [string range [lindex $spec 2] 0 end-2]
|
|
|
|
set spec [list \
|
|
|
|
$n \
|
|
|
|
[lindex $spec 1] \
|
|
|
|
$src[string range $n $len end] \
|
|
|
|
]
|
|
|
|
lappend all $spec
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|
2007-07-04 07:10:41 +02:00
|
|
|
return [lsort -index 0 -unique $all]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proc load_all_remotes {} {
|
|
|
|
global repo_config
|
2007-07-04 06:15:41 +02:00
|
|
|
global all_remotes tracking_branches some_heads_tracking
|
2007-07-25 09:27:57 +02:00
|
|
|
global remote_url
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set some_heads_tracking 0
|
2007-05-08 05:35:48 +02:00
|
|
|
set all_remotes [list]
|
2007-07-04 06:15:41 +02:00
|
|
|
set trck [list]
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set rh_str refs/heads/
|
|
|
|
set rh_len [string length $rh_str]
|
2007-05-08 05:35:48 +02:00
|
|
|
set rm_dir [gitdir remotes]
|
|
|
|
if {[file isdirectory $rm_dir]} {
|
|
|
|
set all_remotes [glob \
|
|
|
|
-types f \
|
|
|
|
-tails \
|
|
|
|
-nocomplain \
|
|
|
|
-directory $rm_dir *]
|
|
|
|
|
|
|
|
foreach name $all_remotes {
|
|
|
|
catch {
|
|
|
|
set fd [open [file join $rm_dir $name] r]
|
|
|
|
while {[gets $fd line] >= 0} {
|
2007-07-25 09:27:57 +02:00
|
|
|
if {[regexp {^URL:[ ]*(.+)$} $line line url]} {
|
|
|
|
set remote_url($name) $url
|
|
|
|
continue
|
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
|
|
|
|
$line line src dst]} continue
|
2007-07-04 07:10:41 +02:00
|
|
|
if {[string index $src 0] eq {+}} {
|
|
|
|
set src [string range $src 1 end]
|
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
if {![string equal -length 5 refs/ $src]} {
|
|
|
|
set src $rh_str$src
|
|
|
|
}
|
|
|
|
if {![string equal -length 5 refs/ $dst]} {
|
|
|
|
set dst $rh_str$dst
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
if {[string equal -length $rh_len $rh_str $dst]} {
|
|
|
|
set some_heads_tracking 1
|
|
|
|
}
|
|
|
|
lappend trck [list $dst $name $src]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach line [array names repo_config remote.*.url] {
|
|
|
|
if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
|
|
|
|
lappend all_remotes $name
|
2007-07-25 09:27:57 +02:00
|
|
|
set remote_url($name) $repo_config(remote.$name.url)
|
2007-05-08 05:35:48 +02:00
|
|
|
|
|
|
|
if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
|
|
|
|
set fl {}
|
|
|
|
}
|
|
|
|
foreach line $fl {
|
|
|
|
if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
|
2007-07-04 07:10:41 +02:00
|
|
|
if {[string index $src 0] eq {+}} {
|
|
|
|
set src [string range $src 1 end]
|
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
if {![string equal -length 5 refs/ $src]} {
|
|
|
|
set src $rh_str$src
|
|
|
|
}
|
|
|
|
if {![string equal -length 5 refs/ $dst]} {
|
|
|
|
set dst $rh_str$dst
|
|
|
|
}
|
|
|
|
if {[string equal -length $rh_len $rh_str $dst]} {
|
|
|
|
set some_heads_tracking 1
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2007-07-04 06:15:41 +02:00
|
|
|
lappend trck [list $dst $name $src]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 06:15:41 +02:00
|
|
|
set tracking_branches [lsort -index 0 -unique $trck]
|
2007-05-08 05:35:48 +02:00
|
|
|
set all_remotes [lsort -unique $all_remotes]
|
|
|
|
}
|
|
|
|
|
2008-09-24 22:44:00 +02:00
|
|
|
proc add_fetch_entry {r} {
|
|
|
|
global repo_config
|
2007-10-08 07:23:54 +02:00
|
|
|
set remote_m .mbar.remote
|
|
|
|
set fetch_m $remote_m.fetch
|
|
|
|
set prune_m $remote_m.prune
|
2008-09-24 22:44:02 +02:00
|
|
|
set remove_m $remote_m.remove
|
2008-09-24 22:44:00 +02:00
|
|
|
set enable 0
|
|
|
|
if {![catch {set a $repo_config(remote.$r.url)}]} {
|
|
|
|
if {![catch {set a $repo_config(remote.$r.fetch)}]} {
|
|
|
|
set enable 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
catch {
|
|
|
|
set fd [open [gitdir remotes $r] r]
|
|
|
|
while {[gets $fd n] >= 0} {
|
|
|
|
if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
|
|
|
|
set enable 1
|
|
|
|
break
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-24 22:44:00 +02:00
|
|
|
close $fd
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2008-09-24 22:44:00 +02:00
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2008-09-24 22:44:00 +02:00
|
|
|
if {$enable} {
|
2011-02-13 14:50:38 +01:00
|
|
|
make_sure_remote_submenues_exist $remote_m
|
2008-09-24 22:44:00 +02:00
|
|
|
|
|
|
|
$fetch_m add command \
|
|
|
|
-label $r \
|
|
|
|
-command [list fetch_from $r]
|
|
|
|
$prune_m add command \
|
|
|
|
-label $r \
|
|
|
|
-command [list prune_from $r]
|
2008-09-24 22:44:02 +02:00
|
|
|
$remove_m add command \
|
|
|
|
-label $r \
|
|
|
|
-command [list remove_remote $r]
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-24 22:44:00 +02:00
|
|
|
proc add_push_entry {r} {
|
|
|
|
global repo_config
|
2007-10-08 07:23:54 +02:00
|
|
|
set remote_m .mbar.remote
|
|
|
|
set push_m $remote_m.push
|
2008-09-24 22:44:00 +02:00
|
|
|
set enable 0
|
|
|
|
if {![catch {set a $repo_config(remote.$r.url)}]} {
|
|
|
|
if {![catch {set a $repo_config(remote.$r.push)}]} {
|
|
|
|
set enable 1
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
catch {
|
|
|
|
set fd [open [gitdir remotes $r] r]
|
|
|
|
while {[gets $fd n] >= 0} {
|
|
|
|
if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
|
|
|
|
set enable 1
|
|
|
|
break
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-24 22:44:00 +02:00
|
|
|
close $fd
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2008-09-24 22:44:00 +02:00
|
|
|
}
|
2007-05-08 05:35:48 +02:00
|
|
|
|
2008-09-24 22:44:00 +02:00
|
|
|
if {$enable} {
|
|
|
|
if {![winfo exists $push_m]} {
|
|
|
|
menu $push_m
|
|
|
|
$remote_m insert 0 cascade \
|
|
|
|
-label [mc "Push to"] \
|
|
|
|
-menu $push_m
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2008-09-24 22:44:00 +02:00
|
|
|
|
|
|
|
$push_m add command \
|
|
|
|
-label $r \
|
|
|
|
-command [list push_to $r]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:50:38 +01:00
|
|
|
proc make_sure_remote_submenues_exist {remote_m} {
|
|
|
|
set fetch_m $remote_m.fetch
|
|
|
|
set prune_m $remote_m.prune
|
|
|
|
set remove_m $remote_m.remove
|
|
|
|
|
|
|
|
if {![winfo exists $fetch_m]} {
|
|
|
|
menu $remove_m
|
|
|
|
$remote_m insert 0 cascade \
|
|
|
|
-label [mc "Remove Remote"] \
|
|
|
|
-menu $remove_m
|
|
|
|
|
|
|
|
menu $prune_m
|
|
|
|
$remote_m insert 0 cascade \
|
|
|
|
-label [mc "Prune from"] \
|
|
|
|
-menu $prune_m
|
|
|
|
|
|
|
|
menu $fetch_m
|
|
|
|
$remote_m insert 0 cascade \
|
|
|
|
-label [mc "Fetch from"] \
|
|
|
|
-menu $fetch_m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:57:15 +01:00
|
|
|
proc update_all_remotes_menu_entry {} {
|
|
|
|
global all_remotes
|
|
|
|
|
2011-02-15 01:20:36 +01:00
|
|
|
if {[git-version < 1.6.6]} { return }
|
|
|
|
|
2011-02-13 14:57:15 +01:00
|
|
|
set have_remote 0
|
|
|
|
foreach r $all_remotes {
|
2011-02-22 20:28:36 +01:00
|
|
|
incr have_remote
|
2011-02-13 14:57:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set remote_m .mbar.remote
|
|
|
|
set fetch_m $remote_m.fetch
|
|
|
|
set prune_m $remote_m.prune
|
2011-02-22 20:28:36 +01:00
|
|
|
if {$have_remote > 1} {
|
2011-02-13 14:57:15 +01:00
|
|
|
make_sure_remote_submenues_exist $remote_m
|
2013-06-16 00:36:27 +02:00
|
|
|
if {[$fetch_m type end] eq "command" \
|
2016-10-13 20:43:48 +02:00
|
|
|
&& [$fetch_m entrycget end -label] ne [mc "All"]} {
|
2011-02-13 14:57:15 +01:00
|
|
|
|
2011-02-22 20:30:21 +01:00
|
|
|
$fetch_m insert end separator
|
|
|
|
$fetch_m insert end command \
|
2016-10-13 20:43:48 +02:00
|
|
|
-label [mc "All"] \
|
2011-02-13 14:57:15 +01:00
|
|
|
-command fetch_from_all
|
|
|
|
|
2011-02-22 20:30:21 +01:00
|
|
|
$prune_m insert end separator
|
|
|
|
$prune_m insert end command \
|
2016-10-13 20:43:48 +02:00
|
|
|
-label [mc "All"] \
|
2011-02-13 14:57:15 +01:00
|
|
|
-command prune_from_all
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if {[winfo exists $fetch_m]} {
|
2013-06-16 00:36:27 +02:00
|
|
|
if {[$fetch_m type end] eq "command" \
|
2016-10-13 20:43:48 +02:00
|
|
|
&& [$fetch_m entrycget end -label] eq [mc "All"]} {
|
2011-02-13 14:57:15 +01:00
|
|
|
|
2011-02-22 20:30:21 +01:00
|
|
|
delete_from_menu $fetch_m end
|
|
|
|
delete_from_menu $fetch_m end
|
2011-02-13 14:57:15 +01:00
|
|
|
|
2011-02-22 20:30:21 +01:00
|
|
|
delete_from_menu $prune_m end
|
|
|
|
delete_from_menu $prune_m end
|
2011-02-13 14:57:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-24 22:44:00 +02:00
|
|
|
proc populate_remotes_menu {} {
|
|
|
|
global all_remotes
|
|
|
|
|
|
|
|
foreach r $all_remotes {
|
|
|
|
add_fetch_entry $r
|
|
|
|
add_push_entry $r
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2011-02-13 14:57:15 +01:00
|
|
|
|
|
|
|
update_all_remotes_menu_entry
|
2007-05-08 05:35:48 +02:00
|
|
|
}
|
2008-09-24 22:44:01 +02:00
|
|
|
|
|
|
|
proc add_single_remote {name location} {
|
|
|
|
global all_remotes repo_config
|
|
|
|
lappend all_remotes $name
|
|
|
|
|
|
|
|
git remote add $name $location
|
|
|
|
|
|
|
|
# XXX: Better re-read the config so that we will never get out
|
|
|
|
# of sync with git remote implementation?
|
|
|
|
set repo_config(remote.$name.url) $location
|
|
|
|
set repo_config(remote.$name.fetch) "+refs/heads/*:refs/remotes/$name/*"
|
|
|
|
|
|
|
|
add_fetch_entry $name
|
|
|
|
add_push_entry $name
|
2011-02-13 14:57:15 +01:00
|
|
|
|
|
|
|
update_all_remotes_menu_entry
|
2008-09-24 22:44:01 +02:00
|
|
|
}
|
2008-09-24 22:44:02 +02:00
|
|
|
|
|
|
|
proc delete_from_menu {menu name} {
|
|
|
|
if {[winfo exists $menu]} {
|
|
|
|
$menu delete $name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc remove_remote {name} {
|
|
|
|
global all_remotes repo_config
|
|
|
|
|
|
|
|
git remote rm $name
|
|
|
|
|
|
|
|
catch {
|
|
|
|
# Missing values are ok
|
|
|
|
unset repo_config(remote.$name.url)
|
|
|
|
unset repo_config(remote.$name.fetch)
|
|
|
|
unset repo_config(remote.$name.push)
|
|
|
|
}
|
|
|
|
|
2011-02-12 17:43:44 +01:00
|
|
|
set i [lsearch -exact $all_remotes $name]
|
|
|
|
set all_remotes [lreplace $all_remotes $i $i]
|
2008-09-24 22:44:02 +02:00
|
|
|
|
|
|
|
set remote_m .mbar.remote
|
|
|
|
delete_from_menu $remote_m.fetch $name
|
|
|
|
delete_from_menu $remote_m.prune $name
|
|
|
|
delete_from_menu $remote_m.remove $name
|
2008-09-25 01:32:47 +02:00
|
|
|
# Not all remotes are in the push menu
|
|
|
|
catch { delete_from_menu $remote_m.push $name }
|
2011-02-13 14:57:15 +01:00
|
|
|
|
|
|
|
update_all_remotes_menu_entry
|
2008-09-24 22:44:02 +02:00
|
|
|
}
|