git-gui: allow Ctrl+T to toggle multiple paths
[git/git.git] / lib / transport.tcl
CommitLineData
f522c9b5
SP
1# git-gui transport (fetch/push) support
2# Copyright (C) 2006, 2007 Shawn Pearce
3
4proc fetch_from {remote} {
a35d65d9 5 set w [console::new \
d4278b51 6 [mc "fetch %s" $remote] \
1ac17950 7 [mc "Fetching new changes from %s" $remote]]
5b6ffff6
SP
8 set cmds [list]
9 lappend cmds [list exec git fetch $remote]
10 if {[is_config_true gui.pruneduringfetch]} {
11 lappend cmds [list exec git remote prune $remote]
12 }
13 console::chain $w $cmds
14}
15
16proc prune_from {remote} {
17 set w [console::new \
d4278b51 18 [mc "remote prune %s" $remote] \
1ac17950 19 [mc "Pruning tracking branches deleted from %s" $remote]]
5b6ffff6 20 console::exec $w [list git remote prune $remote]
f522c9b5
SP
21}
22
69e21b83
HV
23proc fetch_from_all {} {
24 set w [console::new \
25 [mc "fetch all remotes"] \
26 [mc "Fetching new changes from all remotes"]]
27
28 set cmd [list git fetch --all]
29 if {[is_config_true gui.pruneduringfetch]} {
30 lappend cmd --prune
31 }
32
33 console::exec $w $cmd
34}
35
36proc prune_from_all {} {
37 global all_remotes
38
39 set w [console::new \
40 [mc "remote prune all remotes"] \
41 [mc "Pruning tracking branches deleted from all remotes"]]
42
43 set cmd [list git remote prune]
44
45 foreach r $all_remotes {
46 lappend cmd $r
47 }
48
49 console::exec $w $cmd
50}
51
f522c9b5 52proc push_to {remote} {
a35d65d9 53 set w [console::new \
d4278b51 54 [mc "push %s" $remote] \
1ac17950 55 [mc "Pushing changes to %s" $remote]]
f522c9b5
SP
56 set cmd [list git push]
57 lappend cmd -v
58 lappend cmd $remote
a35d65d9 59 console::exec $w $cmd
f522c9b5
SP
60}
61
62proc start_push_anywhere_action {w} {
63 global push_urltype push_remote push_url push_thin push_tags
1952aa1d 64 global push_force
861c68e3 65 global repo_config
f522c9b5 66
861c68e3 67 set is_mirror 0
f522c9b5
SP
68 set r_url {}
69 switch -- $push_urltype {
861c68e3
MB
70 remote {
71 set r_url $push_remote
72 catch {set is_mirror $repo_config(remote.$push_remote.mirror)}
73 }
f522c9b5
SP
74 url {set r_url $push_url}
75 }
76 if {$r_url eq {}} return
77
78 set cmd [list git push]
79 lappend cmd -v
80 if {$push_thin} {
81 lappend cmd --thin
82 }
1952aa1d
SP
83 if {$push_force} {
84 lappend cmd --force
85 }
f522c9b5
SP
86 if {$push_tags} {
87 lappend cmd --tags
88 }
89 lappend cmd $r_url
861c68e3
MB
90 if {$is_mirror} {
91 set cons [console::new \
92 [mc "push %s" $r_url] \
93 [mc "Mirroring to %s" $r_url]]
f522c9b5 94 } else {
861c68e3
MB
95 set cnt 0
96 foreach i [$w.source.l curselection] {
97 set b [$w.source.l get $i]
98 lappend cmd "refs/heads/$b:refs/heads/$b"
99 incr cnt
100 }
101 if {$cnt == 0} {
102 return
103 } elseif {$cnt == 1} {
104 set unit branch
105 } else {
106 set unit branches
107 }
f522c9b5 108
861c68e3
MB
109 set cons [console::new \
110 [mc "push %s" $r_url] \
111 [mc "Pushing %s %s to %s" $cnt $unit $r_url]]
112 }
a35d65d9 113 console::exec $cons $cmd
f522c9b5
SP
114 destroy $w
115}
116
117trace add variable push_remote write \
118 [list radio_selector push_urltype remote]
119
120proc do_push_anywhere {} {
d41b43eb 121 global all_remotes current_branch
f522c9b5 122 global push_urltype push_remote push_url push_thin push_tags
c80d7be5 123 global push_force use_ttk NS
f522c9b5
SP
124
125 set w .push_setup
126 toplevel $w
508dee31 127 catch {wm attributes $w -type dialog}
c80d7be5 128 wm withdraw $w
f522c9b5 129 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
c80d7be5 130 pave_toplevel $w
f522c9b5 131
c80d7be5
PT
132 ${NS}::label $w.header -text [mc "Push Branches"] \
133 -font font_uibold -anchor center
f522c9b5
SP
134 pack $w.header -side top -fill x
135
c80d7be5
PT
136 ${NS}::frame $w.buttons
137 ${NS}::button $w.buttons.create -text [mc Push] \
f522c9b5
SP
138 -default active \
139 -command [list start_push_anywhere_action $w]
140 pack $w.buttons.create -side right
c80d7be5 141 ${NS}::button $w.buttons.cancel -text [mc "Cancel"] \
f522c9b5
SP
142 -default normal \
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
146
c80d7be5
PT
147 ${NS}::labelframe $w.source -text [mc "Source Branches"]
148 slistbox $w.source.l \
f522c9b5
SP
149 -height 10 \
150 -width 70 \
c80d7be5 151 -selectmode extended
d41b43eb 152 foreach h [load_all_heads] {
f522c9b5
SP
153 $w.source.l insert end $h
154 if {$h eq $current_branch} {
155 $w.source.l select set end
fb027e14 156 $w.source.l yview end
f522c9b5
SP
157 }
158 }
f522c9b5
SP
159 pack $w.source.l -side left -fill both -expand 1
160 pack $w.source -fill both -expand 1 -pady 5 -padx 5
161
c80d7be5 162 ${NS}::labelframe $w.dest -text [mc "Destination Repository"]
f522c9b5 163 if {$all_remotes ne {}} {
c80d7be5 164 ${NS}::radiobutton $w.dest.remote_r \
1ac17950 165 -text [mc "Remote:"] \
f522c9b5
SP
166 -value remote \
167 -variable push_urltype
c80d7be5 168 if {$use_ttk} {
9e34e62b
HV
169 ttk::combobox $w.dest.remote_m -state readonly \
170 -exportselection false \
171 -textvariable push_remote \
c80d7be5
PT
172 -values $all_remotes
173 } else {
174 eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
175 }
f522c9b5
SP
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
179 } else {
180 set push_remote [lindex $all_remotes 0]
181 }
182 set push_urltype remote
183 } else {
184 set push_urltype url
185 }
c80d7be5 186 ${NS}::radiobutton $w.dest.url_r \
4259568d 187 -text [mc "Arbitrary Location:"] \
f522c9b5
SP
188 -value url \
189 -variable push_urltype
c80d7be5 190 ${NS}::entry $w.dest.url_t \
f522c9b5
SP
191 -width 50 \
192 -textvariable push_url \
193 -validate key \
194 -validatecommand {
195 if {%d == 1 && [regexp {\s} %S]} {return 0}
196 if {%d == 1 && [string length %S] > 0} {
197 set push_urltype url
198 }
199 return 1
200 }
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
204
c80d7be5
PT
205 ${NS}::labelframe $w.options -text [mc "Transfer Options"]
206 ${NS}::checkbutton $w.options.force \
1952aa1d
SP
207 -text [mc "Force overwrite existing branch (may discard changes)"] \
208 -variable push_force
209 grid $w.options.force -columnspan 2 -sticky w
c80d7be5 210 ${NS}::checkbutton $w.options.thin \
1ac17950 211 -text [mc "Use thin pack (for slow network connections)"] \
f522c9b5
SP
212 -variable push_thin
213 grid $w.options.thin -columnspan 2 -sticky w
c80d7be5 214 ${NS}::checkbutton $w.options.tags \
1ac17950 215 -text [mc "Include tags"] \
f522c9b5
SP
216 -variable push_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
220
221 set push_url {}
1952aa1d 222 set push_force 0
f522c9b5
SP
223 set push_thin 0
224 set push_tags 0
225
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]
a3d97afa 229 wm title $w [mc "%s (%s): Push" [appname] [reponame]]
c80d7be5 230 wm deiconify $w
f522c9b5
SP
231 tkwait window $w
232}