2007-07-09 00:40:56 +02:00
|
|
|
# git-gui branch checkout support
|
|
|
|
# Copyright (C) 2007 Shawn Pearce
|
|
|
|
|
|
|
|
class branch_checkout {
|
|
|
|
|
|
|
|
field w ; # widget path
|
|
|
|
field w_rev ; # mega-widget to pick the initial revision
|
|
|
|
|
|
|
|
field opt_fetch 1; # refetch tracking branch if used?
|
|
|
|
field opt_detach 0; # force a detached head case?
|
|
|
|
|
|
|
|
constructor dialog {} {
|
2010-01-26 01:05:31 +01:00
|
|
|
global use_ttk NS
|
|
|
|
make_dialog top w
|
|
|
|
wm withdraw $w
|
2007-07-21 14:21:34 +02:00
|
|
|
wm title $top [append "[appname] ([reponame]): " [mc "Checkout Branch"]]
|
2007-07-09 00:40:56 +02:00
|
|
|
if {$top ne {.}} {
|
|
|
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
|
|
|
}
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::label $w.header -text [mc "Checkout Branch"] \
|
|
|
|
-font font_uibold -anchor center
|
2007-07-09 00:40:56 +02:00
|
|
|
pack $w.header -side top -fill x
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w.buttons
|
|
|
|
${NS}::button $w.buttons.create -text [mc Checkout] \
|
2007-07-09 00:40:56 +02:00
|
|
|
-default active \
|
|
|
|
-command [cb _checkout]
|
|
|
|
pack $w.buttons.create -side right
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::button $w.buttons.cancel -text [mc Cancel] \
|
2007-07-09 00:40:56 +02:00
|
|
|
-command [list destroy $w]
|
|
|
|
pack $w.buttons.cancel -side right -padx 5
|
|
|
|
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
|
|
|
|
|
2007-07-21 14:21:34 +02:00
|
|
|
set w_rev [::choose_rev::new $w.rev [mc Revision]]
|
2007-07-09 03:34:28 +02:00
|
|
|
$w_rev bind_listbox <Double-Button-1> [cb _checkout]
|
2007-07-09 00:40:56 +02:00
|
|
|
pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::labelframe $w.options -text [mc Options]
|
2007-07-09 00:40:56 +02:00
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::checkbutton $w.options.fetch \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc "Fetch Tracking Branch"] \
|
2007-07-09 00:40:56 +02:00
|
|
|
-variable @opt_fetch
|
|
|
|
pack $w.options.fetch -anchor nw
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::checkbutton $w.options.detach \
|
2007-07-21 14:21:34 +02:00
|
|
|
-text [mc "Detach From Local Branch"] \
|
2007-07-09 00:40:56 +02:00
|
|
|
-variable @opt_detach
|
|
|
|
pack $w.options.detach -anchor nw
|
|
|
|
|
|
|
|
pack $w.options -anchor nw -fill x -pady 5 -padx 5
|
|
|
|
|
|
|
|
bind $w <Visibility> [cb _visible]
|
|
|
|
bind $w <Key-Escape> [list destroy $w]
|
|
|
|
bind $w <Key-Return> [cb _checkout]\;break
|
2010-01-26 01:05:31 +01:00
|
|
|
wm deiconify $w
|
2007-07-09 00:40:56 +02:00
|
|
|
tkwait window $w
|
|
|
|
}
|
|
|
|
|
|
|
|
method _checkout {} {
|
|
|
|
set spec [$w_rev get_tracking_branch]
|
|
|
|
if {$spec ne {} && $opt_fetch} {
|
|
|
|
set new {}
|
|
|
|
} elseif {[catch {set new [$w_rev commit_or_die]}]} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$opt_detach} {
|
|
|
|
set ref {}
|
|
|
|
} else {
|
|
|
|
set ref [$w_rev get_local_branch]
|
|
|
|
}
|
|
|
|
|
|
|
|
set co [::checkout_op::new [$w_rev get] $new $ref]
|
|
|
|
$co parent $w
|
|
|
|
$co enable_checkout 1
|
|
|
|
if {$spec ne {} && $opt_fetch} {
|
|
|
|
$co enable_fetch $spec
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[$co run]} {
|
|
|
|
destroy $w
|
|
|
|
} else {
|
|
|
|
$w_rev focus_filter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
method _visible {} {
|
|
|
|
grab $w
|
|
|
|
$w_rev focus_filter
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|