+proc commit_commitmsg {curHEAD msg_p} {
+ global pch_error
+
+ # -- Run the commit-msg hook.
+ #
+ set pchook [gitdir hooks commit-msg]
+
+ # On Cygwin [file executable] might lie so we need to ask
+ # the shell if the hook is executable. Yes that's annoying.
+ #
+ if {[is_Cygwin] && [file isfile $pchook]} {
+ set pchook [list sh -c [concat \
+ "if test -x \"$pchook\";" \
+ "then exec \"$pchook\" \"$msg_p\" 2>&1;" \
+ "fi"]]
+ } elseif {[file executable $pchook]} {
+ set pchook [list $pchook $msg_p |& cat]
+ } else {
+ commit_writetree $curHEAD $msg_p
+ return
+ }
+
+ ui_status {Calling commit-msg hook...}
+ set pch_error {}
+ set fd_ph [open "| $pchook" r]
+ fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
+ fileevent $fd_ph readable \
+ [list commit_commitmsg_wait $fd_ph $curHEAD $msg_p]
+}
+
+proc commit_commitmsg_wait {fd_ph curHEAD msg_p} {
+ global pch_error
+
+ append pch_error [read $fd_ph]
+ fconfigure $fd_ph -blocking 1
+ if {[eof $fd_ph]} {
+ if {[catch {close $fd_ph}]} {
+ catch {file delete $msg_p}
+ ui_status {Commit declined by commit-msg hook.}
+ hook_failed_popup commit-msg $pch_error
+ unlock_index
+ } else {
+ commit_writetree $curHEAD $msg_p
+ }
+ set pch_error {}
+ return
+ }
+ fconfigure $fd_ph -blocking 0
+}
+
+proc commit_writetree {curHEAD msg_p} {