git-gui: Allow users to match remote branch names locally
Some workflows have users create a local branch that matches a remote branch they have fetched from another repository. If the user wants to push their changes back to that remote repository then they probably want to use the same branch name locally so that git-gui's push dialog can setup the push refspec automatically. To prevent typos with the local branch name we now offer an option to use the remote tracking branch name as the new local branch name. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 4, 2007 at 02:19 UTC
dd87efc8cc71ceb6aa9a27e900976c317c927846
2 files changed
+49
-4
lib/branch_create.tcl
+41
-4
@@ -8,6 +8,8 @@ field w_rev ; # mega-widget to pick the initial revision
8
field w_name ; # new branch name widget
9
10
field name {}; # name of the branch the user has chosen
11
+field name_type user; # type of branch name to use
12
+
13
field opt_checkout 1; # automatically checkout the new branch?
14
15
constructor dialog {} {
@@ -32,10 +34,12 @@ constructor dialog {} {
34
pack $w.buttons.cancel -side right -padx 5
35
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
36
35
- labelframe $w.desc -text {Branch Description}
36
- label $w.desc.name_r \
37
+ labelframe $w.desc -text {Branch Name}
38
+ radiobutton $w.desc.name_r \
39
-anchor w \
38
- -text {Name:}
40
+ -text {Name:} \
41
+ -value user \
42
+ -variable @name_type
43
set w_name $w.desc.name_t
44
entry $w_name \
45
-borderwidth 1 \
@@ -46,6 +50,13 @@ constructor dialog {} {
50
-validatecommand [cb _validate %d %S]
51
grid $w.desc.name_r $w_name -sticky we -padx {0 5}
52
53
+ radiobutton $w.desc.match_r \
54
+ -anchor w \
55
+ -text {Match Tracking Branch Name} \
56
+ -value match \
57
+ -variable @name_type
58
+ grid $w.desc.match_r -sticky we -padx {0 5} -columnspan 2
59
+
60
grid columnconfigure $w.desc 1 -weight 1
61
pack $w.desc -anchor nw -fill x -pady 5 -padx 5
62
@@ -75,7 +86,33 @@ method _create {} {
86
global null_sha1 repo_config
87
global all_heads
88
78
- set newbranch $name
89
+ switch -- $name_type {
90
+ user {
91
+ set newbranch $name
92
+ }
93
+ match {
94
+ set spec [$w_rev get_tracking_branch]
95
+ if {$spec eq {}} {
96
+ tk_messageBox \
97
+ -icon error \
98
+ -type ok \
99
+ -title [wm title $w] \
100
+ -parent $w \
101
+ -message "Please select a tracking branch."
102
+ return
103
+ }
104
+ if {![regsub ^refs/heads/ [lindex $spec 2] {} newbranch]} {
105
+ tk_messageBox \
106
+ -icon error \
107
+ -type ok \
108
+ -title [wm title $w] \
109
+ -parent $w \
110
+ -message "Tracking branch [$w get] is not a branch in the remote repository."
111
+ return
112
+ }
113
+ }
114
+ }
115
+
116
if {$newbranch eq {}
117
|| $newbranch eq $repo_config(gui.newbranchtemplate)} {
118
tk_messageBox \
lib/choose_rev.tcl
+8
@@ -128,6 +128,14 @@ method get {} {
128
}
129
}
130
131
+method get_tracking_branch {} {
132
+ if {$revtype eq {trck}} {
133
+ return $trck_spec($c_trck)
134
+ } else {
135
+ return {}
136
+ }
137
+}
138
+
139
method get_expr {} {
140
switch -- $revtype {
141
head { return refs/heads/$c_head }