ce6fc45eba1d26a9d4221793f1da8ae1ebf06a66
   1# git-gui transport (fetch/push) support
   2# Copyright (C) 2006, 2007 Shawn Pearce
   3
   4proc fetch_from {remote} {
   5        set w [new_console \
   6                "fetch $remote" \
   7                "Fetching new changes from $remote"]
   8        set cmd [list git fetch]
   9        lappend cmd $remote
  10        console_exec $w $cmd console_done
  11}
  12
  13proc push_to {remote} {
  14        set w [new_console \
  15                "push $remote" \
  16                "Pushing changes to $remote"]
  17        set cmd [list git push]
  18        lappend cmd -v
  19        lappend cmd $remote
  20        console_exec $w $cmd console_done
  21}
  22
  23proc start_push_anywhere_action {w} {
  24        global push_urltype push_remote push_url push_thin push_tags
  25
  26        set r_url {}
  27        switch -- $push_urltype {
  28        remote {set r_url $push_remote}
  29        url {set r_url $push_url}
  30        }
  31        if {$r_url eq {}} return
  32
  33        set cmd [list git push]
  34        lappend cmd -v
  35        if {$push_thin} {
  36                lappend cmd --thin
  37        }
  38        if {$push_tags} {
  39                lappend cmd --tags
  40        }
  41        lappend cmd $r_url
  42        set cnt 0
  43        foreach i [$w.source.l curselection] {
  44                set b [$w.source.l get $i]
  45                lappend cmd "refs/heads/$b:refs/heads/$b"
  46                incr cnt
  47        }
  48        if {$cnt == 0} {
  49                return
  50        } elseif {$cnt == 1} {
  51                set unit branch
  52        } else {
  53                set unit branches
  54        }
  55
  56        set cons [new_console "push $r_url" "Pushing $cnt $unit to $r_url"]
  57        console_exec $cons $cmd console_done
  58        destroy $w
  59}
  60
  61trace add variable push_remote write \
  62        [list radio_selector push_urltype remote]
  63
  64proc do_push_anywhere {} {
  65        global all_heads all_remotes current_branch
  66        global push_urltype push_remote push_url push_thin push_tags
  67
  68        set w .push_setup
  69        toplevel $w
  70        wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
  71
  72        label $w.header -text {Push Branches} -font font_uibold
  73        pack $w.header -side top -fill x
  74
  75        frame $w.buttons
  76        button $w.buttons.create -text Push \
  77                -default active \
  78                -command [list start_push_anywhere_action $w]
  79        pack $w.buttons.create -side right
  80        button $w.buttons.cancel -text {Cancel} \
  81                -default normal \
  82                -command [list destroy $w]
  83        pack $w.buttons.cancel -side right -padx 5
  84        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
  85
  86        labelframe $w.source -text {Source Branches}
  87        listbox $w.source.l \
  88                -height 10 \
  89                -width 70 \
  90                -selectmode extended \
  91                -yscrollcommand [list $w.source.sby set]
  92        foreach h $all_heads {
  93                $w.source.l insert end $h
  94                if {$h eq $current_branch} {
  95                        $w.source.l select set end
  96                }
  97        }
  98        scrollbar $w.source.sby -command [list $w.source.l yview]
  99        pack $w.source.sby -side right -fill y
 100        pack $w.source.l -side left -fill both -expand 1
 101        pack $w.source -fill both -expand 1 -pady 5 -padx 5
 102
 103        labelframe $w.dest -text {Destination Repository}
 104        if {$all_remotes ne {}} {
 105                radiobutton $w.dest.remote_r \
 106                        -text {Remote:} \
 107                        -value remote \
 108                        -variable push_urltype
 109                eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
 110                grid $w.dest.remote_r $w.dest.remote_m -sticky w
 111                if {[lsearch -sorted -exact $all_remotes origin] != -1} {
 112                        set push_remote origin
 113                } else {
 114                        set push_remote [lindex $all_remotes 0]
 115                }
 116                set push_urltype remote
 117        } else {
 118                set push_urltype url
 119        }
 120        radiobutton $w.dest.url_r \
 121                -text {Arbitrary URL:} \
 122                -value url \
 123                -variable push_urltype
 124        entry $w.dest.url_t \
 125                -borderwidth 1 \
 126                -relief sunken \
 127                -width 50 \
 128                -textvariable push_url \
 129                -validate key \
 130                -validatecommand {
 131                        if {%d == 1 && [regexp {\s} %S]} {return 0}
 132                        if {%d == 1 && [string length %S] > 0} {
 133                                set push_urltype url
 134                        }
 135                        return 1
 136                }
 137        grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
 138        grid columnconfigure $w.dest 1 -weight 1
 139        pack $w.dest -anchor nw -fill x -pady 5 -padx 5
 140
 141        labelframe $w.options -text {Transfer Options}
 142        checkbutton $w.options.thin \
 143                -text {Use thin pack (for slow network connections)} \
 144                -variable push_thin
 145        grid $w.options.thin -columnspan 2 -sticky w
 146        checkbutton $w.options.tags \
 147                -text {Include tags} \
 148                -variable push_tags
 149        grid $w.options.tags -columnspan 2 -sticky w
 150        grid columnconfigure $w.options 1 -weight 1
 151        pack $w.options -anchor nw -fill x -pady 5 -padx 5
 152
 153        set push_url {}
 154        set push_thin 0
 155        set push_tags 0
 156
 157        bind $w <Visibility> "grab $w; focus $w.buttons.create"
 158        bind $w <Key-Escape> "destroy $w"
 159        bind $w <Key-Return> [list start_push_anywhere_action $w]
 160        wm title $w "[appname] ([reponame]): Push"
 161        tkwait window $w
 162}