You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
5.3 KiB
225 lines
5.3 KiB
18 years ago
|
# git-gui branch create support
|
||
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
||
|
|
||
|
class branch_create {
|
||
|
|
||
|
field w ; # widget path
|
||
|
field w_rev ; # mega-widget to pick the initial revision
|
||
|
field w_name ; # new branch name widget
|
||
|
|
||
|
field name {}; # name of the branch the user has chosen
|
||
18 years ago
|
field name_type user; # type of branch name to use
|
||
|
|
||
18 years ago
|
field opt_merge ff; # type of merge to apply to existing branch
|
||
18 years ago
|
field opt_checkout 1; # automatically checkout the new branch?
|
||
18 years ago
|
field opt_fetch 1; # refetch tracking branch if used?
|
||
18 years ago
|
field reset_ok 0; # did the user agree to reset?
|
||
18 years ago
|
|
||
|
constructor dialog {} {
|
||
15 years ago
|
global repo_config use_ttk NS
|
||
18 years ago
|
|
||
15 years ago
|
make_dialog top w
|
||
|
wm withdraw $w
|
||
9 years ago
|
wm title $top [mc "%s (%s): Create Branch" [appname] [reponame]]
|
||
18 years ago
|
if {$top ne {.}} {
|
||
|
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
|
||
|
}
|
||
|
|
||
15 years ago
|
${NS}::label $w.header -text [mc "Create New Branch"] \
|
||
|
-font font_uibold -anchor center
|
||
18 years ago
|
pack $w.header -side top -fill x
|
||
|
|
||
15 years ago
|
${NS}::frame $w.buttons
|
||
|
${NS}::button $w.buttons.create -text [mc Create] \
|
||
18 years ago
|
-default active \
|
||
|
-command [cb _create]
|
||
|
pack $w.buttons.create -side right
|
||
15 years ago
|
${NS}::button $w.buttons.cancel -text [mc Cancel] \
|
||
18 years ago
|
-command [list destroy $w]
|
||
|
pack $w.buttons.cancel -side right -padx 5
|
||
|
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
|
||
|
|
||
15 years ago
|
${NS}::labelframe $w.desc -text [mc "Branch Name"]
|
||
|
${NS}::radiobutton $w.desc.name_r \
|
||
18 years ago
|
-text [mc "Name:"] \
|
||
18 years ago
|
-value user \
|
||
|
-variable @name_type
|
||
15 years ago
|
if {!$use_ttk} {$w.desc.name_r configure -anchor w}
|
||
18 years ago
|
set w_name $w.desc.name_t
|
||
15 years ago
|
${NS}::entry $w_name \
|
||
18 years ago
|
-width 40 \
|
||
|
-textvariable @name \
|
||
|
-validate key \
|
||
|
-validatecommand [cb _validate %d %S]
|
||
|
grid $w.desc.name_r $w_name -sticky we -padx {0 5}
|
||
|
|
||
15 years ago
|
${NS}::radiobutton $w.desc.match_r \
|
||
18 years ago
|
-text [mc "Match Tracking Branch Name"] \
|
||
18 years ago
|
-value match \
|
||
|
-variable @name_type
|
||
15 years ago
|
if {!$use_ttk} {$w.desc.match_r configure -anchor w}
|
||
18 years ago
|
grid $w.desc.match_r -sticky we -padx {0 5} -columnspan 2
|
||
|
|
||
18 years ago
|
grid columnconfigure $w.desc 1 -weight 1
|
||
|
pack $w.desc -anchor nw -fill x -pady 5 -padx 5
|
||
|
|
||
18 years ago
|
set w_rev [::choose_rev::new $w.rev [mc "Starting Revision"]]
|
||
18 years ago
|
pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
|
||
18 years ago
|
|
||
15 years ago
|
${NS}::labelframe $w.options -text [mc Options]
|
||
18 years ago
|
|
||
15 years ago
|
${NS}::frame $w.options.merge
|
||
|
${NS}::label $w.options.merge.l -text [mc "Update Existing Branch:"]
|
||
18 years ago
|
pack $w.options.merge.l -side left
|
||
15 years ago
|
${NS}::radiobutton $w.options.merge.no \
|
||
18 years ago
|
-text [mc No] \
|
||
18 years ago
|
-value none \
|
||
18 years ago
|
-variable @opt_merge
|
||
|
pack $w.options.merge.no -side left
|
||
15 years ago
|
${NS}::radiobutton $w.options.merge.ff \
|
||
18 years ago
|
-text [mc "Fast Forward Only"] \
|
||
18 years ago
|
-value ff \
|
||
|
-variable @opt_merge
|
||
|
pack $w.options.merge.ff -side left
|
||
15 years ago
|
${NS}::radiobutton $w.options.merge.reset \
|
||
18 years ago
|
-text [mc Reset] \
|
||
18 years ago
|
-value reset \
|
||
|
-variable @opt_merge
|
||
|
pack $w.options.merge.reset -side left
|
||
|
pack $w.options.merge -anchor nw
|
||
|
|
||
15 years ago
|
${NS}::checkbutton $w.options.fetch \
|
||
18 years ago
|
-text [mc "Fetch Tracking Branch"] \
|
||
18 years ago
|
-variable @opt_fetch
|
||
|
pack $w.options.fetch -anchor nw
|
||
|
|
||
15 years ago
|
${NS}::checkbutton $w.options.checkout \
|
||
18 years ago
|
-text [mc "Checkout After Creation"] \
|
||
18 years ago
|
-variable @opt_checkout
|
||
18 years ago
|
pack $w.options.checkout -anchor nw
|
||
|
pack $w.options -anchor nw -fill x -pady 5 -padx 5
|
||
18 years ago
|
|
||
18 years ago
|
trace add variable @name_type write [cb _select]
|
||
|
|
||
18 years ago
|
set name $repo_config(gui.newbranchtemplate)
|
||
18 years ago
|
if {[is_config_true gui.matchtrackingbranch]} {
|
||
|
set name_type match
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
bind $w <Visibility> [cb _visible]
|
||
18 years ago
|
bind $w <Key-Escape> [list destroy $w]
|
||
|
bind $w <Key-Return> [cb _create]\;break
|
||
15 years ago
|
wm deiconify $w
|
||
18 years ago
|
tkwait window $w
|
||
|
}
|
||
|
|
||
|
method _create {} {
|
||
18 years ago
|
global repo_config
|
||
18 years ago
|
global M1B
|
||
18 years ago
|
|
||
18 years ago
|
set spec [$w_rev get_tracking_branch]
|
||
18 years ago
|
switch -- $name_type {
|
||
|
user {
|
||
|
set newbranch $name
|
||
|
}
|
||
|
match {
|
||
|
if {$spec eq {}} {
|
||
|
tk_messageBox \
|
||
|
-icon error \
|
||
|
-type ok \
|
||
|
-title [wm title $w] \
|
||
|
-parent $w \
|
||
18 years ago
|
-message [mc "Please select a tracking branch."]
|
||
18 years ago
|
return
|
||
|
}
|
||
|
if {![regsub ^refs/heads/ [lindex $spec 2] {} newbranch]} {
|
||
|
tk_messageBox \
|
||
|
-icon error \
|
||
|
-type ok \
|
||
|
-title [wm title $w] \
|
||
|
-parent $w \
|
||
18 years ago
|
-message [mc "Tracking branch %s is not a branch in the remote repository." [$w get]]
|
||
18 years ago
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
if {$newbranch eq {}
|
||
|
|| $newbranch eq $repo_config(gui.newbranchtemplate)} {
|
||
|
tk_messageBox \
|
||
|
-icon error \
|
||
|
-type ok \
|
||
|
-title [wm title $w] \
|
||
|
-parent $w \
|
||
18 years ago
|
-message [mc "Please supply a branch name."]
|
||
18 years ago
|
focus $w_name
|
||
|
return
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
if {[catch {git check-ref-format "heads/$newbranch"}]} {
|
||
|
tk_messageBox \
|
||
|
-icon error \
|
||
|
-type ok \
|
||
|
-title [wm title $w] \
|
||
|
-parent $w \
|
||
18 years ago
|
-message [mc "'%s' is not an acceptable branch name." $newbranch]
|
||
18 years ago
|
focus $w_name
|
||
|
return
|
||
|
}
|
||
|
|
||
18 years ago
|
if {$spec ne {} && $opt_fetch} {
|
||
18 years ago
|
set new {}
|
||
|
} elseif {[catch {set new [$w_rev commit_or_die]}]} {
|
||
18 years ago
|
return
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
set co [::checkout_op::new \
|
||
|
[$w_rev get] \
|
||
|
$new \
|
||
|
refs/heads/$newbranch]
|
||
|
$co parent $w
|
||
|
$co enable_create 1
|
||
|
$co enable_merge $opt_merge
|
||
|
$co enable_checkout $opt_checkout
|
||
|
if {$spec ne {} && $opt_fetch} {
|
||
|
$co enable_fetch $spec
|
||
18 years ago
|
}
|
||
17 years ago
|
if {$spec ne {}} {
|
||
|
$co remote_source $spec
|
||
|
}
|
||
18 years ago
|
|
||
18 years ago
|
if {[$co run]} {
|
||
|
destroy $w
|
||
|
} else {
|
||
|
focus $w_name
|
||
18 years ago
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
method _validate {d S} {
|
||
|
if {$d == 1} {
|
||
|
if {[regexp {[~^:?*\[\0- ]} $S]} {
|
||
|
return 0
|
||
|
}
|
||
|
if {[string length $S] > 0} {
|
||
|
set name_type user
|
||
|
}
|
||
|
}
|
||
|
return 1
|
||
|
}
|
||
|
|
||
18 years ago
|
method _select {args} {
|
||
|
if {$name_type eq {match}} {
|
||
|
$w_rev pick_tracking_branch
|
||
|
}
|
||
|
}
|
||
|
|
||
|
method _visible {} {
|
||
|
grab $w
|
||
|
if {$name_type eq {user}} {
|
||
|
$w_name icursor end
|
||
|
focus $w_name
|
||
|
}
|
||
|
}
|
||
|
|
||
18 years ago
|
}
|