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_checkout 1; # automatically checkout the new branch?
15 constructor dialog {} {
19 wm title $top "[appname] ([reponame]): Create Branch"
21 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
24 label $w.header -text {Create New Branch} -font font_uibold
25 pack $w.header -side top -fill x
28 button $w.buttons.create -text Create \
31 pack $w.buttons.create -side right
32 button $w.buttons.cancel -text {Cancel} \
33 -command [list destroy $w]
34 pack $w.buttons.cancel -side right -padx 5
35 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
37 labelframe $w.desc -text {Branch Name}
38 radiobutton $w.desc.name_r \
43 set w_name $w.desc.name_t
50 -validatecommand [cb _validate %d %S]
51 grid $w.desc.name_r $w_name -sticky we -padx {0 5}
53 radiobutton $w.desc.match_r \
55 -text {Match Tracking Branch Name} \
58 grid $w.desc.match_r -sticky we -padx {0 5} -columnspan 2
60 grid columnconfigure $w.desc 1 -weight 1
61 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
63 set w_rev [::choose_rev::new $w.rev {Starting Revision}]
64 pack $w.rev -anchor nw -fill x -pady 5 -padx 5
66 labelframe $w.postActions -text {Post Creation Actions}
67 checkbutton $w.postActions.checkout \
68 -text {Checkout after creation} \
69 -variable @opt_checkout
70 pack $w.postActions.checkout -anchor nw
71 pack $w.postActions -anchor nw -fill x -pady 5 -padx 5
73 set name $repo_config(gui.newbranchtemplate)
75 bind $w <Visibility> "
80 bind $w <Key-Escape> [list destroy $w]
81 bind $w <Key-Return> [cb _create]\;break
86 global null_sha1 repo_config
89 switch -- $name_type {
94 set spec [$w_rev get_tracking_branch]
99 -title [wm title $w] \
101 -message "Please select a tracking branch."
104 if {![regsub ^refs/heads/ [lindex $spec 2] {} newbranch]} {
108 -title [wm title $w] \
110 -message "Tracking branch [$w get] is not a branch in the remote repository."
117 || $newbranch eq $repo_config(gui.newbranchtemplate)} {
121 -title [wm title $w] \
123 -message "Please supply a branch name."
127 if {![catch {git show-ref --verify -- "refs/heads/$newbranch"}]} {
131 -title [wm title $w] \
133 -message "Branch '$newbranch' already exists."
137 if {[catch {git check-ref-format "heads/$newbranch"}]} {
141 -title [wm title $w] \
143 -message "We do not like '$newbranch' as a branch name."
148 if {[catch {set cmt [$w_rev get_commit]}]} {
152 -title [wm title $w] \
154 -message "Invalid starting revision: [$w_rev get]"
159 -m "branch: Created from [$w_rev get]" \
160 "refs/heads/$newbranch" \
167 -title [wm title $w] \
169 -message "Failed to create '$newbranch'.\n\n$err"
173 lappend all_heads $newbranch
174 set all_heads [lsort $all_heads]
178 switch_branch $newbranch
182 method _validate {d S} {
184 if {[regexp {[~^:?*\[\0- ]} $S]} {
187 if {[string length $S] > 0} {