git-gui: Automatically refresh tracking branches when needed
If the user is creating a new local branch and has selected to use a tracking branch as the starting revision they probably want to make sure they are using the absolute latest version available of that branch. We now offer a checkbox "Fetch Tracking Branch" (on by default) that instructs git-gui to run git-fetch on just that one branch before resolving the branch name into a commit SHA-1 and making (or updating) the local branch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 5, 2007 at 02:23 UTC
ba1964be26b8b9e3441591257a2c87f5811d6b50
2 files changed
+88
-14
lib/branch_create.tcl
+55
-3
@@ -12,6 +12,7 @@ field name_type user; # type of branch name to use
12
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?
17
18
constructor dialog {} {
@@ -87,6 +88,11 @@ constructor dialog {} {
88
pack $w.options.merge.reset -side left
89
pack $w.options.merge -anchor nw
90
91
+ checkbutton $w.options.fetch \
92
+ -text {Fetch Tracking Branch} \
93
+ -variable @opt_fetch
94
+ pack $w.options.fetch -anchor nw
95
+
96
checkbutton $w.options.checkout \
97
-text {Checkout After Creation} \
98
-variable @opt_checkout
@@ -107,15 +113,15 @@ constructor dialog {} {
113
}
114
115
method _create {} {
110
- global null_sha1 repo_config
111
- global all_heads current_branch
116
+ global repo_config current_branch
117
+ global M1B
118
119
+ set spec [$w_rev get_tracking_branch]
120
switch -- $name_type {
121
user {
122
set newbranch $name
123
}
124
match {
118
- set spec [$w_rev get_tracking_branch]
125
if {$spec eq {}} {
126
tk_messageBox \
127
-icon error \
@@ -171,6 +177,52 @@ method _create {} {
177
return
178
}
179
180
+ if {$spec ne {} && $opt_fetch} {
181
+ set l_trck [lindex $spec 0]
182
+ set remote [lindex $spec 1]
183
+ set r_head [lindex $spec 2]
184
+ regsub ^refs/heads/ $r_head {} r_head
185
+
186
+ set c $w.fetch_trck
187
+ toplevel $c
188
+ wm title $c "Refreshing Tracking Branch"
189
+ wm geometry $c "+[winfo rootx $w]+[winfo rooty $w]"
190
+
191
+ set e [::console::embed \
192
+ $c.console \
193
+ "Fetching $r_head from $remote"]
194
+ pack $c.console -fill both -expand 1
195
+ $e exec \
196
+ [list git fetch $remote +$r_head:$l_trck] \
197
+ [cb _finish_fetch $newbranch $c $e]
198
+
199
+ bind $c <Visibility> [list grab $c]
200
+ bind $c <$M1B-Key-w> break
201
+ bind $c <$M1B-Key-W> break
202
+ wm protocol $c WM_DELETE_WINDOW [cb _noop]
203
+ } else {
204
+ _finish_create $this $newbranch
205
+ }
206
+}
207
+
208
+method _noop {} {}
209
+
210
+method _finish_fetch {newbranch c e ok} {
211
+ wm protocol $c WM_DELETE_WINDOW {}
212
+
213
+ if {$ok} {
214
+ destroy $c
215
+ _finish_create $this $newbranch
216
+ } else {
217
+ $e done $ok
218
+ button $c.close -text Close -command [list destroy $c]
219
+ pack $c.close -side bottom -anchor e -padx 10 -pady 10
220
+ }
221
+}
222
+
223
+method _finish_create {newbranch} {
224
+ global null_sha1 all_heads
225
+
226
if {[catch {set new [$w_rev commit_or_die]}]} {
227
return
228
}
lib/console.tcl
+33
-11
@@ -7,6 +7,7 @@ field t_short
7
field t_long
8
field w
9
field console_cr
10
+field is_toplevel 1; # are we our own window?
11
12
constructor new {short_title long_title} {
13
set t_short $short_title
@@ -15,10 +16,25 @@ constructor new {short_title long_title} {
16
return $this
17
}
18
19
+constructor embed {path title} {
20
+ set t_short {}
21
+ set t_long $title
22
+ set w $path
23
+ set is_toplevel 0
24
+ _init $this
25
+ return $this
26
+}
27
+
28
method _init {} {
29
global M1B
20
- make_toplevel top w -autodelete 0
21
- wm title $top "[appname] ([reponame]): $t_short"
30
+
31
+ if {$is_toplevel} {
32
+ make_toplevel top w -autodelete 0
33
+ wm title $top "[appname] ([reponame]): $t_short"
34
+ } else {
35
+ frame $w
36
+ }
37
+
38
set console_cr 1.0
39
40
frame $w.m
@@ -57,15 +73,17 @@ method _init {} {
73
$w.m.t tag remove sel 0.0 end
74
"
75
60
- button $w.ok -text {Close} \
61
- -state disabled \
62
- -command "destroy $w"
63
- pack $w.ok -side bottom -anchor e -pady 10 -padx 10
76
+ if {$is_toplevel} {
77
+ button $w.ok -text {Close} \
78
+ -state disabled \
79
+ -command [list destroy $w]
80
+ pack $w.ok -side bottom -anchor e -pady 10 -padx 10
81
+ bind $w <Visibility> [list focus $w]
82
+ }
83
84
bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
85
bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
86
bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
68
- bind $w <Visibility> "focus $w"
87
}
88
89
method exec {cmd {after {}}} {
@@ -159,16 +177,20 @@ method done {ok} {
177
if {$ok} {
178
if {[winfo exists $w.m.s]} {
179
$w.m.s conf -background green -text {Success}
162
- $w.ok conf -state normal
163
- focus $w.ok
180
+ if {$is_toplevel} {
181
+ $w.ok conf -state normal
182
+ focus $w.ok
183
+ }
184
}
185
} else {
186
if {![winfo exists $w.m.s]} {
187
_init $this
188
}
189
$w.m.s conf -background red -text {Error: Command Failed}
170
- $w.ok conf -state normal
171
- focus $w.ok
190
+ if {$is_toplevel} {
191
+ $w.ok conf -state normal
192
+ focus $w.ok
193
+ }
194
}
195
delete_this
196
}