{"thread":{"id":"15556","subject":"[GIT-GUI PATCH] call prepare-commit-msg hook","startedAt":"2008-09-16T21:12:36Z","lastAt":"2008-09-24T19:46:22Z","messageCount":5,"participants":["Joshua Williams","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"90864","messageId":"48D02144.8030409@qlogic.com","threadId":"15556","inReplyTo":null,"subject":"[GIT-GUI PATCH] call prepare-commit-msg hook","fromName":"Joshua Williams","fromEmail":"joshua.williams@qlogic.com","sentAt":"2008-09-16T21:12:36Z","receivedAt":"2008-09-16T21:12:36Z","isPatch":true,"sender":{"key":"joshua.williams@qlogic.com","avatar":null},"body":"This patch adds support to git-gui for calling out to the\nprepare-commit-msg hook.\n\nSigned-off-by: Joshua Williams <joshua.williams@qlogic.com>\n---\n  git-gui/git-gui.sh |   66 \n++++++++++++++++++++++++++++++++++++++++++++++++++-\n  1 files changed, 64 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 10d8a44..1e269de 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1131,8 +1131,7 @@ proc rescan {after {honor_trustmtime 1}} {\n  \t\t|| [string trim [$ui_comm get 0.0 end]] eq {})} {\n  \t\tif {[string match amend* $commit_type]} {\n  \t\t} elseif {[load_message GITGUI_MSG]} {\n-\t\t} elseif {[load_message MERGE_MSG]} {\n-\t\t} elseif {[load_message SQUASH_MSG]} {\n+\t\t} elseif {[run_prepare_commit_msg_hook]} {\n  \t\t}\n  \t\t$ui_comm edit reset\n  \t\t$ui_comm edit modified false\n@@ -1230,6 +1229,69 @@ proc load_message {file} {\n  \treturn 0\n  }\n\n+proc run_prepare_commit_msg_hook {} {\n+\tglobal pch_error\n+\n+\t# prepare-commit-msg requires PREPARE_COMMIT_MSG exist.  From git-gui\n+\t# it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an\n+\t# empty file but existant file.\n+\n+\tset fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]\n+\n+\tif {[file isfile [gitdir MERGE_MSG]]} {\n+\t\tset pcm_source \"merge\"\n+\t\tset fd_mm [open [gitdir MERGE_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_mm]\n+\t\tclose $fd_mm\n+\t} elseif {[file isfile [gitdir SQUASH_MSG]]} {\n+\t\tset pcm_source \"squash\"\n+\t\tset fd_sm [open [gitdir SQUASH_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_sm]\n+\t\tclose $fd_sm\n+\t} else {\n+\t\tset pcm_source \"\"\n+\t}\n+\n+\tclose $fd_pcm\n+\n+\tset fd_ph [githook_read prepare-commit-msg \\\n+\t\t\t[gitdir PREPARE_COMMIT_MSG] $pcm_source]\n+\tif {$fd_ph eq {}} {\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn 0;\n+\t}\n+\n+\tui_status [mc \"Calling prepare-commit-msg hook...\"]\n+\tset pch_error {}\n+\n+\tfconfigure $fd_ph -blocking 0 -translation binary -eofchar {}\n+\tfileevent $fd_ph readable \\\n+\t\t[list prepare_commit_msg_hook_wait $fd_ph]\n+\n+\treturn 1;\n+}\n+\n+proc prepare_commit_msg_hook_wait {fd_ph} {\n+\tglobal pch_error\n+\n+\tappend pch_error [read $fd_ph]\n+\tfconfigure $fd_ph -blocking 1\n+\tif {[eof $fd_ph]} {\n+\t\tif {[catch {close $fd_ph}]} {\n+\t\t\tui_status [mc \"Commit declined by prepare-commit-msg hook.\"]\n+\t\t\thook_failed_popup prepare-commit-msg $pch_error\n+\t\t\texit 1\n+\t\t} else {\n+\t\t\tload_message PREPARE_COMMIT_MSG\n+\t\t}\n+\t\tset pch_error {}\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn\n+        }\n+\tfconfigure $fd_ph -blocking 0\n+\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+}\n+\n  proc read_diff_index {fd after} {\n  \tglobal buf_rdi\n"},{"id":"90867","messageId":"48D02D99.9090102@qlogic.com","threadId":"15556","inReplyTo":"48D02144.8030409@qlogic.com","subject":"Re: [GIT-GUI PATCH] call prepare-commit-msg hook","fromName":"Joshua Williams","fromEmail":"joshua.williams@qlogic.com","sentAt":"2008-09-16T22:05:13Z","receivedAt":"2008-09-16T22:05:13Z","isPatch":true,"sender":{"key":"joshua.williams@qlogic.com","avatar":null},"body":"Small change.  Still need to load MERGE_MSG and SQUASH_MSG\nif there's no prepare-commit-msg hook.  We now process the hook\nfirst and if it's not there, load MERGE_MSG or SQUASH_MSG.\n\nSigned-off-by: Joshua Williams <joshua.williams@qlogic.com>\n---\n  git-gui/git-gui.sh |   64 \n++++++++++++++++++++++++++++++++++++++++++++++++++++\n  1 files changed, 64 insertions(+), 0 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 10d8a44..8d06cd1 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1131,6 +1131,7 @@ proc rescan {after {honor_trustmtime 1}} {\n  \t\t|| [string trim [$ui_comm get 0.0 end]] eq {})} {\n  \t\tif {[string match amend* $commit_type]} {\n  \t\t} elseif {[load_message GITGUI_MSG]} {\n+\t\t} elseif {[run_prepare_commit_msg_hook]} {\n  \t\t} elseif {[load_message MERGE_MSG]} {\n  \t\t} elseif {[load_message SQUASH_MSG]} {\n  \t\t}\n@@ -1230,6 +1231,69 @@ proc load_message {file} {\n  \treturn 0\n  }\n\n+proc run_prepare_commit_msg_hook {} {\n+\tglobal pch_error\n+\n+\t# prepare-commit-msg requires PREPARE_COMMIT_MSG exist.  From git-gui\n+\t# it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an\n+\t# empty file but existant file.\n+\n+\tset fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]\n+\n+\tif {[file isfile [gitdir MERGE_MSG]]} {\n+\t\tset pcm_source \"merge\"\n+\t\tset fd_mm [open [gitdir MERGE_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_mm]\n+\t\tclose $fd_mm\n+\t} elseif {[file isfile [gitdir SQUASH_MSG]]} {\n+\t\tset pcm_source \"squash\"\n+\t\tset fd_sm [open [gitdir SQUASH_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_sm]\n+\t\tclose $fd_sm\n+\t} else {\n+\t\tset pcm_source \"\"\n+\t}\n+\n+\tclose $fd_pcm\n+\n+\tset fd_ph [githook_read prepare-commit-msg \\\n+\t\t\t[gitdir PREPARE_COMMIT_MSG] $pcm_source]\n+\tif {$fd_ph eq {}} {\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn 0;\n+\t}\n+\n+\tui_status [mc \"Calling prepare-commit-msg hook...\"]\n+\tset pch_error {}\n+\n+\tfconfigure $fd_ph -blocking 0 -translation binary -eofchar {}\n+\tfileevent $fd_ph readable \\\n+\t\t[list prepare_commit_msg_hook_wait $fd_ph]\n+\n+\treturn 1;\n+}\n+\n+proc prepare_commit_msg_hook_wait {fd_ph} {\n+\tglobal pch_error\n+\n+\tappend pch_error [read $fd_ph]\n+\tfconfigure $fd_ph -blocking 1\n+\tif {[eof $fd_ph]} {\n+\t\tif {[catch {close $fd_ph}]} {\n+\t\t\tui_status [mc \"Commit declined by prepare-commit-msg hook.\"]\n+\t\t\thook_failed_popup prepare-commit-msg $pch_error\n+\t\t\texit 1\n+\t\t} else {\n+\t\t\tload_message PREPARE_COMMIT_MSG\n+\t\t}\n+\t\tset pch_error {}\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn\n+        }\n+\tfconfigure $fd_ph -blocking 0\n+\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+}\n+\n  proc read_diff_index {fd after} {\n  \tglobal buf_rdi\n"},{"id":"91495","messageId":"20080924170434.GW3669@spearce.org","threadId":"15556","inReplyTo":"48D02D99.9090102@qlogic.com","subject":"Re: [GIT-GUI PATCH] call prepare-commit-msg hook","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-24T17:04:34Z","receivedAt":"2008-09-24T17:04:34Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Joshua Williams <joshua.williams@qlogic.com> wrote:\n> Small change.  Still need to load MERGE_MSG and SQUASH_MSG\n> if there's no prepare-commit-msg hook.  We now process the hook\n> first and if it's not there, load MERGE_MSG or SQUASH_MSG.\n>\n> Signed-off-by: Joshua Williams <joshua.williams@qlogic.com>\n\nThis patch looks reasonable.  My only comment is maybe we want\nto delete PREPARE_COMMIT_MSG file when we \"exit 1\" when the hook\nhas declined.\n\n> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\n> index 10d8a44..8d06cd1 100755\n> --- a/git-gui/git-gui.sh\n> +++ b/git-gui/git-gui.sh\n\nCan you please try to put this onto my current git-gui tree?\nI don't have the base 10d8a44 object so I can't 3-way merge\nthis in, and the patch doesn't apply cleanly anymore.\n\n-- \nShawn.\n"},{"id":"91513","messageId":"48DA90F9.8070606@qlogic.com","threadId":"15556","inReplyTo":"20080924170434.GW3669@spearce.org","subject":"Re: [GIT-GUI PATCH] call prepare-commit-msg hook","fromName":"Joshua Williams","fromEmail":"joshua.williams@qlogic.com","sentAt":"2008-09-24T19:11:53Z","receivedAt":"2008-09-24T19:11:53Z","isPatch":true,"sender":{"key":"joshua.williams@qlogic.com","avatar":null},"body":"Shawn O. Pearce wrote:\n> Joshua Williams <joshua.williams@qlogic.com> wrote:\n>> Small change.  Still need to load MERGE_MSG and SQUASH_MSG\n>> if there's no prepare-commit-msg hook.  We now process the hook\n>> first and if it's not there, load MERGE_MSG or SQUASH_MSG.\n>>\n>> Signed-off-by: Joshua Williams <joshua.williams@qlogic.com>\n> \n> This patch looks reasonable.  My only comment is maybe we want\n> to delete PREPARE_COMMIT_MSG file when we \"exit 1\" when the hook\n> has declined.\n\nGood catch.  I've added that to the latest patch.\n\n>> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\n>> index 10d8a44..8d06cd1 100755\n>> --- a/git-gui/git-gui.sh\n>> +++ b/git-gui/git-gui.sh\n> \n> Can you please try to put this onto my current git-gui tree?\n> I don't have the base 10d8a44 object so I can't 3-way merge\n> this in, and the patch doesn't apply cleanly anymore.\n\nAbsolutely.  Here it is:\n\nAdd support to git-gui for calling out to the prepare-commit-msg hook.\nSigned-off-by: Joshua Williams <joshua.williams@qlogic.com>\n---\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 1939001..cb0fcac 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -1170,6 +1170,7 @@ proc rescan {after {honor_trustmtime 1}} {\n  \t\t|| [string trim [$ui_comm get 0.0 end]] eq {})} {\n  \t\tif {[string match amend* $commit_type]} {\n  \t\t} elseif {[load_message GITGUI_MSG]} {\n+\t\t} elseif {[run_prepare_commit_msg_hook]} {\n  \t\t} elseif {[load_message MERGE_MSG]} {\n  \t\t} elseif {[load_message SQUASH_MSG]} {\n  \t\t}\n@@ -1269,6 +1270,70 @@ proc load_message {file} {\n  \treturn 0\n  }\n\n+proc run_prepare_commit_msg_hook {} {\n+\tglobal pch_error\n+\n+\t# prepare-commit-msg requires PREPARE_COMMIT_MSG exist.  From git-gui\n+\t# it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an\n+\t# empty file but existant file.\n+\n+\tset fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]\n+\n+\tif {[file isfile [gitdir MERGE_MSG]]} {\n+\t\tset pcm_source \"merge\"\n+\t\tset fd_mm [open [gitdir MERGE_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_mm]\n+\t\tclose $fd_mm\n+\t} elseif {[file isfile [gitdir SQUASH_MSG]]} {\n+\t\tset pcm_source \"squash\"\n+\t\tset fd_sm [open [gitdir SQUASH_MSG] r]\n+\t\tputs -nonewline $fd_pcm [read $fd_sm]\n+\t\tclose $fd_sm\n+\t} else {\n+\t\tset pcm_source \"\"\n+\t}\n+\n+\tclose $fd_pcm\n+\n+\tset fd_ph [githook_read prepare-commit-msg \\\n+\t\t\t[gitdir PREPARE_COMMIT_MSG] $pcm_source]\n+\tif {$fd_ph eq {}} {\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn 0;\n+\t}\n+\n+\tui_status [mc \"Calling prepare-commit-msg hook...\"]\n+\tset pch_error {}\n+\n+\tfconfigure $fd_ph -blocking 0 -translation binary -eofchar {}\n+\tfileevent $fd_ph readable \\\n+\t\t[list prepare_commit_msg_hook_wait $fd_ph]\n+\n+\treturn 1;\n+}\n+\n+proc prepare_commit_msg_hook_wait {fd_ph} {\n+\tglobal pch_error\n+\n+\tappend pch_error [read $fd_ph]\n+\tfconfigure $fd_ph -blocking 1\n+\tif {[eof $fd_ph]} {\n+\t\tif {[catch {close $fd_ph}]} {\n+\t\t\tui_status [mc \"Commit declined by prepare-commit-msg hook.\"]\n+\t\t\thook_failed_popup prepare-commit-msg $pch_error\n+\t\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\t\texit 1\n+\t\t} else {\n+\t\t\tload_message PREPARE_COMMIT_MSG\n+\t\t}\n+\t\tset pch_error {}\n+\t\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+\t\treturn\n+        }\n+\tfconfigure $fd_ph -blocking 0\n+\tcatch {file delete [gitdir PREPARE_COMMIT_MSG]}\n+}\n+\n  proc read_diff_index {fd after} {\n  \tglobal buf_rdi\n"},{"id":"91514","messageId":"20080924194622.GF3669@spearce.org","threadId":"15556","inReplyTo":"48DA90F9.8070606@qlogic.com","subject":"Re: [GIT-GUI PATCH] call prepare-commit-msg hook","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-24T19:46:22Z","receivedAt":"2008-09-24T19:46:22Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Joshua Williams <joshua.williams@qlogic.com> wrote:\n>>\n>> Can you please try to put this onto my current git-gui tree?\n>> I don't have the base 10d8a44 object so I can't 3-way merge\n>> this in, and the patch doesn't apply cleanly anymore.\n>\n> Absolutely.  Here it is:\n\nI'm not sure what happened, but any line of context got an extra\nspace inserted at the front of it.  I had to go rip out the extra\nspaces from every line of context to get git-apply to process the\npatch.\n\nAnyway, its applied now.  Thanks.\n\n-- \nShawn.\n"}]}