From: Jens Lidestrom <jens@xxxxxxxxxxxx> This is a consequence of allowing checkout of detached heads (through keyboard shortcut). It doesn't make sense to disallow checkout of commits on remote branches if all other commits can be checked out. Signed-off-by: Jens Lidestrom <jens@xxxxxxxxxxxx> --- gitk-git/gitk | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index fafff2b1a5b..99f93371482 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -9989,10 +9989,6 @@ proc headmenu {x y id head} { set headmenuhead $head array set state {0 normal 1 normal 2 normal} if {[string match "remotes/*" $head]} { - set localhead [string range $head [expr [string last / $head] + 1] end] - if {[info exists headids($localhead)]} { - set state(0) disabled - } array set state {1 disabled 2 disabled} } if {$head eq $mainhead} { @@ -10078,17 +10074,29 @@ proc checkout {heads_on_commit id_to_checkout} { set ref_to_checkout $head_to_checkout } - # Handle remote branches set command [list | git checkout] if {[string match "remotes/*" $head_to_checkout]} { - set remote $head_to_checkout + # Handle remote branches + set remote_head $head_to_checkout set head_to_checkout [string range $head_to_checkout [expr [string last / $head_to_checkout] + 1] end] - set ref_to_checkout $head_to_checkout if {[info exists headids($head_to_checkout)]} { - error_popup [mc "A local branch named %s exists already" $head_to_checkout] - return + # The local branch exists + set id_to_checkout $headids($remote_head) + if {$headids($head_to_checkout) eq $id_to_checkout} { + # Remote and local are at the same commit + set ref_to_checkout $head_to_checkout + } else { + # Check out the detached head of the remote branch + set head_to_checkout "" + set ref_to_checkout $id_to_checkout + } + lappend command $ref_to_checkout + } else { + # Create local branch and checkout + set ref_to_checkout $head_to_checkout + puts $ref_to_checkout + lappend command -b $ref_to_checkout --track $remote_head } - lappend command -b $head_to_checkout --track $remote } else { lappend command $ref_to_checkout } -- gitgitgadget