212
213
# -- Run the pre-commit hook.
214
#
215
- set pchook [gitdir hooks pre-commit]
216
-
217
- # On Cygwin [file executable] might lie so we need to ask
218
- # the shell if the hook is executable. Yes that's annoying.
219
- #
220
- if {[is_Cygwin] && [file isfile $pchook]} {
221
- set pchook [list sh -c [concat \
222
- "if test -x \"$pchook\";" \
223
- "then exec \"$pchook\" 2>&1;" \
224
- "fi"]]
225
- } elseif {[file executable $pchook]} {
226
- set pchook [list $pchook |& cat]
227
- } else {
215
+ set fd_ph [githook_read pre-commit]
216
+ if {$fd_ph eq {}} {
217
commit_commitmsg $curHEAD $msg_p
218
return
219
}
220
221
ui_status {Calling pre-commit hook...}
222
set pch_error {}
234
- set fd_ph [open "| $pchook" r]
223
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
224
fileevent $fd_ph readable \
225
[list commit_prehook_wait $fd_ph $curHEAD $msg_p]
250
251
# -- Run the commit-msg hook.
252
#
265
- set pchook [gitdir hooks commit-msg]
266
-
267
- # On Cygwin [file executable] might lie so we need to ask
268
- # the shell if the hook is executable. Yes that's annoying.
269
- #
270
- if {[is_Cygwin] && [file isfile $pchook]} {
271
- set pchook [list sh -c [concat \
272
- "if test -x \"$pchook\";" \
273
- "then exec \"$pchook\" \"$msg_p\" 2>&1;" \
274
- "fi"]]
275
- } elseif {[file executable $pchook]} {
276
- set pchook [list $pchook $msg_p |& cat]
277
- } else {
253
+ set fd_ph [githook_read commit-msg $msg_p]
254
+ if {$fd_ph eq {}} {
255
commit_writetree $curHEAD $msg_p
256
return
257
}
258
259
ui_status {Calling commit-msg hook...}
260
set pch_error {}
284
- set fd_ph [open "| $pchook" r]
261
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
262
fileevent $fd_ph readable \
263
[list commit_commitmsg_wait $fd_ph $curHEAD $msg_p]
391
392
# -- Run the post-commit hook.
393
#
418
- set pchook [gitdir hooks post-commit]
419
- if {[is_Cygwin] && [file isfile $pchook]} {
420
- set pchook [list sh -c [concat \
421
- "if test -x \"$pchook\";" \
422
- "then exec \"$pchook\";" \
423
- "fi"]]
424
- } elseif {![file executable $pchook]} {
425
- set pchook {}
426
- }
427
- if {$pchook ne {}} {
428
- catch {exec $pchook &}
394
+ set fd_ph [githook_read post-commit]
395
+ if {$fd_ph ne {}} {
396
+ upvar #0 pch_error$cmt_id pc_err
397
+ set pc_err {}
398
+ fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
399
+ fileevent $fd_ph readable \
400
+ [list commit_postcommit_wait $fd_ph $cmt_id]
401
}
402
403
$ui_comm delete 0.0 end
453
reshow_diff
454
ui_status [mc "Created commit %s: %s" [string range $cmt_id 0 7] $subject]
455
}
456
+
457
+proc commit_postcommit_wait {fd_ph cmt_id} {
458
+ upvar #0 pch_error$cmt_id pch_error
459
+
460
+ append pch_error [read $fd_ph]
461
+ fconfigure $fd_ph -blocking 1
462
+ if {[eof $fd_ph]} {
463
+ if {[catch {close $fd_ph}]} {
464
+ hook_failed_popup post-commit $pch_error 0
465
+ }
466
+ unset pch_error
467
+ return
468
+ }
469
+ fconfigure $fd_ph -blocking 0
470
+}