3 # GUI interface for common LilyPond git repository commands
4 # Copyright 2009 by Johannes Schindelin and Carl Sorensen
9 # set to 1 to set up for translation, to 0 for other
12 if {$translator == 1} {
14 "LilyPond Translator's Git Interface version $version"
15 set updateButtonText "1. Update translation"
16 set initializeButtonText "1. Get translation"
17 set originHead "lilypond/translation"
21 "LilyPond Contributor's Git Interface version $version"
22 set updateButtonText "1. Update source"
23 set initializeButtonText "1. Get source"
24 set originHead "master"
31 set lily_dir $env(HOME)/lilypond
32 if {[file exists $lily_dir]} {
36 set abort_dir "./aborted_edits"
38 proc write_to_output {s} {
39 .output.text insert insert $s
43 proc write_file_to_output {f} {
46 fconfigure $f -blocking true
47 if {[catch {close $f} err]} {
48 tk_messageBox -type ok -message \
49 "Command returned an error: $err\n\nCheck output text for details"
53 write_to_output [read $f 24]
58 global lily_dir git_command
59 set git_command [linsert $args 0 "|git" "--git-dir=$lily_dir/.git"]
60 set git_command "$git_command 2>@1"
61 .output.text insert end "$git_command\n"
62 set git [open $git_command r]
63 fconfigure $git -blocking false
64 fileevent $git readable [list write_file_to_output $git]
70 set p [open [linsert $args 0 "|git" --git-dir=$lily_dir/.git config] r]
71 set result [regsub "\n\$" [read $p] ""]
72 if {[catch {close $p} err]} {
73 tk_messageBox -type ok -message "config failed: $err"
78 proc config_quiet {args} {
80 set p [open [linsert $args 0 "|git" --git-dir=$lily_dir/.git config] r]
81 set result [regsub "\n\$" [read $p] ""]
82 if {[catch {close $p} err]} {
88 proc update_lilypond_rebase {} {
94 global commit_canceled
97 tkwait visibility .commitMessage
98 tkwait window .commitMessage
99 if {$commit_canceled != 1} {
100 if {$commit_message == ""} {
101 tk_messageBox -message "You must enter a commit message!" \
104 git commit -a -m $commit_message
105 git rebase --whitespace=fix HEAD^
106 set commit_message ""
111 # This won't work, because --amend needs an editor
112 # lilyconfig users are on their own.
113 proc commit_amend {} {
114 git commit -a --amend
115 git rebase --whitespace=fix HEAD^
118 proc update_lilypond_norebase {} {
122 proc update_lilypond_with_rebase {} {
124 update_lilypond $rebase
127 proc update_lilypond {rebase} {
131 . config -cursor watch
132 if {![file exists $lily_dir]} {
133 write_to_output "Cloning LilyPond (this can take some time) ...\n"
137 git config core.bare false
138 git remote add -t $originHead \
139 origin git://git.sv.gnu.org/lilypond.git
140 if {$translator == 1} {
145 git reset --hard origin/$originHead
146 git config branch.$originHead.remote origin
147 git config branch.$originHead.merge refs/heads/$originHead
148 .buttons.commit configure -state normal
149 .buttons.update configure -text buttonUpdateText
150 .buttons.patch configure -state normal
151 .buttons.panic configure -state normal
154 write_to_output "Updating LilyPond...\n"
157 git rebase origin/$originHead
159 git merge origin/$originHead
162 write_to_output "Done.\n"
166 proc patch_from_origin {} {
168 make_patch_from_origin $rebase
169 if {![llength [glob -nocomplain 0*.patch]]} {
170 tk_messageBox -type ok -message \
171 "No patches created; did you make a local commit?"
175 proc make_patch_from_origin {rebase} {
178 . config -cursor watch
179 update_lilypond $rebase
180 write_to_output "Creating patch...\n"
181 git format-patch origin/$originHead
182 write_to_output "Done.\n"
186 proc abort_changes {} {
189 set answer [tk_messageBox -type okcancel \
190 -message "This will copy all changed files to $abort_dir and reset the repository." \
194 write_to_output "abort_dir: $abort_dir \n"
195 if {![file exists $abort_dir]} {
196 set return_code [exec mkdir $abort_dir]
198 set return_code [catch {exec git diff origin/$originHead} gitdiff]
199 set return_code [regexp {diff --git a/(\S*)} $gitdiff match modified_file]
200 while {$return_code != 0} {
201 write_to_output "Copying $modified_file to $abort_dir.\n"
202 set return_code [catch {exec cp $modified_file $abort_dir} result]
203 set return_code [regsub {diff --git a/(\S*)} $gitdiff "" gitdiff]
204 set return_code [regexp {diff --git a/(\S*)} $gitdiff match modified_file]
206 set return_code [git reset --hard origin/$originHead]
207 write_to_output "Repository reset. \n"
212 proc toggle_rebase {} {
216 global updateButtonText
217 global initializeButtonText
218 if {[file exists $lily_dir]} {
219 config --bool branch.$originHead.rebase $rebase
220 .buttons.update configure -text $updateButtonText
222 .buttons.update configure -text $initializeButtonText
226 proc clear_rebase {} {
238 proc commitMessageOK {} {
239 global commit_message
241 set commit_body [.commitMessage.bottomFrame.commit_body get 1.0 end]
242 set commit_message "$commit_header\n\n$commit_body"
243 destroy .commitMessage
246 proc commitMessageCancel {} {
247 global commit_message
248 global commit_canceled
249 set commit_message ""
250 set commit_canceled 1
251 destroy .commitMessage
255 # Commit message input window
256 proc get_commit_message {} {
259 toplevel .commitMessage
260 frame .commitMessage.topFrame
261 label .commitMessage.topFrame.label \
262 -text "Enter commit message header:\n(50 chars max = width of box)"
263 entry .commitMessage.topFrame.commit_header \
264 -width 50 -relief solid -border 2 -textvariable commit_header
265 pack .commitMessage.topFrame.label -side left
266 pack .commitMessage.topFrame.commit_header -side left
268 frame .commitMessage.bottomFrame
269 text .commitMessage.bottomFrame.commit_body \
270 -width 75 -height 10 -relief solid -border 2 -wrap none
272 frame .commitMessage.bottomFrame.leftFrame
273 label .commitMessage.bottomFrame.leftFrame.label \
274 -text "Enter commit message body:\n(No limit -- Full description)"
275 button .commitMessage.bottomFrame.leftFrame.ok \
276 -text OK -default active -command commitMessageOK
277 button .commitMessage.bottomFrame.leftFrame.cancel -text Cancel -default active \
278 -command commitMessageCancel
279 wm withdraw .commitMessage
280 wm title .commitMessage "Git Commit Message"
282 pack .commitMessage.bottomFrame.leftFrame.label
283 pack .commitMessage.bottomFrame.leftFrame.ok
284 pack .commitMessage.bottomFrame.leftFrame.cancel
286 pack .commitMessage.bottomFrame.leftFrame -side left
287 pack .commitMessage.bottomFrame.commit_body -side left
289 pack .commitMessage.topFrame
290 pack .commitMessage.bottomFrame
292 wm transient .commitMessage .
293 wm deiconify .commitMessage
299 wm title . $windowTitle
304 button .buttons.commit -text "2. Make local commit" -command commit
305 button .buttons.update -text $updateButtonText \
306 -command update_lilypond_with_rebase
308 button .buttons.patch -text "3. Make patch set" \
309 -command patch_from_origin
310 button .buttons.panic -text "Abort changes -- Reset to origin" \
311 -command abort_changes -fg Blue -bg Red
312 label .buttons.spacer -text " "
313 if {![file exists $lily_dir]} {
314 .buttons.update configure \
315 -text $initializeButtonText
316 .buttons.commit configure -state disabled
317 .buttons.patch configure -state disabled
318 .buttons.panic configure -state disabled
323 pack .buttons.update -side left
324 pack .buttons.commit -side left
325 pack .buttons.patch -side left
326 pack .buttons.spacer -side left
327 pack .buttons.panic -side left
333 label .output.label -text "Command output:"
334 text .output.text -width 80 -height 15 \
335 -xscrollcommand [list .output.horizontal set] \
336 -yscrollcommand [list .output.vertical set] \
337 -relief solid -border 2
338 scrollbar .output.horizontal -orient h -command [list .output.text xview]
339 scrollbar .output.vertical -orient v -command [list .output.text yview]
340 pack .output.label -side left
341 pack .output.horizontal -side bottom -fill x
342 pack .output.vertical -side right -fill y
343 pack .output.text -expand true -anchor nw -fill both
348 #grid .buttons -row 2 -column 1
349 #grid .output -row 3 -column 1 -sticky "w"