@@ -9824,14 +9824,18 @@ proc readresetstat {fd} {
9824
9824
9825
9825
# context menu for a head
9826
9826
proc headmenu {x y id head} {
9827
- global headmenuid headmenuhead headctxmenu mainhead
9827
+ global headmenuid headmenuhead headctxmenu mainhead headids
9828
9828
9829
9829
stopfinding
9830
9830
set headmenuid $id
9831
9831
set headmenuhead $head
9832
9832
array set state {0 normal 1 normal 2 normal}
9833
9833
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}
9835
9839
}
9836
9840
if {$head eq $mainhead } {
9837
9841
array set state {0 disabled 2 disabled}
@@ -9847,24 +9851,40 @@ proc cobranch {} {
9847
9851
global showlocalchanges
9848
9852
9849
9853
# 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
9850
9870
nowbusy checkout [mc " Checking out" ]
9851
9871
update
9852
9872
dohidelocalchanges
9853
9873
if {[catch {
9854
- set fd [open [ list | git checkout $headmenuhead 2>@1] r]
9874
+ set fd [open $command r]
9855
9875
} err]} {
9856
9876
notbusy checkout
9857
9877
error_popup $err
9858
9878
if {$showlocalchanges } {
9859
9879
dodiffindex
9860
9880
}
9861
9881
} else {
9862
- filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid ]
9882
+ filerun $fd [list readcheckoutstat $fd $newhead $headmenuid ]
9863
9883
}
9864
9884
}
9865
9885
9866
9886
proc readcheckoutstat {fd newhead newheadid} {
9867
- global mainhead mainheadid headids showlocalchanges progresscoords
9887
+ global mainhead mainheadid headids idheads showlocalchanges progresscoords
9868
9888
global viewmainheadid curview
9869
9889
9870
9890
if {[gets $fd line] >= 0} {
@@ -9879,8 +9899,14 @@ proc readcheckoutstat {fd newhead newheadid} {
9879
9899
notbusy checkout
9880
9900
if {[catch {close $fd } err]} {
9881
9901
error_popup $err
9902
+ return
9882
9903
}
9883
9904
set oldmainid $mainheadid
9905
+ if {! [info exists headids($newhead )]} {
9906
+ set headids($newhead ) $newheadid
9907
+ lappend idheads($newheadid ) $newhead
9908
+ addedhead $newheadid $newhead
9909
+ }
9884
9910
set mainhead $newhead
9885
9911
set mainheadid $newheadid
9886
9912
set viewmainheadid($curview ) $newheadid
0 commit comments