@@ -9824,14 +9824,18 @@ proc readresetstat {fd} {
98249824
98259825# context menu for a head
98269826proc headmenu {x y id head} {
9827- global headmenuid headmenuhead headctxmenu mainhead
9827+ global headmenuid headmenuhead headctxmenu mainhead headids
98289828
98299829 stopfinding
98309830 set headmenuid $id
98319831 set headmenuhead $head
98329832 array set state {0 normal 1 normal 2 normal}
98339833 if {[string match " remotes/*" $head ]} {
9834- array set state {0 disabled 1 disabled 2 disabled}
9834+ set localhead [string range $head [expr [string last / $head ] + 1] end]
9835+ if {[info exists headids($localhead )]} {
9836+ set state(0) disabled
9837+ }
9838+ array set state {1 disabled 2 disabled}
98359839 }
98369840 if {$head eq $mainhead } {
98379841 array set state {0 disabled 2 disabled}
@@ -9847,24 +9851,40 @@ proc cobranch {} {
98479851 global showlocalchanges
98489852
98499853 # check the tree is clean first??
9854+ set newhead $headmenuhead
9855+ set command [list | git checkout]
9856+ if {[string match " remotes/*" $newhead ]} {
9857+ set remote $newhead
9858+ set newhead [string range $newhead [expr [string last / $newhead ] + 1] end]
9859+ # The following check is redundant - the menu option should
9860+ # be disabled to begin with...
9861+ if {[info exists headids($newhead )]} {
9862+ error_popup [mc " A local branch named %s exists already" $newhead ]
9863+ return
9864+ }
9865+ lappend command -b $newhead --track $remote
9866+ } else {
9867+ lappend command $newhead
9868+ }
9869+ lappend command 2>@1
98509870 nowbusy checkout [mc " Checking out" ]
98519871 update
98529872 dohidelocalchanges
98539873 if {[catch {
9854- set fd [open [ list | git checkout $headmenuhead 2>@1] r]
9874+ set fd [open $command r]
98559875 } err]} {
98569876 notbusy checkout
98579877 error_popup $err
98589878 if {$showlocalchanges } {
98599879 dodiffindex
98609880 }
98619881 } else {
9862- filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid ]
9882+ filerun $fd [list readcheckoutstat $fd $newhead $headmenuid ]
98639883 }
98649884}
98659885
98669886proc readcheckoutstat {fd newhead newheadid} {
9867- global mainhead mainheadid headids showlocalchanges progresscoords
9887+ global mainhead mainheadid headids idheads showlocalchanges progresscoords
98689888 global viewmainheadid curview
98699889
98709890 if {[gets $fd line] >= 0} {
@@ -9879,8 +9899,14 @@ proc readcheckoutstat {fd newhead newheadid} {
98799899 notbusy checkout
98809900 if {[catch {close $fd } err]} {
98819901 error_popup $err
9902+ return
98829903 }
98839904 set oldmainid $mainheadid
9905+ if {! [info exists headids($newhead )]} {
9906+ set headids($newhead ) $newheadid
9907+ lappend idheads($newheadid ) $newhead
9908+ addedhead $newheadid $newhead
9909+ }
98849910 set mainhead $newhead
98859911 set mainheadid $newheadid
98869912 set viewmainheadid($curview ) $newheadid
0 commit comments