@matheusbsbs / matheus-bagliano / commits / 359ca42a4b
Fork 0

git-gui: Automatically skip tracking branches in branch menu.

Since the user should not work on a tracking branch we automatically hide any branch which is used as a tracking branch by either a remote.<name>.fetch config entry or by a Pull: line in a remotes file. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 25, 2006 at 03:33 UTC 359ca42a4b9288421d2f0409652f76e9a365b801
1 file changed +37 -9
git-gui
+37 -9
@@ -1610,7 +1610,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} {
1610 ## branch management
1611
1612 proc load_all_branches {} {
1613 - global all_branches
1613 + global all_branches tracking_branches
1614
1615 set all_branches [list]
1616 set cmd [list git for-each-ref]
@@ -1618,9 +1618,9 @@ proc load_all_branches {} {
1618 lappend cmd refs/heads
1619 set fd [open "| $cmd" r]
1620 while {[gets $fd line] > 0} {
1621 - if {[regsub ^refs/heads/ $line {} line]} {
1622 - lappend all_branches $line
1623 - }
1621 + if {![catch {set info $tracking_branches($line)}]} continue
1622 + if {![regsub ^refs/heads/ $line {} name]} continue
1623 + lappend all_branches $name
1624 }
1625 close $fd
1626
@@ -1652,21 +1652,49 @@ proc switch_branch {b} {
1652 ## remote management
1653
1654 proc load_all_remotes {} {
1655 - global gitdir all_remotes repo_config
1655 + global gitdir repo_config
1656 + global all_remotes tracking_branches
1657
1658 set all_remotes [list]
1659 + array unset tracking_branches
1660 +
1661 set rm_dir [file join $gitdir remotes]
1662 if {[file isdirectory $rm_dir]} {
1660 - set all_remotes [concat $all_remotes [glob \
1663 + set all_remotes [glob \
1664 -types f \
1665 -tails \
1666 -nocomplain \
1664 - -directory $rm_dir *]]
1667 + -directory $rm_dir *]
1668 +
1669 + foreach name $all_remotes {
1670 + catch {
1671 + set fd [open [file join $rm_dir $name] r]
1672 + while {[gets $fd line] >= 0} {
1673 + if {![regexp {^Pull:[ ]*([^:]+):(.+)$} \
1674 + $line line src dst]} continue
1675 + if {![regexp ^refs/ $dst]} {
1676 + set dst "refs/heads/$dst"
1677 + }
1678 + set tracking_branches($dst) [list $name $src]
1679 + }
1680 + close $fd
1681 + }
1682 + }
1683 }
1684
1685 foreach line [array names repo_config remote.*.url] {
1668 - if {[regexp ^remote\.(.*)\.url\$ $line line name]} {
1669 - lappend all_remotes $name
1686 + if {![regexp ^remote\.(.*)\.url\$ $line line name]} continue
1687 + lappend all_remotes $name
1688 +
1689 + if {[catch {set fl $repo_config(remote.$name.fetch)}]} {
1690 + set fl {}
1691 + }
1692 + foreach line $fl {
1693 + if {![regexp {^([^:]+):(.+)$} $line line src dst]} continue
1694 + if {![regexp ^refs/ $dst]} {
1695 + set dst "refs/heads/$dst"
1696 + }
1697 + set tracking_branches($dst) [list $name $src]
1698 }
1699 }
1700