]> git.ipfire.org Git - thirdparty/git.git/blame - git-gui/lib/branch_checkout.tcl
Merge branch 'ds/commit-graph'
[thirdparty/git.git] / git-gui / lib / branch_checkout.tcl
CommitLineData
d41b43eb
SP
1# git-gui branch checkout support
2# Copyright (C) 2007 Shawn Pearce
3
4class branch_checkout {
5
6field w ; # widget path
7field w_rev ; # mega-widget to pick the initial revision
8
9field opt_fetch 1; # refetch tracking branch if used?
10field opt_detach 0; # force a detached head case?
11
12constructor dialog {} {
c80d7be5
PT
13 global use_ttk NS
14 make_dialog top w
15 wm withdraw $w
a3d97afa 16 wm title $top [mc "%s (%s): Checkout Branch" [appname] [reponame]]
d41b43eb
SP
17 if {$top ne {.}} {
18 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
19 }
20
c80d7be5
PT
21 ${NS}::label $w.header -text [mc "Checkout Branch"] \
22 -font font_uibold -anchor center
d41b43eb
SP
23 pack $w.header -side top -fill x
24
c80d7be5
PT
25 ${NS}::frame $w.buttons
26 ${NS}::button $w.buttons.create -text [mc Checkout] \
d41b43eb
SP
27 -default active \
28 -command [cb _checkout]
29 pack $w.buttons.create -side right
c80d7be5 30 ${NS}::button $w.buttons.cancel -text [mc Cancel] \
d41b43eb
SP
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
34
1ac17950 35 set w_rev [::choose_rev::new $w.rev [mc Revision]]
827c7119 36 $w_rev bind_listbox <Double-Button-1> [cb _checkout]
d41b43eb
SP
37 pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
38
c80d7be5 39 ${NS}::labelframe $w.options -text [mc Options]
d41b43eb 40
c80d7be5 41 ${NS}::checkbutton $w.options.fetch \
1ac17950 42 -text [mc "Fetch Tracking Branch"] \
d41b43eb
SP
43 -variable @opt_fetch
44 pack $w.options.fetch -anchor nw
45
c80d7be5 46 ${NS}::checkbutton $w.options.detach \
1ac17950 47 -text [mc "Detach From Local Branch"] \
d41b43eb
SP
48 -variable @opt_detach
49 pack $w.options.detach -anchor nw
50
51 pack $w.options -anchor nw -fill x -pady 5 -padx 5
52
53 bind $w <Visibility> [cb _visible]
54 bind $w <Key-Escape> [list destroy $w]
55 bind $w <Key-Return> [cb _checkout]\;break
c80d7be5 56 wm deiconify $w
d41b43eb
SP
57 tkwait window $w
58}
59
60method _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 }
67
68 if {$opt_detach} {
69 set ref {}
70 } else {
71 set ref [$w_rev get_local_branch]
72 }
73
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 }
80
81 if {[$co run]} {
82 destroy $w
83 } else {
84 $w_rev focus_filter
85 }
86}
87
88method _visible {} {
89 grab $w
90 $w_rev focus_filter
91}
92
93}