1 # git-gui transport (fetch/push) support
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 proc fetch_from {remote} {
6 [mc "fetch %s" $remote] \
7 [mc "Fetching new changes from %s" $remote]]
9 lappend cmds [list exec git fetch $remote]
10 if {[is_config_true gui.pruneduringfetch]} {
11 lappend cmds [list exec git remote prune $remote]
13 console::chain $w $cmds
16 proc prune_from {remote} {
18 [mc "remote prune %s" $remote] \
19 [mc "Pruning tracking branches deleted from %s" $remote]]
20 console::exec $w [list git remote prune $remote]
23 proc push_to {remote} {
25 [mc "push %s" $remote] \
26 [mc "Pushing changes to %s" $remote]]
27 set cmd [list git push]
33 proc start_push_anywhere_action {w} {
34 global push_urltype push_remote push_url push_thin push_tags
38 switch -- $push_urltype {
39 remote {set r_url $push_remote}
40 url {set r_url $push_url}
42 if {$r_url eq {}} return
44 set cmd [list git push]
57 foreach i [$w.source.l curselection] {
58 set b [$w.source.l get $i]
59 lappend cmd "refs/heads/$b:refs/heads/$b"
64 } elseif {$cnt == 1} {
70 set cons [console::new \
71 [mc "push %s" $r_url] \
72 [mc "Pushing %s %s to %s" $cnt $unit $r_url]]
73 console::exec $cons $cmd
77 trace add variable push_remote write \
78 [list radio_selector push_urltype remote]
80 proc do_push_anywhere {} {
81 global all_remotes current_branch
82 global push_urltype push_remote push_url push_thin push_tags
87 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
89 label $w.header -text [mc "Push Branches"] -font font_uibold
90 pack $w.header -side top -fill x
93 button $w.buttons.create -text [mc Push] \
95 -command [list start_push_anywhere_action $w]
96 pack $w.buttons.create -side right
97 button $w.buttons.cancel -text [mc "Cancel"] \
99 -command [list destroy $w]
100 pack $w.buttons.cancel -side right -padx 5
101 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
103 labelframe $w.source -text [mc "Source Branches"]
104 listbox $w.source.l \
107 -selectmode extended \
108 -yscrollcommand [list $w.source.sby set]
109 foreach h [load_all_heads] {
110 $w.source.l insert end $h
111 if {$h eq $current_branch} {
112 $w.source.l select set end
115 scrollbar $w.source.sby -command [list $w.source.l yview]
116 pack $w.source.sby -side right -fill y
117 pack $w.source.l -side left -fill both -expand 1
118 pack $w.source -fill both -expand 1 -pady 5 -padx 5
120 labelframe $w.dest -text [mc "Destination Repository"]
121 if {$all_remotes ne {}} {
122 radiobutton $w.dest.remote_r \
123 -text [mc "Remote:"] \
125 -variable push_urltype
126 eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
127 grid $w.dest.remote_r $w.dest.remote_m -sticky w
128 if {[lsearch -sorted -exact $all_remotes origin] != -1} {
129 set push_remote origin
131 set push_remote [lindex $all_remotes 0]
133 set push_urltype remote
137 radiobutton $w.dest.url_r \
138 -text [mc "Arbitrary Location:"] \
140 -variable push_urltype
141 entry $w.dest.url_t \
145 -textvariable push_url \
148 if {%d == 1 && [regexp {\s} %S]} {return 0}
149 if {%d == 1 && [string length %S] > 0} {
154 grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
155 grid columnconfigure $w.dest 1 -weight 1
156 pack $w.dest -anchor nw -fill x -pady 5 -padx 5
158 labelframe $w.options -text [mc "Transfer Options"]
159 checkbutton $w.options.force \
160 -text [mc "Force overwrite existing branch (may discard changes)"] \
162 grid $w.options.force -columnspan 2 -sticky w
163 checkbutton $w.options.thin \
164 -text [mc "Use thin pack (for slow network connections)"] \
166 grid $w.options.thin -columnspan 2 -sticky w
167 checkbutton $w.options.tags \
168 -text [mc "Include tags"] \
170 grid $w.options.tags -columnspan 2 -sticky w
171 grid columnconfigure $w.options 1 -weight 1
172 pack $w.options -anchor nw -fill x -pady 5 -padx 5
179 bind $w <Visibility> "grab $w; focus $w.buttons.create"
180 bind $w <Key-Escape> "destroy $w"
181 bind $w <Key-Return> [list start_push_anywhere_action $w]
182 wm title $w [append "[appname] ([reponame]): " [mc "Push"]]