Merge git-gui 0.14.0
[git/git.git] / git-gui / lib / transport.tcl
1 # git-gui transport (fetch/push) support
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 proc fetch_from {remote} {
5 set w [console::new \
6 [mc "fetch %s" $remote] \
7 [mc "Fetching new changes from %s" $remote]]
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
16 proc prune_from {remote} {
17 set w [console::new \
18 [mc "remote prune %s" $remote] \
19 [mc "Pruning tracking branches deleted from %s" $remote]]
20 console::exec $w [list git remote prune $remote]
21 }
22
23 proc 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
36 proc 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
52 proc push_to {remote} {
53 set w [console::new \
54 [mc "push %s" $remote] \
55 [mc "Pushing changes to %s" $remote]]
56 set cmd [list git push]
57 lappend cmd -v
58 lappend cmd $remote
59 console::exec $w $cmd
60 }
61
62 proc start_push_anywhere_action {w} {
63 global push_urltype push_remote push_url push_thin push_tags
64 global push_force
65 global repo_config
66
67 set is_mirror 0
68 set r_url {}
69 switch -- $push_urltype {
70 remote {
71 set r_url $push_remote
72 catch {set is_mirror $repo_config(remote.$push_remote.mirror)}
73 }
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 }
83 if {$push_force} {
84 lappend cmd --force
85 }
86 if {$push_tags} {
87 lappend cmd --tags
88 }
89 lappend cmd $r_url
90 if {$is_mirror} {
91 set cons [console::new \
92 [mc "push %s" $r_url] \
93 [mc "Mirroring to %s" $r_url]]
94 } else {
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 }
108
109 set cons [console::new \
110 [mc "push %s" $r_url] \
111 [mc "Pushing %s %s to %s" $cnt $unit $r_url]]
112 }
113 console::exec $cons $cmd
114 destroy $w
115 }
116
117 trace add variable push_remote write \
118 [list radio_selector push_urltype remote]
119
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
124
125 set w .push_setup
126 toplevel $w
127 wm withdraw $w
128 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
129 pave_toplevel $w
130
131 ${NS}::label $w.header -text [mc "Push Branches"] \
132 -font font_uibold -anchor center
133 pack $w.header -side top -fill x
134
135 ${NS}::frame $w.buttons
136 ${NS}::button $w.buttons.create -text [mc Push] \
137 -default active \
138 -command [list start_push_anywhere_action $w]
139 pack $w.buttons.create -side right
140 ${NS}::button $w.buttons.cancel -text [mc "Cancel"] \
141 -default normal \
142 -command [list destroy $w]
143 pack $w.buttons.cancel -side right -padx 5
144 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
145
146 ${NS}::labelframe $w.source -text [mc "Source Branches"]
147 slistbox $w.source.l \
148 -height 10 \
149 -width 70 \
150 -selectmode extended
151 foreach h [load_all_heads] {
152 $w.source.l insert end $h
153 if {$h eq $current_branch} {
154 $w.source.l select set end
155 $w.source.l yview end
156 }
157 }
158 pack $w.source.l -side left -fill both -expand 1
159 pack $w.source -fill both -expand 1 -pady 5 -padx 5
160
161 ${NS}::labelframe $w.dest -text [mc "Destination Repository"]
162 if {$all_remotes ne {}} {
163 ${NS}::radiobutton $w.dest.remote_r \
164 -text [mc "Remote:"] \
165 -value remote \
166 -variable push_urltype
167 if {$use_ttk} {
168 ttk::combobox $w.dest.remote_m -state readonly \
169 -exportselection false \
170 -textvariable push_remote \
171 -values $all_remotes
172 } else {
173 eval tk_optionMenu $w.dest.remote_m push_remote $all_remotes
174 }
175 grid $w.dest.remote_r $w.dest.remote_m -sticky w
176 if {[lsearch -sorted -exact $all_remotes origin] != -1} {
177 set push_remote origin
178 } else {
179 set push_remote [lindex $all_remotes 0]
180 }
181 set push_urltype remote
182 } else {
183 set push_urltype url
184 }
185 ${NS}::radiobutton $w.dest.url_r \
186 -text [mc "Arbitrary Location:"] \
187 -value url \
188 -variable push_urltype
189 ${NS}::entry $w.dest.url_t \
190 -width 50 \
191 -textvariable push_url \
192 -validate key \
193 -validatecommand {
194 if {%d == 1 && [regexp {\s} %S]} {return 0}
195 if {%d == 1 && [string length %S] > 0} {
196 set push_urltype url
197 }
198 return 1
199 }
200 grid $w.dest.url_r $w.dest.url_t -sticky we -padx {0 5}
201 grid columnconfigure $w.dest 1 -weight 1
202 pack $w.dest -anchor nw -fill x -pady 5 -padx 5
203
204 ${NS}::labelframe $w.options -text [mc "Transfer Options"]
205 ${NS}::checkbutton $w.options.force \
206 -text [mc "Force overwrite existing branch (may discard changes)"] \
207 -variable push_force
208 grid $w.options.force -columnspan 2 -sticky w
209 ${NS}::checkbutton $w.options.thin \
210 -text [mc "Use thin pack (for slow network connections)"] \
211 -variable push_thin
212 grid $w.options.thin -columnspan 2 -sticky w
213 ${NS}::checkbutton $w.options.tags \
214 -text [mc "Include tags"] \
215 -variable push_tags
216 grid $w.options.tags -columnspan 2 -sticky w
217 grid columnconfigure $w.options 1 -weight 1
218 pack $w.options -anchor nw -fill x -pady 5 -padx 5
219
220 set push_url {}
221 set push_force 0
222 set push_thin 0
223 set push_tags 0
224
225 bind $w <Visibility> "grab $w; focus $w.buttons.create"
226 bind $w <Key-Escape> "destroy $w"
227 bind $w <Key-Return> [list start_push_anywhere_action $w]
228 wm title $w [append "[appname] ([reponame]): " [mc "Push"]]
229 wm deiconify $w
230 tkwait window $w
231 }