1 # git-gui remote branch deleting support
2 # Copyright (C) 2007 Shawn Pearce
4 class remote_branch_delete
{
13 field checktype
{head
}
25 constructor dialog
{} {
26 global all_remotes M1B use_ttk NS
29 wm title
$top [append "[appname] ([reponame]): " [mc
"Delete Branch Remotely"]]
31 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
34 ${NS
}::label $w.header
-text [mc
"Delete Branch Remotely"] \
35 -font font_uibold
-anchor center
36 pack $w.header
-side top
-fill x
38 ${NS
}::frame $w.buttons
39 ${NS
}::button $w.buttons.delete
-text [mc Delete
] \
42 pack $w.buttons.delete
-side right
43 ${NS
}::button $w.buttons.cancel
-text [mc
"Cancel"] \
44 -command [list destroy $w]
45 pack $w.buttons.cancel
-side right
-padx 5
46 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
48 ${NS
}::labelframe $w.dest
-text [mc
"From Repository"]
49 if {$all_remotes ne
{}} {
50 ${NS
}::radiobutton $w.dest.remote_r
\
51 -text [mc
"Remote:"] \
55 ttk
::combobox $w.dest.remote_m
-textvariable @remote
\
56 -values $all_remotes -state readonly
58 eval tk_optionMenu $w.dest.remote_m
@remote
$all_remotes
60 grid $w.dest.remote_r
$w.dest.remote_m
-sticky w
61 if {[lsearch -sorted -exact $all_remotes origin
] != -1} {
64 set remote
[lindex $all_remotes 0]
67 trace add
variable @remote write
[cb _write_remote
]
71 ${NS
}::radiobutton $w.dest.url_r
\
72 -text [mc
"Arbitrary Location:"] \
75 ${NS
}::entry $w.dest.url_t
\
80 if {%d
== 1 && [regexp {\s
} %S
]} {return 0}
83 trace add
variable @url write
[cb _write_url
]
84 grid $w.dest.url_r
$w.dest.url_t
-sticky we
-padx {0 5}
85 grid columnconfigure
$w.dest
1 -weight 1
86 pack $w.dest
-anchor nw
-fill x
-pady 5 -padx 5
88 ${NS
}::labelframe $w.heads
-text [mc
"Branches"]
92 -listvariable @head_list
\
95 ${NS
}::frame $w.heads.footer
96 ${NS
}::label $w.heads.footer.status
\
97 -textvariable @status
\
100 ${NS
}::button $w.heads.footer.rescan
\
101 -text [mc
"Rescan"] \
102 -command [cb _rescan
]
103 pack $w.heads.footer.status
-side left
-fill x
104 pack $w.heads.footer.rescan
-side right
106 pack $w.heads.footer
-side bottom
-fill x
107 pack $w.heads.l
-side left
-fill both
-expand 1
108 pack $w.heads
-fill both
-expand 1 -pady 5 -padx 5
110 ${NS
}::labelframe $w.validate
-text [mc
"Delete Only If"]
111 ${NS
}::radiobutton $w.validate.head_r
\
112 -text [mc
"Merged Into:"] \
115 set head_m
[tk_optionMenu $w.validate.head_m
@check_head
{}]
116 trace add
variable @head_list write
[cb _write_head_list
]
117 trace add
variable @check_head write
[cb _write_check_head
]
118 grid $w.validate.head_r
$w.validate.head_m
-sticky w
119 ${NS
}::radiobutton $w.validate.always_r
\
120 -text [mc
"Always (Do not perform merge checks)"] \
123 grid $w.validate.always_r
-columnspan 2 -sticky w
124 grid columnconfigure
$w.validate
1 -weight 1
125 pack $w.validate
-anchor nw
-fill x
-pady 5 -padx 5
127 trace add
variable @urltype write
[cb _write_urltype
]
130 bind $w <Key-F5
> [cb _rescan
]
131 bind $w <$M1B-Key
-r
> [cb _rescan
]
132 bind $w <$M1B-Key
-R
> [cb _rescan
]
133 bind $w <Key-Return
> [cb _delete
]
134 bind $w <Key-Escape
> [list destroy $w]
140 remote
{set uri
$remote}
144 set cache
$urltype:$uri
146 if {$checktype eq
{head
}} {
147 if {$check_head eq
{}} {
151 -title [wm title
$w] \
153 -message [mc
"A branch is required for 'Merged Into'."]
156 set crev
$full_cache("$cache\nrefs/heads/$check_head")
159 set not_merged
[list]
162 set push_cmd
[list git push
]
164 lappend push_cmd
$uri
166 foreach i
[$w.heads.l curselection
] {
167 set ref
[lindex $full_list $i]
169 set obj
$full_cache("$cache\n$ref")
170 if {[catch {set m
[git merge-base
$obj $crev]}]} {
175 lappend not_merged
[lindex $head_list $i]
180 lappend push_cmd
:$ref
184 if {$not_merged ne
{}} {
185 set msg
[mc
"The following branches are not completely merged into %s:
187 - %s" $check_head [join $not_merged "\n - "]]
190 append msg
"\n\n" [mc
"One or more of the merge tests failed because you have not fetched the necessary commits. Try fetching from %s first." $uri]
196 -title [wm title
$w] \
199 if {!$have_selection} return
202 if {!$have_selection} {
206 -title [wm title
$w] \
208 -message [mc
"Please select one or more branches to delete."]
212 if {$checktype ne
{head
}} {
216 -title [wm title
$w] \
218 -message [mc
"Recovering deleted branches is difficult.\n\nDelete the selected branches?"]] ne yes
} {
225 set cons
[console::new \
227 [mc
"Deleting branches from %s" $uri]]
228 console::exec $cons $push_cmd
231 method _rescan
{{force
1}} {
233 remote
{set uri
$remote}
238 unset -nocomplain cached
($urltype:$uri)
241 if {$idle_id ne
{}} {
242 after cancel
$idle_id
246 _load
$this $urltype:$uri $uri
249 method _write_remote
{args
} { set urltype remote
}
250 method _write_url
{args
} { set urltype url
}
251 method _write_check_head
{args
} { set checktype head
}
253 method _write_head_list
{args
} {
254 global current_branch
257 foreach abr
$head_list {
258 $head_m insert end
radiobutton \
261 -variable @check_head
263 if {[lsearch -exact -sorted $head_list $check_head] < 0} {
264 if {[lsearch -exact -sorted $head_list $current_branch] < 0} {
267 set check_head
$current_branch
272 method _write_urltype
{args
} {
273 if {$urltype eq
{url
}} {
274 if {$idle_id ne
{}} {
275 after cancel
$idle_id
278 set idle_id
[after 1000 [cb _rescan
0]]
284 method _load
{cache uri
} {
285 if {$active_ls ne
{}} {
286 catch {close $active_ls}
290 $w.heads.l conf
-state disabled
293 set status
[mc
"No repository selected."]
297 if {[catch {set x
$cached($cache)}]} {
298 set status
[mc
"Scanning %s..." $uri]
299 $w.heads.l conf
-state disabled
302 set head_cache
($cache) [list]
303 set full_cache
($cache) [list]
304 set active_ls
[git_read ls-remote
$uri]
305 fconfigure $active_ls \
309 fileevent $active_ls readable
[cb _read
$cache $active_ls]
312 set full_list
$full_cache($cache)
313 set head_list
$head_cache($cache)
314 $w.heads.l conf
-state normal
318 method _read
{cache fd
} {
319 if {$fd ne
$active_ls} {
324 while {[gets $fd line
] >= 0} {
325 if {[string match
{*^
{}} $line]} continue
326 if {[regexp {^
([0-9a-f
]{40}) (.
*)$} $line _junk obj ref
]} {
327 if {[regsub ^refs
/heads
/ $ref {} abr
]} {
328 lappend head_list
$abr
329 lappend head_cache
($cache) $abr
330 lappend full_list
$ref
331 lappend full_cache
($cache) $ref
332 set full_cache
("$cache\n$ref") $obj
338 if {[catch {close $fd} err
]} {
345 $w.heads.l conf
-state normal