OSDN Git Service

git-gui: GUI support for running 'git remote prune <name>'
authorShawn O. Pearce <spearce@spearce.org>
Mon, 28 May 2007 15:04:59 +0000 (11:04 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 28 May 2007 21:50:40 +0000 (17:50 -0400)
In some workflows it is common for a large number of temporary
branches to be created in a remote repository, get fetched to
clients that typically only use git-gui, and then later have
those branches deleted from the remote repository once they have
been fully merged into all destination branches.  Users of git-gui
would obviously like to have their local tracking branches cleaned
up for them, otherwise their local tracking branch namespace would
grow out of control.

The best known way to remove these tracking branches is to run
"git remote prune <remotename>".  Even though it is more of a
Porcelain command than plumbing I'm invoking it through the UI,
because frankly I don't see a reason to reimplement its ls-remote
output filtering and config file parsing.

A new configuration option (gui.pruneduringfetch) can be used to
automatically enable running "git remote prune <remotename>" after
the fetch of that remote also completes successfully.  This is off
by default as it require an additional network connection and is
not very fast on Cygwin if a large number of tracking branches have
been removed (due to the 2 fork+exec calls per branch).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh
lib/option.tcl
lib/remote.tcl
lib/transport.tcl

index dba5851..d238d45 100755 (executable)
@@ -1243,6 +1243,7 @@ set default_config(merge.verbosity) 2
 set default_config(user.name) {}
 set default_config(user.email) {}
 
+set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.diffcontext) 5
 set default_config(gui.newbranchtemplate) {}
index 17fcc65..e06aca5 100644 (file)
@@ -173,6 +173,7 @@ proc do_options {} {
                {i-1..5 merge.verbosity {Merge Verbosity}}
 
                {b gui.trustmtime  {Trust File Modification Timestamps}}
+               {b gui.pruneduringfetch {Prune Tracking Branches During Fetch}}
                {i-1..99 gui.diffcontext {Number of Diff Context Lines}}
                {t gui.newbranchtemplate {New Branch Name Template}}
                } {
index 99f353e..b54824a 100644 (file)
@@ -95,6 +95,7 @@ proc populate_fetch_menu {} {
        global all_remotes repo_config
 
        set m .mbar.fetch
+       set prune_list [list]
        foreach r $all_remotes {
                set enable 0
                if {![catch {set a $repo_config(remote.$r.url)}]} {
@@ -115,11 +116,21 @@ proc populate_fetch_menu {} {
                }
 
                if {$enable} {
+                       lappend prune_list $r
                        $m add command \
                                -label "Fetch from $r..." \
                                -command [list fetch_from $r]
                }
        }
+
+       if {$prune_list ne {}} {
+               $m add separator
+       }
+       foreach r $prune_list {
+               $m add command \
+                       -label "Prune from $r..." \
+                       -command [list prune_from $r]
+       }
 }
 
 proc populate_push_menu {} {
index c0e7d20..e8ebc6e 100644 (file)
@@ -5,9 +5,19 @@ proc fetch_from {remote} {
        set w [console::new \
                "fetch $remote" \
                "Fetching new changes from $remote"]
-       set cmd [list git fetch]
-       lappend cmd $remote
-       console::exec $w $cmd
+       set cmds [list]
+       lappend cmds [list exec git fetch $remote]
+       if {[is_config_true gui.pruneduringfetch]} {
+               lappend cmds [list exec git remote prune $remote]
+       }
+       console::chain $w $cmds
+}
+
+proc prune_from {remote} {
+       set w [console::new \
+               "remote prune $remote" \
+               "Pruning tracking branches deleted from $remote"]
+       console::exec $w [list git remote prune $remote]
 }
 
 proc push_to {remote} {