diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-07-05 02:23:53 -0400 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-07-08 21:12:55 -0400 |
commit | ba1964be26b8b9e3441591257a2c87f5811d6b50 (patch) | |
tree | 75beedcb2e8fe66ff9bd7cf688a2b2417cabc99e /lib/branch_create.tcl | |
parent | 7cf044266779d69d3a16322b4d505bc87267a005 (diff) | |
download | git-ba1964be26b8b9e3441591257a2c87f5811d6b50.tar.gz git-ba1964be26b8b9e3441591257a2c87f5811d6b50.tar.xz |
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>
Diffstat (limited to 'lib/branch_create.tcl')
-rw-r--r-- | lib/branch_create.tcl | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/lib/branch_create.tcl b/lib/branch_create.tcl index df3f435e1..f708957b2 100644 --- a/lib/branch_create.tcl +++ b/lib/branch_create.tcl @@ -12,6 +12,7 @@ field name_type user; # type of branch name to use field opt_merge ff; # type of merge to apply to existing branch field opt_checkout 1; # automatically checkout the new branch? +field opt_fetch 1; # refetch tracking branch if used? field reset_ok 0; # did the user agree to reset? constructor dialog {} { @@ -87,6 +88,11 @@ constructor dialog {} { pack $w.options.merge.reset -side left pack $w.options.merge -anchor nw + checkbutton $w.options.fetch \ + -text {Fetch Tracking Branch} \ + -variable @opt_fetch + pack $w.options.fetch -anchor nw + checkbutton $w.options.checkout \ -text {Checkout After Creation} \ -variable @opt_checkout @@ -107,15 +113,15 @@ constructor dialog {} { } method _create {} { - global null_sha1 repo_config - global all_heads current_branch + global repo_config current_branch + global M1B + set spec [$w_rev get_tracking_branch] switch -- $name_type { user { set newbranch $name } match { - set spec [$w_rev get_tracking_branch] if {$spec eq {}} { tk_messageBox \ -icon error \ @@ -171,6 +177,52 @@ method _create {} { return } + if {$spec ne {} && $opt_fetch} { + set l_trck [lindex $spec 0] + set remote [lindex $spec 1] + set r_head [lindex $spec 2] + regsub ^refs/heads/ $r_head {} r_head + + set c $w.fetch_trck + toplevel $c + wm title $c "Refreshing Tracking Branch" + wm geometry $c "+[winfo rootx $w]+[winfo rooty $w]" + + set e [::console::embed \ + $c.console \ + "Fetching $r_head from $remote"] + pack $c.console -fill both -expand 1 + $e exec \ + [list git fetch $remote +$r_head:$l_trck] \ + [cb _finish_fetch $newbranch $c $e] + + bind $c <Visibility> [list grab $c] + bind $c <$M1B-Key-w> break + bind $c <$M1B-Key-W> break + wm protocol $c WM_DELETE_WINDOW [cb _noop] + } else { + _finish_create $this $newbranch + } +} + +method _noop {} {} + +method _finish_fetch {newbranch c e ok} { + wm protocol $c WM_DELETE_WINDOW {} + + if {$ok} { + destroy $c + _finish_create $this $newbranch + } else { + $e done $ok + button $c.close -text Close -command [list destroy $c] + pack $c.close -side bottom -anchor e -padx 10 -pady 10 + } +} + +method _finish_create {newbranch} { + global null_sha1 all_heads + if {[catch {set new [$w_rev commit_or_die]}]} { return } |