1 # git-gui branch checkout support
 
   2 # Copyright (C) 2007 Shawn Pearce
 
   4 class branch_checkout {
 
   6 field w              ; # widget path
 
   7 field w_rev          ; # mega-widget to pick the initial revision
 
   9 field opt_fetch     1; # refetch tracking branch if used?
 
  10 field opt_detach    0; # force a detached head case?
 
  12 constructor dialog {} {
 
  16         wm title $top [mc "%s (%s): Checkout Branch" [appname] [reponame]]
 
  18                 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
 
  21         ${NS}::label $w.header -text [mc "Checkout Branch"] \
 
  22                 -font font_uibold -anchor center
 
  23         pack $w.header -side top -fill x
 
  25         ${NS}::frame $w.buttons
 
  26         ${NS}::button $w.buttons.create -text [mc Checkout] \
 
  28                 -command [cb _checkout]
 
  29         pack $w.buttons.create -side right
 
  30         ${NS}::button $w.buttons.cancel -text [mc Cancel] \
 
  31                 -command [list destroy $w]
 
  32         pack $w.buttons.cancel -side right -padx 5
 
  33         pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
  35         set w_rev [::choose_rev::new $w.rev [mc Revision]]
 
  36         $w_rev bind_listbox <Double-Button-1> [cb _checkout]
 
  37         pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
 
  39         ${NS}::labelframe $w.options -text [mc Options]
 
  41         ${NS}::checkbutton $w.options.fetch \
 
  42                 -text [mc "Fetch Tracking Branch"] \
 
  44         pack $w.options.fetch -anchor nw
 
  46         ${NS}::checkbutton $w.options.detach \
 
  47                 -text [mc "Detach From Local Branch"] \
 
  49         pack $w.options.detach -anchor nw
 
  51         pack $w.options -anchor nw -fill x -pady 5 -padx 5
 
  53         bind $w <Visibility> [cb _visible]
 
  54         bind $w <Key-Escape> [list destroy $w]
 
  55         bind $w <Key-Return> [cb _checkout]\;break
 
  61         set spec [$w_rev get_tracking_branch]
 
  62         if {$spec ne {} && $opt_fetch} {
 
  64         } elseif {[catch {set new [$w_rev commit_or_die]}]} {
 
  71                 set ref [$w_rev get_local_branch]
 
  74         set co [::checkout_op::new [$w_rev get] $new $ref]
 
  77         if {$spec ne {} && $opt_fetch} {
 
  78                 $co enable_fetch $spec