Subject: [PATCH] git-gui: Include version check and test for tearoff menu entry

From: Pat Thoyts <[email-masked]>
Date: Mon, 14 Feb 2011 13:03:24 +0000

The --all option for git fetch was added in v1.6.6 so ensure we have a usable version before adding
the menu items.
Sometimes people use tearoff menus and these offset the entry indices by one.

Signed-off-by: Pat Thoyts <[email-masked]>
---

Heiko Voigt <[email-masked]> writes:
>It just came to my mind that I probably should implement a version check
>of the commandline to ensure that this option is available. Thats why I
>tagged only this patch with RFC.
>
>Cheers Heiko

The posted patch seems fine except that an error is reported if tearoff
menus are present. So this patch accommodates tearoff's. I looked up
when the --all option was added (1.6.6) and skip adding the menu entry
if we have an older version.

Seems to do the right thing.

 lib/remote.tcl |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/remote.tcl b/lib/remote.tcl
index 817ca1b..b88f6e5 100644
--- a/lib/remote.tcl
+++ b/lib/remote.tcl
@@ -233,6 +233,8 @@ proc make_sure_remote_submenues_exist {remote_m} {
 proc update_all_remotes_menu_entry {} {
 	global all_remotes
 
+	if {[git-version < 1.6.6]} { return }
+
 	set have_remote 0
 	foreach r $all_remotes {
 		set have_remote 1
@@ -243,27 +245,29 @@ proc update_all_remotes_menu_entry {} {
 	set prune_m $remote_m.prune
 	if {$have_remote} {
 		make_sure_remote_submenues_exist $remote_m
-		if {[$fetch_m entrycget 0 -label] ne "All"} {
+		set index [expr {[$fetch_m type 0] eq "tearoff" ? 1 : 0}]
+		if {[$fetch_m entrycget $index -label] ne "All"} {
 
-			$fetch_m insert 0 separator
-			$fetch_m insert 0 command \
+			$fetch_m insert $index separator
+			$fetch_m insert $index command \
 				-label "All" \
 				-command fetch_from_all
 
-			$prune_m insert 0 separator
-			$prune_m insert 0 command \
+			$prune_m insert $index separator
+			$prune_m insert $index command \
 	  			-label "All" \
 				-command prune_from_all
 		}
 	} else {
 		if {[winfo exists $fetch_m]} {
+			set index [expr {[$fetch_m type 0] eq "tearoff" ? 1 : 0}]
 			if {[$fetch_m type end] eq "separator"} {
 
-				delete_from_menu $fetch_m 0
-				delete_from_menu $fetch_m 0
+				delete_from_menu $fetch_m $index
+				delete_from_menu $fetch_m $index
 
-				delete_from_menu $prune_m 0
-				delete_from_menu $prune_m 0
+				delete_from_menu $prune_m $index
+				delete_from_menu $prune_m $index
 			}
 		}
 	}
-- 
1.7.4.47.gb308bf