{"thread":{"id":"24039","subject":"[PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","startedAt":"2010-06-08T02:56:02Z","lastAt":"2010-06-22T01:07:57Z","messageCount":6,"participants":["Mark Levedahl","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"143203","messageId":"1275965763-18940-1-git-send-email-mlevedahl@gmail.com","threadId":"24039","inReplyTo":null,"subject":"[PATCH 1/2 v2] commit.c - provide base commit to the hooks/pre-commit script","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2010-06-08T02:56:02Z","receivedAt":"2010-06-08T02:56:02Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"If hooks/pre-commit acts based upon the changes to be checked in\nrather than just the resulting content, the script needs to know which\ncommit to use. For a normal commit, this is HEAD, but when amending this\nis HEAD~1. So, this modifies commit.c to pass $1 as HEAD|HEAD~1 depending\nupon the commit type. Existing scripts are unaffected as they did not\nexpect any argument so will silently ignore this extra bit of info.\n\nSigned-off-by: Mark Levedahl <mlevedahl@gmail.com>\n---\n Documentation/githooks.txt         |   10 ++++++----\n builtin/commit.c                   |    2 +-\n templates/hooks--pre-commit.sample |    9 +++++----\n 3 files changed, 12 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\nindex 7183aa9..d785b6c 100644\n--- a/Documentation/githooks.txt\n+++ b/Documentation/githooks.txt\n@@ -73,10 +73,12 @@ pre-commit\n ~~~~~~~~~~\n \n This hook is invoked by 'git commit', and can be bypassed\n-with `\\--no-verify` option.  It takes no parameter, and is\n-invoked before obtaining the proposed commit log message and\n-making a commit.  Exiting with non-zero status from this script\n-causes the 'git commit' to abort.\n+with `\\--no-verify` option.  It takes a single parameter naming\n+the current commit's parent (HEAD | HEAD~1), and is invoked before\n+obtaining the proposed commit log message and making a commit.\n+Note that $1=HEAD~1 indicates an amended commit is in process.\n+Exiting with non-zero status from this script causes the 'git\n+commit' to abort.\n \n The default 'pre-commit' hook, when enabled, catches introduction\n of lines with trailing whitespaces and aborts the commit when\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex ddf77e4..49f799e 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -544,7 +544,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tconst char *hook_arg2 = NULL;\n \tint ident_shown = 0;\n \n-\tif (!no_verify && run_hook(index_file, \"pre-commit\", NULL))\n+\tif (!no_verify && run_hook(index_file, \"pre-commit\", amend ? \"HEAD~1\" : \"HEAD\", NULL))\n \t\treturn 0;\n \n \tif (message.len) {\ndiff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\nindex b187c4b..e72cf9c 100755\n--- a/templates/hooks--pre-commit.sample\n+++ b/templates/hooks--pre-commit.sample\n@@ -1,15 +1,16 @@\n #!/bin/sh\n #\n # An example hook script to verify what is about to be committed.\n-# Called by \"git commit\" with no arguments.  The hook should\n-# exit with non-zero status after issuing an appropriate message if\n-# it wants to stop the commit.\n+# Called by \"git commit\" with a single argument indicating the\n+# commit-base (HEAD|HEAD~1).  The hook should exit with non-zero\n+# status after issuing an appropriate message if it wants to stop\n+# the commit.\n #\n # To enable this hook, rename this file to \"pre-commit\".\n \n if git rev-parse --verify HEAD >/dev/null 2>&1\n then\n-\tagainst=HEAD\n+\tagainst=$1\n else\n \t# Initial commit: diff against an empty tree object\n \tagainst=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n-- \n1.7.1.269.g9fb6\n"},{"id":"143202","messageId":"1275965763-18940-2-git-send-email-mlevedahl@gmail.com","threadId":"24039","inReplyTo":"1275965763-18940-1-git-send-email-mlevedahl@gmail.com","subject":"[PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2010-06-08T02:56:03Z","receivedAt":"2010-06-08T02:56:03Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"If hooks/pre-commit acts based upon the changes to be checked in\nrather than just the resulting content, the script needs to know which\ncommit to use. For a normal commit, this is HEAD, but when amending this\nis HEAD~1. So, this modifies commit.tcl to pass $1 as HEAD|HEAD~1 depending\nupon the commit type. Existing scripts are unaffected as they did not\nexpect any argument so will silently ignore this extra bit of info.\n\nSigned-off-by: Mark Levedahl <mlevedahl@gmail.com>\n---\n git-gui/lib/commit.tcl |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl\nindex 7f459cd..a62edc9 100644\n--- a/git-gui/lib/commit.tcl\n+++ b/git-gui/lib/commit.tcl\n@@ -225,7 +225,13 @@ A good commit message has the following format:\n \n \t# -- Run the pre-commit hook.\n \t#\n-\tset fd_ph [githook_read pre-commit]\n+\tif {[string compare $commit_type \"normal\"] == 0} {\n+\t\tset against \"HEAD\"\n+\t} else {\n+\t\tset against \"HEAD~1\"\n+\t}\n+\n+\tset fd_ph [githook_read pre-commit $against]\n \tif {$fd_ph eq {}} {\n \t\tcommit_commitmsg $curHEAD $msg_p\n \t\treturn\n-- \n1.7.1.269.g9fb6\n"},{"id":"143932","messageId":"4C1C3288.5000308@gmail.com","threadId":"24039","inReplyTo":"1275965763-18940-2-git-send-email-mlevedahl@gmail.com","subject":"Re: [PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2010-06-19T02:59:20Z","receivedAt":"2010-06-19T02:59:20Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"On 06/07/2010 10:56 PM, Mark Levedahl wrote:\n> If hooks/pre-commit acts based upon the changes to be checked in\n> rather than just the resulting content, the script needs to know which\n> commit to use. For a normal commit, this is HEAD, but when amending this\n> is HEAD~1. So, this modifies commit.tcl to pass $1 as HEAD|HEAD~1 depending\n> upon the commit type. Existing scripts are unaffected as they did not\n> expect any argument so will silently ignore this extra bit of info.\n>\n> Signed-off-by: Mark Levedahl<mlevedahl@gmail.com>\n>    \nGiven the discussion on the first series  (starting \nwith)<1275759590-16342-1-git-send-email-mlevedahl@gmail.com>, and the \nabsence of objection to v2, I presume this sequence is ok?\n\nMark\n"},{"id":"143972","messageId":"7vvd9drnn4.fsf@alter.siamese.dyndns.org","threadId":"24039","inReplyTo":"4C1C3288.5000308@gmail.com","subject":"Re: [PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-21T04:54:39Z","receivedAt":"2010-06-21T04:54:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Levedahl <mlevedahl@gmail.com> writes:\n\n> Given the discussion on the first series (starting with)\n> <1275759590-16342-1-git-send-email-mlevedahl@gmail.com>, and the absence\n> of objection to v2, I presume this sequence is ok?\n\nI generally take absense of responses as absense of interest and/or\nsupport, not absense of objection.\n\nFor this particular patch, I am mostly indifferent (i.e. no objection, but\nno strong support neither).\n"},{"id":"143973","messageId":"20100621050012.GA13043@coredump.intra.peff.net","threadId":"24039","inReplyTo":"7vvd9drnn4.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-06-21T05:00:12Z","receivedAt":"2010-06-21T05:00:12Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jun 20, 2010 at 09:54:39PM -0700, Junio C Hamano wrote:\n\n> Mark Levedahl <mlevedahl@gmail.com> writes:\n> \n> > Given the discussion on the first series (starting with)\n> > <1275759590-16342-1-git-send-email-mlevedahl@gmail.com>, and the absence\n> > of objection to v2, I presume this sequence is ok?\n> \n> I generally take absense of responses as absense of interest and/or\n> support, not absense of objection.\n> \n> For this particular patch, I am mostly indifferent (i.e. no objection, but\n> no strong support neither).\n\nDitto. I don't personally have a use, but all of my concerns were\nanswered.\n\n-Peff\n"},{"id":"144021","messageId":"4C200CED.7090402@gmail.com","threadId":"24039","inReplyTo":"20100621050012.GA13043@coredump.intra.peff.net","subject":"Re: [PATCH 2/2 v2] git-gui - provide commit base to the hooks/pre-commit script","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2010-06-22T01:07:57Z","receivedAt":"2010-06-22T01:07:57Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"On 06/21/2010 01:00 AM, Jeff King wrote:\n> On Sun, Jun 20, 2010 at 09:54:39PM -0700, Junio C Hamano wrote:\n>\n>    \n>> I generally take absense of responses as absense of interest and/or\n>> support, not absense of objection.\n>>\n>> For this particular patch, I am mostly indifferent (i.e. no objection, but\n>> no strong support neither).\n>>      \n> Ditto. I don't personally have a use, but all of my concerns were\n> answered.\n>\n> -Peff\n>    \nWell, I have a use else I wouldn't have written this :^).\n\nAbsent this patch, the default commit hook is always computing a diff \nagainst HEAD and that is wrong when amending a commit. Folks may not \ncare, but that is an error so this patch fixes an existing bug. I'll \nleave it at that.\n\nMark\n"}]}