Code

git-gui: Internally allow fetch without storing for future pull support
authorShawn O. Pearce <spearce@spearce.org>
Fri, 20 Jul 2007 08:10:13 +0000 (04:10 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 21 Jul 2007 09:00:37 +0000 (05:00 -0400)
This is actually just an underlying code improvement that has no user
visible component yet.  UI improvements to actually fetch and merge via
an arbitrary remote with no tracking branches must still follow to make
this change useful for the end-user.

Our tracking branch specifications are a Tcl list of three components:

  - local tracking branch name
  - remote name/url
  - remote branch name/tag name

This change just makes the first element optional.  If it is an empty
string we will run the fetch, but have the value be saved only into the
special .git/FETCH_HEAD, where we can pick it up and use it for this one
time operation.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
lib/checkout_op.tcl

index cb04d1e57e254858e1ceca36158e40aec570034f..05711151287b4a4ae595b8e73fd99575c2972073 100644 (file)
@@ -66,14 +66,19 @@ method run {} {
                set r_head [lindex $fetch_spec 2]
                regsub ^refs/heads/ $r_head {} r_name
 
+               set cmd [list git fetch $remote]
+               if {$l_trck ne {}} {
+                       lappend cmd +$r_head:$l_trck
+               } else {
+                       lappend cmd $r_head
+               }
+
                _toplevel $this {Refreshing Tracking Branch}
                set w_cons [::console::embed \
                        $w.console \
                        "Fetching $r_name from $remote"]
                pack $w.console -fill both -expand 1
-               $w_cons exec \
-                       [list git fetch $remote +$r_head:$l_trck] \
-                       [cb _finish_fetch]
+               $w_cons exec $cmd [cb _finish_fetch]
 
                bind $w <$M1B-Key-w> break
                bind $w <$M1B-Key-W> break
@@ -114,6 +119,9 @@ method _noop {} {}
 method _finish_fetch {ok} {
        if {$ok} {
                set l_trck [lindex $fetch_spec 0]
+               if {$l_trck eq {}} {
+                       set l_trck FETCH_HEAD
+               }
                if {[catch {set new_hash [git rev-parse --verify "$l_trck^0"]} err]} {
                        set ok 0
                        $w_cons insert "fatal: Cannot resolve $l_trck"