@matheusbsbs / matheus-bagliano / commits / c1237ae288
Fork 0

git-gui: Only populate a fetch or push if we have an action.

Don't offer to fetch from a remote unless we have at least one Pull: line in its .git/remotes/<name> file or at least one configuration value for remote.<name>.fetch. Ditto for push. Users shouldn't be fetching or pushing branch groups unless they have them configured; anything else is just crazy. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 15, 2006 at 23:52 UTC c1237ae288aae7e45a18f3d5097b49451293acfe
1 file changed +60 -8
git-gui
+60 -8
@@ -1343,13 +1343,65 @@ proc load_all_remotes {} {
1343 set all_remotes [lsort -unique $all_remotes]
1344 }
1345
1346 -proc populate_remote_menu {m pfx op} {
1347 - global all_remotes
1346 +proc populate_fetch_menu {m} {
1347 + global gitdir all_remotes repo_config
1348
1349 - foreach remote $all_remotes {
1350 - $m add command -label "$pfx $remote..." \
1351 - -command [list $op $remote] \
1352 - -font font_ui
1349 + foreach r $all_remotes {
1350 + set enable 0
1351 + if {![catch {set a $repo_config(remote.$r.url)}]} {
1352 + if {![catch {set a $repo_config(remote.$r.fetch)}]} {
1353 + set enable 1
1354 + }
1355 + } else {
1356 + catch {
1357 + set fd [open [file join $gitdir remotes $r] r]
1358 + while {[gets $fd n] >= 0} {
1359 + if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
1360 + set enable 1
1361 + break
1362 + }
1363 + }
1364 + close $fd
1365 + }
1366 + }
1367 +
1368 + if {$enable} {
1369 + $m add command \
1370 + -label "Fetch from $r..." \
1371 + -command [list fetch_from $r] \
1372 + -font font_ui
1373 + }
1374 + }
1375 +}
1376 +
1377 +proc populate_push_menu {m} {
1378 + global gitdir all_remotes repo_config
1379 +
1380 + foreach r $all_remotes {
1381 + set enable 0
1382 + if {![catch {set a $repo_config(remote.$r.url)}]} {
1383 + if {![catch {set a $repo_config(remote.$r.push)}]} {
1384 + set enable 1
1385 + }
1386 + } else {
1387 + catch {
1388 + set fd [open [file join $gitdir remotes $r] r]
1389 + while {[gets $fd n] >= 0} {
1390 + if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
1391 + set enable 1
1392 + break
1393 + }
1394 + }
1395 + close $fd
1396 + }
1397 + }
1398 +
1399 + if {$enable} {
1400 + $m add command \
1401 + -label "Push to $r..." \
1402 + -command [list push_to $r] \
1403 + -font font_ui
1404 + }
1405 }
1406 }
1407
@@ -2713,8 +2765,8 @@ wm title . "$appname ([file normalize [file dirname $gitdir]])"
2765 focus -force $ui_comm
2766 if {!$single_commit} {
2767 load_all_remotes
2716 - populate_remote_menu .mbar.fetch From fetch_from
2717 - populate_remote_menu .mbar.push To push_to
2768 + populate_fetch_menu .mbar.fetch
2769 populate_pull_menu .mbar.pull
2770 + populate_push_menu .mbar.push
2771 }
2772 after 1 do_rescan