Code

tests: unset COLUMNS inherited from environment
[git.git] / git-gui / lib / branch_checkout.tcl
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 {} {
13         global use_ttk NS
14         make_dialog top w
15         wm withdraw $w
16         wm title $top [append "[appname] ([reponame]): " [mc "Checkout Branch"]]
17         if {$top ne {.}} {
18                 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
19         }
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] \
27                 -default active \
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"] \
43                 -variable @opt_fetch
44         pack $w.options.fetch -anchor nw
46         ${NS}::checkbutton $w.options.detach \
47                 -text [mc "Detach From Local Branch"] \
48                 -variable @opt_detach
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
56         wm deiconify $w
57         tkwait window $w
58 }
60 method _checkout {} {
61         set spec [$w_rev get_tracking_branch]
62         if {$spec ne {} && $opt_fetch} {
63                 set new {}
64         } elseif {[catch {set new [$w_rev commit_or_die]}]} {
65                 return
66         }
68         if {$opt_detach} {
69                 set ref {}
70         } else {
71                 set ref [$w_rev get_local_branch]
72         }
74         set co [::checkout_op::new [$w_rev get] $new $ref]
75         $co parent $w
76         $co enable_checkout 1
77         if {$spec ne {} && $opt_fetch} {
78                 $co enable_fetch $spec
79         }
81         if {[$co run]} {
82                 destroy $w
83         } else {
84                 $w_rev focus_filter
85         }
86 }
88 method _visible {} {
89         grab $w
90         $w_rev focus_filter
91 }
93 }