git-gui: Option to default new branches to match tracking branches
[gitweb.git] / lib / branch_create.tcl
index 375f575eaf4884d735e21bcb34ab36a75d28f512..df3f435e11a13e6d1e812909bc0277ac6e1add2f 100644 (file)
@@ -93,13 +93,14 @@ constructor dialog {} {
        pack $w.options.checkout -anchor nw
        pack $w.options -anchor nw -fill x -pady 5 -padx 5
 
+       trace add variable @name_type write [cb _select]
+
        set name $repo_config(gui.newbranchtemplate)
+       if {[is_config_true gui.matchtrackingbranch]} {
+               set name_type match
+       }
 
-       bind $w <Visibility> "
-               grab $w
-               $w_name icursor end
-               focus $w_name
-       "
+       bind $w <Visibility> [cb _visible]
        bind $w <Key-Escape> [list destroy $w]
        bind $w <Key-Return> [cb _create]\;break
        tkwait window $w
@@ -361,4 +362,18 @@ method _validate {d S} {
        return 1
 }
 
+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
+       }
+}
+
 }