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-git
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 "2
111 proc commit_amend {} {
112 git commit -a --amend -C HEAD
113 git rebase --whitespace=fix HEAD^
116 proc update_lilypond_norebase {} {
120 proc update_lilypond_with_rebase {} {
122 update_lilypond $rebase
125 proc update_lilypond {rebase} {
129 . config -cursor watch
130 if {![file exists $lily_dir]} {
131 write_to_output "Cloning LilyPond (this can take some time) ...\n"
135 git config core.bare false
136 git remote add -t $originHead \
137 origin git://git.sv.gnu.org/lilypond.git
138 if {$translator == 1} {
143 git reset --hard origin/$originHead
144 git config branch.$originHead.remote origin
145 git config branch.$originHead.merge refs/heads/$originHead
146 .buttons.commitFrame.commit configure -state normal
147 .buttons.commitFrame.amend configure -state normal
148 .buttons.update configure -text buttonUpdateText
149 .buttons.patch configure -state normal
150 .buttons.panic configure -state normal
153 write_to_output "Updating LilyPond...\n"
156 git rebase origin/$originHead
158 git merge origin/$originHead
161 write_to_output "Done.\n"
165 proc patch_from_origin {} {
167 make_patch_from_origin $rebase
168 if {![llength [glob -nocomplain 0*.patch]]} {
169 tk_messageBox -type ok -message \
170 "No patches created; did you make a local commit?"
174 proc make_patch_from_origin {rebase} {
177 . config -cursor watch
178 update_lilypond $rebase
179 write_to_output "Creating patch...\n"
180 git format-patch origin/$originHead
181 write_to_output "Done.\n"
185 proc abort_changes {} {
188 set answer [tk_messageBox -type okcancel \
189 -message "This will copy all changed files to $abort_dir and reset the repository." \
193 write_to_output "abort_dir: $abort_dir \n"
194 if {![file exists $abort_dir]} {
195 set return_code [exec mkdir $abort_dir]
197 set return_code [catch {exec git diff origin/$originHead} gitdiff]
198 set return_code [regexp {diff --git a/(\S*)} $gitdiff match modified_file]
199 while {$return_code != 0} {
200 write_to_output "Copying $modified_file to $abort_dir.\n"
201 set return_code [catch {exec cp $modified_file $abort_dir} result]
202 set return_code [regsub {diff --git a/(\S*)} $gitdiff "" gitdiff]
203 set return_code [regexp {diff --git a/(\S*)} $gitdiff match modified_file]
205 set return_code [git reset --hard origin/$originHead]
206 write_to_output "Repository reset. \n"
211 proc toggle_rebase {} {
215 global updateButtonText
216 global initializeButtonText
217 if {[file exists $lily_dir]} {
218 config --bool branch.$originHead.rebase $rebase
219 .buttons.update configure -text $updateButtonText
221 .buttons.update configure -text $initializeButtonText
225 proc clear_rebase {} {
237 proc commitMessageOK {} {
238 global commit_message
240 set commit_body [.commitMessage.bottomFrame.commit_body get 1.0 end]
241 set commit_message "$commit_header\n\n$commit_body"
242 destroy .commitMessage
245 proc commitMessageCancel {} {
246 global commit_message
247 global commit_canceled
248 set commit_message ""
249 set commit_canceled 1
250 destroy .commitMessage
254 # Commit message input window
255 proc get_commit_message {} {
258 toplevel .commitMessage
259 frame .commitMessage.topFrame
260 label .commitMessage.topFrame.label \
261 -text "Enter commit message header:\n(50 chars max = width of box)"
262 entry .commitMessage.topFrame.commit_header \
263 -width 50 -relief solid -border 2 -textvariable commit_header
264 pack .commitMessage.topFrame.label -side left
265 pack .commitMessage.topFrame.commit_header -side left
267 frame .commitMessage.bottomFrame
268 text .commitMessage.bottomFrame.commit_body \
269 -width 75 -height 10 -relief solid -border 2 -wrap none
271 frame .commitMessage.bottomFrame.leftFrame
272 label .commitMessage.bottomFrame.leftFrame.label \
273 -text "Enter commit message body:\n(No limit -- Full description)"
274 button .commitMessage.bottomFrame.leftFrame.ok \
275 -text OK -default active -command commitMessageOK
276 button .commitMessage.bottomFrame.leftFrame.cancel -text Cancel -default active \
277 -command commitMessageCancel
278 wm withdraw .commitMessage
279 wm title .commitMessage "Git Commit Message"
281 pack .commitMessage.bottomFrame.leftFrame.label
282 pack .commitMessage.bottomFrame.leftFrame.ok
283 pack .commitMessage.bottomFrame.leftFrame.cancel
285 pack .commitMessage.bottomFrame.leftFrame -side left
286 pack .commitMessage.bottomFrame.commit_body -side left
288 pack .commitMessage.topFrame
289 pack .commitMessage.bottomFrame
291 wm transient .commitMessage .
292 wm deiconify .commitMessage
298 wm title . $windowTitle
304 frame .buttons.commitFrame
305 button .buttons.commitFrame.commit -text "2a. New local commit" -command commit
306 button .buttons.commitFrame.amend -text "2b. Amend previous commit" -command commit_amend
307 pack .buttons.commitFrame.commit -fill x
308 pack .buttons.commitFrame.amend -fill x
310 button .buttons.update -text $updateButtonText \
311 -command update_lilypond_with_rebase
312 button .buttons.patch -text "3. Make patch set" \
313 -command patch_from_origin
315 button .buttons.panic -text "Abort changes -- Reset to origin" \
316 -command abort_changes -fg Blue -bg Red
317 label .buttons.spacer -text " "
318 if {![file exists $lily_dir]} {
319 .buttons.update configure \
320 -text $initializeButtonText
321 .buttons.commitFrame.commit configure -state disabled
322 .buttons.commitFrame.amend configure -state disabled
323 .buttons.patch configure -state disabled
324 .buttons.panic configure -state disabled
329 pack .buttons.update -side left
330 pack .buttons.commitFrame -side left
331 pack .buttons.patch -side left
332 pack .buttons.spacer -side left
333 pack .buttons.panic -side right
339 label .output.label -text "Command output:"
340 text .output.text -width 80 -height 15 \
341 -xscrollcommand [list .output.horizontal set] \
342 -yscrollcommand [list .output.vertical set] \
343 -relief solid -border 2
344 scrollbar .output.horizontal -orient h -command [list .output.text xview]
345 scrollbar .output.vertical -orient v -command [list .output.text yview]
346 pack .output.label -side left
347 pack .output.horizontal -side bottom -fill x
348 pack .output.vertical -side right -fill y
349 pack .output.text -expand true -anchor nw -fill both
354 #grid .buttons -row 2 -column 1
355 #grid .output -row 3 -column 1 -sticky "w"