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 fetch_from_all {} {
25 [mc "fetch all remotes"] \
26 [mc "Fetching new changes from all remotes"]]
28 set cmd [list git fetch --all]
29 if {[is_config_true gui.pruneduringfetch]} {
36 proc prune_from_all {} {
40 [mc "remote prune all remotes"] \
41 [mc "Pruning tracking branches deleted from all remotes"]]
43 set cmd [list git remote prune]
45 foreach r $all_remotes {
52 proc push_to {remote} {
54 [mc "push %s" $remote] \
55 [mc "Pushing changes to %s" $remote]]
56 set cmd [list git push]
62 proc start_push_anywhere_action {w} {
63 global push_urltype push_remote push_url push_thin push_tags
69 switch -- $push_urltype {
71 set r_url $push_remote
72 catch {set is_mirror $repo_config(remote.$push_remote.mirror)}
74 url {set r_url $push_url}
76 if {$r_url eq {}} return
78 set cmd [list git push]
91 set cons [console::new \
92 [mc "push %s" $r_url] \
93 [mc "Mirroring to %s" $r_url]]
96 foreach i [$w.source.l curselection] {
97 set b [$w.source.l get $i]
98 lappend cmd "refs/heads/$b:refs/heads/$b"
103 } elseif {$cnt == 1} {
109 set cons [console::new \
110 [mc "push %s" $r_url] \
111 [mc "Pushing %s %s to %s" $cnt $unit $r_url]]
113 console::exec $cons $cmd
117 trace add variable push_remote write \
118 [list radio_selector push_urltype remote]
120 proc do_push_anywhere {} {
121 global all_remotes current_branch
122 global push_urltype push_remote push_url push_thin push_tags
123 global push_force use_ttk NS
127 catch {wm attributes $w -type dialog}
129 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
132 ${NS}::label $w.header -text [mc "Push Branches"] \
133 -font font_uibold -anchor center
134 pack $w.header -side top -fill x
136 ${NS}::frame $w.buttons
137 ${NS}::button $w.buttons.create -text [mc Push] \
139 -command [list start_push_anywhere_action $w]
140 pack $w.buttons.create -side right
141 ${NS}::button $w.buttons.cancel -text [mc "Cancel"] \
143 -command [list destroy $w]
144 pack $w.buttons.cancel -side right -padx 5
145 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
147 ${NS}::labelframe $w.source -text [mc "Source Branches"]
148 slistbox $w.source.l \
152 foreach h [load_all_heads] {
153 $w.source.l insert end $h
154 if {$h eq $current_branch} {
155 $w.source.l select set end
156 $w.source.l yview end
159 pack $w.source.l -side left -fill both -expand 1
160 pack $w.source -fill both -expand 1 -pady 5 -padx 5
162 ${NS}::labelframe $w.dest -text [mc "Destination Repository"]
163 if {$all_remotes ne {}} {
164 ${NS}::radiobutton $w.dest.remote_r \
165 -text [mc "Remote:"] \
167 -variable push_urltype
169 ttk::combobox $w.dest.remote_m -state readonly \
170 -exportselection false \
171 -textvariable push_remote \
174 eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
176 grid $w.dest.remote_r $w.dest.remote_m -sticky w
177 if {[lsearch -sorted -exact $all_remotes origin] != -1} {
178 set push_remote origin
180 set push_remote [lindex $all_remotes 0]
182 set push_urltype remote
186 ${NS}::radiobutton $w.dest.url_r \
187 -text [mc "Arbitrary Location:"] \
189 -variable push_urltype
190 ${NS}::entry $w.dest.url_t \
192 -textvariable push_url \
195 if {%d == 1 && [regexp {\s} %S]} {return 0}
196 if {%d == 1 && [string length %S] > 0} {
201 grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
202 grid columnconfigure $w.dest 1 -weight 1
203 pack $w.dest -anchor nw -fill x -pady 5 -padx 5
205 ${NS}::labelframe $w.options -text [mc "Transfer Options"]
206 ${NS}::checkbutton $w.options.force \
207 -text [mc "Force overwrite existing branch (may discard changes)"] \
209 grid $w.options.force -columnspan 2 -sticky w
210 ${NS}::checkbutton $w.options.thin \
211 -text [mc "Use thin pack (for slow network connections)"] \
213 grid $w.options.thin -columnspan 2 -sticky w
214 ${NS}::checkbutton $w.options.tags \
215 -text [mc "Include tags"] \
217 grid $w.options.tags -columnspan 2 -sticky w
218 grid columnconfigure $w.options 1 -weight 1
219 pack $w.options -anchor nw -fill x -pady 5 -padx 5
226 bind $w <Visibility> "grab $w; focus $w.buttons.create"
227 bind $w <Key-Escape> "destroy $w"
228 bind $w <Key-Return> [list start_push_anywhere_action $w]
229 wm title $w [mc "%s (%s): Push" [appname] [reponame]]