1 # git-gui branch create support
2 # Copyright (C) 2006, 2007 Shawn Pearce
6 field w ; # widget path
7 field w_rev ; # mega-widget to pick the initial revision
8 field w_name ; # new branch name widget
10 field name {}; # name of the branch the user has chosen
11 field name_type user; # type of branch name to use
13 field opt_merge ff; # type of merge to apply to existing branch
14 field opt_checkout 1; # automatically checkout the new branch?
15 field opt_fetch 1; # refetch tracking branch if used?
16 field reset_ok 0; # did the user agree to reset?
18 constructor dialog {} {
19 global repo_config use_ttk NS
23 wm title $top [mc "%s (%s): Create Branch" [appname] [reponame]]
25 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
28 ${NS}::label $w.header -text [mc "Create New Branch"] \
29 -font font_uibold -anchor center
30 pack $w.header -side top -fill x
32 ${NS}::frame $w.buttons
33 ${NS}::button $w.buttons.create -text [mc Create] \
36 pack $w.buttons.create -side right
37 ${NS}::button $w.buttons.cancel -text [mc Cancel] \
38 -command [list destroy $w]
39 pack $w.buttons.cancel -side right -padx 5
40 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
42 ${NS}::labelframe $w.desc -text [mc "Branch Name"]
43 ${NS}::radiobutton $w.desc.name_r \
47 if {!$use_ttk} {$w.desc.name_r configure -anchor w}
48 set w_name $w.desc.name_t
49 ${NS}::entry $w_name \
53 -validatecommand [cb _validate %d %S]
54 grid $w.desc.name_r $w_name -sticky we -padx {0 5}
56 ${NS}::radiobutton $w.desc.match_r \
57 -text [mc "Match Tracking Branch Name"] \
60 if {!$use_ttk} {$w.desc.match_r configure -anchor w}
61 grid $w.desc.match_r -sticky we -padx {0 5} -columnspan 2
63 grid columnconfigure $w.desc 1 -weight 1
64 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
66 set w_rev [::choose_rev::new $w.rev [mc "Starting Revision"]]
67 pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
69 ${NS}::labelframe $w.options -text [mc Options]
71 ${NS}::frame $w.options.merge
72 ${NS}::label $w.options.merge.l -text [mc "Update Existing Branch:"]
73 pack $w.options.merge.l -side left
74 ${NS}::radiobutton $w.options.merge.no \
78 pack $w.options.merge.no -side left
79 ${NS}::radiobutton $w.options.merge.ff \
80 -text [mc "Fast Forward Only"] \
83 pack $w.options.merge.ff -side left
84 ${NS}::radiobutton $w.options.merge.reset \
88 pack $w.options.merge.reset -side left
89 pack $w.options.merge -anchor nw
91 ${NS}::checkbutton $w.options.fetch \
92 -text [mc "Fetch Tracking Branch"] \
94 pack $w.options.fetch -anchor nw
96 ${NS}::checkbutton $w.options.checkout \
97 -text [mc "Checkout After Creation"] \
98 -variable @opt_checkout
99 pack $w.options.checkout -anchor nw
100 pack $w.options -anchor nw -fill x -pady 5 -padx 5
102 trace add variable @name_type write [cb _select]
104 set name $repo_config(gui.newbranchtemplate)
105 if {[is_config_true gui.matchtrackingbranch]} {
109 bind $w <Visibility> [cb _visible]
110 bind $w <Key-Escape> [list destroy $w]
111 bind $w <Key-Return> [cb _create]\;break
120 set spec [$w_rev get_tracking_branch]
121 switch -- $name_type {
130 -title [wm title $w] \
132 -message [mc "Please select a tracking branch."]
135 if {![regsub ^refs/heads/ [lindex $spec 2] {} newbranch]} {
139 -title [wm title $w] \
141 -message [mc "Tracking branch %s is not a branch in the remote repository." [$w get]]
148 || $newbranch eq $repo_config(gui.newbranchtemplate)} {
152 -title [wm title $w] \
154 -message [mc "Please supply a branch name."]
159 if {[catch {git check-ref-format "heads/$newbranch"}]} {
163 -title [wm title $w] \
165 -message [mc "'%s' is not an acceptable branch name." $newbranch]
170 if {$spec ne {} && $opt_fetch} {
172 } elseif {[catch {set new [$w_rev commit_or_die]}]} {
176 set co [::checkout_op::new \
179 refs/heads/$newbranch]
182 $co enable_merge $opt_merge
183 $co enable_checkout $opt_checkout
184 if {$spec ne {} && $opt_fetch} {
185 $co enable_fetch $spec
188 $co remote_source $spec
198 method _validate {d S} {
200 if {[regexp {[~^:?*\[\0- ]} $S]} {
203 if {[string length $S] > 0} {
210 method _select {args} {
211 if {$name_type eq {match}} {
212 $w_rev pick_tracking_branch
218 if {$name_type eq {user}} {