@matheusbsbs / matheus-bagliano / commits / 1d6a978752
Fork 0

git-gui: Added arbitrary branch pushing support.

Because its common for some users to push topic branches to a remote repository for review and merging by other parties, users need an easy way to push one or more branches to a remote repository without needing to edit their .git/config file anytime their set of active branches changes. We now provide a basic 'Push...' menu action in the Push menu which opens a dialog allowing the user to select from their set of local branches (refs/heads, minus tracking branches). The user can designate which repository to send the changes to by selecting from an already configured remote or by entering any valid Git URL. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 25, 2007 at 23:50 UTC 1d6a9787526372609d3b105659e9cb5f3718df4a
1 file changed +158
git-gui.sh
+158
@@ -2471,6 +2471,7 @@ proc populate_push_menu {} {
2471 global all_remotes repo_config
2472
2473 set m .mbar.push
2474 + set fast_count 0
2475 foreach r $all_remotes {
2476 set enable 0
2477 if {![catch {set a $repo_config(remote.$r.url)}]} {
@@ -2491,12 +2492,165 @@ proc populate_push_menu {} {
2492 }
2493
2494 if {$enable} {
2495 + if {!$fast_count} {
2496 + $m add separator
2497 + }
2498 $m add command \
2499 -label "Push to $r..." \
2500 -command [list push_to $r] \
2501 -font font_ui
2502 + incr fast_count
2503 + }
2504 + }
2505 +}
2506 +
2507 +proc start_push_anywhere_action {w} {
2508 + global push_urltype push_remote push_url push_thin push_tags
2509 +
2510 + set r_url {}
2511 + switch -- $push_urltype {
2512 + remote {set r_url $push_remote}
2513 + url {set r_url $push_url}
2514 + }
2515 + if {$r_url eq {}} return
2516 +
2517 + set cmd [list git push]
2518 + lappend cmd -v
2519 + if {$push_thin} {
2520 + lappend cmd --thin
2521 + }
2522 + if {$push_tags} {
2523 + lappend cmd --tags
2524 + }
2525 + lappend cmd $r_url
2526 + set cnt 0
2527 + foreach i [$w.source.l curselection] {
2528 + set b [$w.source.l get $i]
2529 + lappend cmd "refs/heads/$b:refs/heads/$b"
2530 + incr cnt
2531 + }
2532 + if {$cnt == 0} {
2533 + return
2534 + } elseif {$cnt == 1} {
2535 + set unit branch
2536 + } else {
2537 + set unit branches
2538 + }
2539 +
2540 + set cons [new_console "push $r_url" "Pushing $cnt $unit to $r_url"]
2541 + console_exec $cons $cmd
2542 + destroy $w
2543 +}
2544 +
2545 +trace add variable push_remote write \
2546 + [list radio_selector push_urltype remote]
2547 +
2548 +proc do_push_anywhere {} {
2549 + global all_heads all_remotes current_branch
2550 + global push_urltype push_remote push_url push_thin push_tags
2551 +
2552 + set w .push_setup
2553 + toplevel $w
2554 + wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2555 +
2556 + label $w.header -text {Push Branches} -font font_uibold
2557 + pack $w.header -side top -fill x
2558 +
2559 + frame $w.buttons
2560 + button $w.buttons.create -text Push \
2561 + -font font_ui \
2562 + -command [list start_push_anywhere_action $w]
2563 + pack $w.buttons.create -side right
2564 + button $w.buttons.cancel -text {Cancel} \
2565 + -font font_ui \
2566 + -command [list destroy $w]
2567 + pack $w.buttons.cancel -side right -padx 5
2568 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2569 +
2570 + labelframe $w.source \
2571 + -text {Source Branches} \
2572 + -font font_ui
2573 + listbox $w.source.l \
2574 + -height 10 \
2575 + -width 50 \
2576 + -selectmode extended \
2577 + -font font_ui
2578 + foreach h $all_heads {
2579 + $w.source.l insert end $h
2580 + if {$h eq $current_branch} {
2581 + $w.source.l select set end
2582 + }
2583 + }
2584 + pack $w.source.l -fill both -pady 5 -padx 5
2585 + pack $w.source -fill both -pady 5 -padx 5
2586 +
2587 + labelframe $w.dest \
2588 + -text {Destination Repository} \
2589 + -font font_ui
2590 + if {$all_remotes ne {}} {
2591 + radiobutton $w.dest.remote_r \
2592 + -text {Remote:} \
2593 + -value remote \
2594 + -variable push_urltype \
2595 + -font font_ui
2596 + eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
2597 + grid $w.dest.remote_r $w.dest.remote_m -sticky w
2598 + if {[lsearch -sorted -exact $all_remotes origin] != -1} {
2599 + set push_remote origin
2600 + } else {
2601 + set push_remote [lindex $all_remotes 0]
2602 }
2603 + set push_urltype remote
2604 + } else {
2605 + set push_urltype url
2606 }
2607 + radiobutton $w.dest.url_r \
2608 + -text {Arbitrary URL:} \
2609 + -value url \
2610 + -variable push_urltype \
2611 + -font font_ui
2612 + entry $w.dest.url_t \
2613 + -borderwidth 1 \
2614 + -relief sunken \
2615 + -width 50 \
2616 + -textvariable push_url \
2617 + -font font_ui \
2618 + -validate key \
2619 + -validatecommand {
2620 + if {%d == 1 && [regexp {\s} %S]} {return 0}
2621 + if {%d == 1 && [string length %S] > 0} {
2622 + set push_urltype url
2623 + }
2624 + return 1
2625 + }
2626 + grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
2627 + grid columnconfigure $w.dest 1 -weight 1
2628 + pack $w.dest -anchor nw -fill x -pady 5 -padx 5
2629 +
2630 + labelframe $w.options \
2631 + -text {Transfer Options} \
2632 + -font font_ui
2633 + checkbutton $w.options.thin \
2634 + -text {Use thin pack (for slow network connections)} \
2635 + -variable push_thin \
2636 + -font font_ui
2637 + grid $w.options.thin -columnspan 2 -sticky w
2638 + checkbutton $w.options.tags \
2639 + -text {Include tags} \
2640 + -variable push_tags \
2641 + -font font_ui
2642 + grid $w.options.tags -columnspan 2 -sticky w
2643 + grid columnconfigure $w.options 1 -weight 1
2644 + pack $w.options -anchor nw -fill x -pady 5 -padx 5
2645 +
2646 + set push_url {}
2647 + set push_thin 0
2648 + set push_tags 0
2649 +
2650 + bind $w <Visibility> "grab $w"
2651 + bind $w <Key-Escape> "destroy $w"
2652 + wm title $w "[appname] ([reponame]): Push"
2653 + tkwait window $w
2654 }
2655
2656 ######################################################################
@@ -3900,6 +4054,10 @@ lappend disable_on_lock \
4054 if {!$single_commit} {
4055 menu .mbar.fetch
4056 menu .mbar.push
4057 +
4058 + .mbar.push add command -label {Push...} \
4059 + -command do_push_anywhere \
4060 + -font font_ui
4061 }
4062
4063 if {[is_MacOSX]} {