Merge branch 'nd/narrow' (early part) into jc/add-i-t-a
[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 push_to {remote} {
24         set w [console::new \
25                 [mc "push %s" $remote] \
26                 [mc "Pushing changes to %s" $remote]]
27         set cmd [list git push]
28         lappend cmd -v
29         lappend cmd $remote
30         console::exec $w $cmd
31 }
32
33 proc start_push_anywhere_action {w} {
34         global push_urltype push_remote push_url push_thin push_tags
35         global push_force
36
37         set r_url {}
38         switch -- $push_urltype {
39         remote {set r_url $push_remote}
40         url {set r_url $push_url}
41         }
42         if {$r_url eq {}} return
43
44         set cmd [list git push]
45         lappend cmd -v
46         if {$push_thin} {
47                 lappend cmd --thin
48         }
49         if {$push_force} {
50                 lappend cmd --force
51         }
52         if {$push_tags} {
53                 lappend cmd --tags
54         }
55         lappend cmd $r_url
56         set cnt 0
57         foreach i [$w.source.l curselection] {
58                 set b [$w.source.l get $i]
59                 lappend cmd "refs/heads/$b:refs/heads/$b"
60                 incr cnt
61         }
62         if {$cnt == 0} {
63                 return
64         } elseif {$cnt == 1} {
65                 set unit branch
66         } else {
67                 set unit branches
68         }
69
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
74         destroy $w
75 }
76
77 trace add variable push_remote write \
78         [list radio_selector push_urltype remote]
79
80 proc do_push_anywhere {} {
81         global all_remotes current_branch
82         global push_urltype push_remote push_url push_thin push_tags
83         global push_force
84
85         set w .push_setup
86         toplevel $w
87         wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
88
89         label $w.header -text [mc "Push Branches"] -font font_uibold
90         pack $w.header -side top -fill x
91
92         frame $w.buttons
93         button $w.buttons.create -text [mc Push] \
94                 -default active \
95                 -command [list start_push_anywhere_action $w]
96         pack $w.buttons.create -side right
97         button $w.buttons.cancel -text [mc "Cancel"] \
98                 -default normal \
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
102
103         labelframe $w.source -text [mc "Source Branches"]
104         listbox $w.source.l \
105                 -height 10 \
106                 -width 70 \
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
113                 }
114         }
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
119
120         labelframe $w.dest -text [mc "Destination Repository"]
121         if {$all_remotes ne {}} {
122                 radiobutton $w.dest.remote_r \
123                         -text [mc "Remote:"] \
124                         -value 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
130                 } else {
131                         set push_remote [lindex $all_remotes 0]
132                 }
133                 set push_urltype remote
134         } else {
135                 set push_urltype url
136         }
137         radiobutton $w.dest.url_r \
138                 -text [mc "Arbitrary Location:"] \
139                 -value url \
140                 -variable push_urltype
141         entry $w.dest.url_t \
142                 -borderwidth 1 \
143                 -relief sunken \
144                 -width 50 \
145                 -textvariable push_url \
146                 -validate key \
147                 -validatecommand {
148                         if {%d == 1 && [regexp {\s} %S]} {return 0}
149                         if {%d == 1 && [string length %S] > 0} {
150                                 set push_urltype url
151                         }
152                         return 1
153                 }
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
157
158         labelframe $w.options -text [mc "Transfer Options"]
159         checkbutton $w.options.force \
160                 -text [mc "Force overwrite existing branch (may discard changes)"] \
161                 -variable push_force
162         grid $w.options.force -columnspan 2 -sticky w
163         checkbutton $w.options.thin \
164                 -text [mc "Use thin pack (for slow network connections)"] \
165                 -variable push_thin
166         grid $w.options.thin -columnspan 2 -sticky w
167         checkbutton $w.options.tags \
168                 -text [mc "Include tags"] \
169                 -variable push_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
173
174         set push_url {}
175         set push_force 0
176         set push_thin 0
177         set push_tags 0
178
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"]]
183         tkwait window $w
184 }