git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
@ 2006-11-29 11:20 Johannes Schindelin
  2006-12-20 15:54 ` Andy Parkins
  2006-12-20 16:04 ` Andy Parkins
  0 siblings, 2 replies; 11+ messages in thread
From: Johannes Schindelin @ 2006-11-29 11:20 UTC (permalink / raw)
  To: Andy Parkins, git, junkio


It is good to have an example of how to supply a template for the
commit message anyway.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 templates/hooks--pre-commit |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit
index 723a9ef..931f127 100644
--- a/templates/hooks--pre-commit
+++ b/templates/hooks--pre-commit
@@ -7,6 +7,13 @@
 #
 # To enable this hook, make this file executable.
 
+# Uncomment this to add a Signed-off-by line to the message.
+
+# . git-sh-setup
+# git var GIT_AUTHOR_IDENT | \
+# sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p" \
+# > $GIT_DIR/SQUASH_MSG
+
 # This is slightly modified from Andrew Morton's Perfect Patch.
 # Lines you introduce should not have trailing whitespace.
 # Also check for an indentation that has SP before a TAB.
-- 
1.4.4.1.gb475

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-11-29 11:20 [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message Johannes Schindelin
@ 2006-12-20 15:54 ` Andy Parkins
  2006-12-20 16:04 ` Andy Parkins
  1 sibling, 0 replies; 11+ messages in thread
From: Andy Parkins @ 2006-12-20 15:54 UTC (permalink / raw)
  To: git

On Wednesday 2006 November 29 11:20, Johannes Schindelin wrote:

> +# . git-sh-setup
> +# git var GIT_AUTHOR_IDENT | \
> +# sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p" \
> +# > $GIT_DIR/SQUASH_MSG

I've been using this; and very useful it is too.  However, I just noticed that 
I was getting "Not a git repository" errors when I tried to commit in a 
subdirectory.  I traced the problem to my use of this fragment.  It seems 
that calling git-sh-setup inside the pre-commit hook was changing GIT_DIR 
(don't know why).  When I changed this to

git var GIT_AUTHOR_IDENT | \
sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p" \
 >> $(git-rev-parse --git-dir)/SQUASH_MSG

It worked correctly again.


Andy


-- 
Dr Andy Parkins, M Eng (hons), MIEE

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-11-29 11:20 [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message Johannes Schindelin
  2006-12-20 15:54 ` Andy Parkins
@ 2006-12-20 16:04 ` Andy Parkins
  2006-12-20 16:18   ` Johannes Schindelin
  1 sibling, 1 reply; 11+ messages in thread
From: Andy Parkins @ 2006-12-20 16:04 UTC (permalink / raw)
  To: git

Based on Johannes Schindelin's earlier patch to perform the same
function.

The call to git-sh-setup was causing "Not a git repository" errors after
the pre-commit script had run.  I removed the call and used
$(git-rev-parse --git-dir) instead, which seems to have fixed the
problem.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 templates/hooks--pre-commit |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit
index 723a9ef..87d9ccc 100644
--- a/templates/hooks--pre-commit
+++ b/templates/hooks--pre-commit
@@ -7,6 +7,11 @@
 #
 # To enable this hook, make this file executable.
 
+# Uncomment the below to add a Signed-off-by line to the message.
+#git var GIT_AUTHOR_IDENT | \
+#sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p" \
+# >> $(git-rev-parse --git-dir)/SQUASH_MSG
+
 # This is slightly modified from Andrew Morton's Perfect Patch.
 # Lines you introduce should not have trailing whitespace.
 # Also check for an indentation that has SP before a TAB.
-- 
1.4.4.2.g120e3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-12-20 16:04 ` Andy Parkins
@ 2006-12-20 16:18   ` Johannes Schindelin
  2006-12-20 17:29     ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-20 16:18 UTC (permalink / raw)
  To: Andy Parkins; +Cc: git

Hi,

On Wed, 20 Dec 2006, Andy Parkins wrote:

> Signed-off-by: Andy Parkins <andyparkins@gmail.com>

Acked-by: Johannes E. Schindelin <johannes.schindelin@gmx.de>

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-12-20 16:18   ` Johannes Schindelin
@ 2006-12-20 17:29     ` Junio C Hamano
  2006-12-20 17:37       ` Johannes Schindelin
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2006-12-20 17:29 UTC (permalink / raw)
  To: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi,
>
> On Wed, 20 Dec 2006, Andy Parkins wrote:
>
>> Signed-off-by: Andy Parkins <andyparkins@gmail.com>
>
> Acked-by: Johannes E. Schindelin <johannes.schindelin@gmx.de>
>
> Ciao,
> Dscho

Why SQUASH_MSG?  Doesn't it confuse git-explain when it wants to
detect that you are in the middle of a squash merge?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-12-20 17:29     ` Junio C Hamano
@ 2006-12-20 17:37       ` Johannes Schindelin
  2006-12-20 17:44         ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-20 17:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Wed, 20 Dec 2006, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > Hi,
> >
> > On Wed, 20 Dec 2006, Andy Parkins wrote:
> >
> >> Signed-off-by: Andy Parkins <andyparkins@gmail.com>
> >
> > Acked-by: Johannes E. Schindelin <johannes.schindelin@gmx.de>
> >
> > Ciao,
> > Dscho
> 
> Why SQUASH_MSG?  Doesn't it confuse git-explain when it wants to
> detect that you are in the middle of a squash merge?

Yes, it confuses git-explain. Which did not existed when I concocted the 
first (broken) version of this patch. There are only two ways to give 
commit message templates AFAICT: misusing SQUASH_MSG and misusing 
MERGE_MSG.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-12-20 17:37       ` Johannes Schindelin
@ 2006-12-20 17:44         ` Junio C Hamano
  2006-12-21  8:26           ` Johannes Schindelin
  2006-12-21  9:24           ` [PATCH] hooks/commit-msg: " Andy Parkins
  0 siblings, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2006-12-20 17:44 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> Why SQUASH_MSG?  Doesn't it confuse git-explain when it wants to
>> detect that you are in the middle of a squash merge?
>
> Yes, it confuses git-explain. Which did not existed when I concocted the 
> first (broken) version of this patch. There are only two ways to give 
> commit message templates AFAICT: misusing SQUASH_MSG and misusing 
> MERGE_MSG.

I wonder...

# An example hook script to check the commit log message.
# Called by git-commit with one argument, the name of the file
# that has the commit message.  The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit.  The hook is allowed to edit the commit message file.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message
  2006-12-20 17:44         ` Junio C Hamano
@ 2006-12-21  8:26           ` Johannes Schindelin
  2006-12-21  9:24           ` [PATCH] hooks/commit-msg: " Andy Parkins
  1 sibling, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2006-12-21  8:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Wed, 20 Dec 2006, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> >> Why SQUASH_MSG?  Doesn't it confuse git-explain when it wants to
> >> detect that you are in the middle of a squash merge?
> >
> > Yes, it confuses git-explain. Which did not existed when I concocted the 
> > first (broken) version of this patch. There are only two ways to give 
> > commit message templates AFAICT: misusing SQUASH_MSG and misusing 
> > MERGE_MSG.
> 
> I wonder...
> 
> # An example hook script to check the commit log message.
> # Called by git-commit with one argument, the name of the file
> # that has the commit message.  The hook should exit with non-zero
> # status after issuing an appropriate message if it wants to stop the
> # commit.  The hook is allowed to edit the commit message file.

Yes, I missed that.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] hooks/commit-msg: add example to add Signed-off-by line to message
  2006-12-20 17:44         ` Junio C Hamano
  2006-12-21  8:26           ` Johannes Schindelin
@ 2006-12-21  9:24           ` Andy Parkins
  2006-12-22  5:45             ` Junio C Hamano
  1 sibling, 1 reply; 11+ messages in thread
From: Andy Parkins @ 2006-12-21  9:24 UTC (permalink / raw)
  To: git

After checking to see if the commit message already has the target
signed-off-by (for example in --amend commits), this patch generates a
signed off by line from the repository owner and adds it to the commit
message.

Based on Johannes Schindelin's earlier patch to perform the same
function.

Originally, this was done in the pre-commit hook but Junio pointed out
that the commit-msg hook allows the message to be edited.  This has the
aditional advantage that the commit-msg hook gets passed the name of the
message file as a parameter, so it doesn't have to figure out GIT_DIR for
itself.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 templates/hooks--commit-msg |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/templates/hooks--commit-msg b/templates/hooks--commit-msg
index 0b906ca..ce76bdf 100644
--- a/templates/hooks--commit-msg
+++ b/templates/hooks--commit-msg
@@ -8,6 +8,11 @@
 #
 # To enable this hook, make this file executable.
 
+# Uncomment the below to add a Signed-off-by line to the message.
+#SOB=$(git var GIT_AUTHOR_IDENT | \
+#	sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p")
+#grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+
 # This example catches duplicate Signed-off-by lines.
 
 test "" = "$(grep '^Signed-off-by: ' "$1" |
-- 
1.4.4.2.g120e3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/commit-msg: add example to add Signed-off-by line to message
  2006-12-21  9:24           ` [PATCH] hooks/commit-msg: " Andy Parkins
@ 2006-12-22  5:45             ` Junio C Hamano
  2006-12-22  9:28               ` Andy Parkins
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2006-12-22  5:45 UTC (permalink / raw)
  To: git

Andy Parkins <andyparkins@gmail.com> writes:

> +# Uncomment the below to add a Signed-off-by line to the message.
> +#SOB=$(git var GIT_AUTHOR_IDENT | \
> +#	sed -n "s/^\(.*\) [0-9]\+ [-+][0-9]\+$/Signed-off-by: \1/p")
> +#grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

I suspect this sed script is quite wrong.  Did you test it?

 * quoting with dq means you are losing one level of backslash
   to the shell and sed is not seeing them.

 * one-or-more regexp '+' is typically not found in sed.

Also if this is meant to also handle cases where somebody
commits a patch received from an e-mail chain that multiple
people signed off their own changes to the patch, your name may
already appear earlier in the chain of existing Signed-off-by:
lines to sign off an earlier edition of the patch, but what you
are committing now would include your own changes you just made
on top of what all these people did, and you would want to sign
off that new change as well, I think.  So checking the last
instance of the existing signed-off-by line, ignoring earlier
ones, may be more preferrable.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] hooks/commit-msg: add example to add Signed-off-by line to message
  2006-12-22  5:45             ` Junio C Hamano
@ 2006-12-22  9:28               ` Andy Parkins
  0 siblings, 0 replies; 11+ messages in thread
From: Andy Parkins @ 2006-12-22  9:28 UTC (permalink / raw)
  To: git

On Friday 2006 December 22 05:45, Junio C Hamano wrote:

> I suspect this sed script is quite wrong.  Did you test it?

I plead not guilty; cut and pasted from Johannes.  In it's defence; I've been 
using it since he gave it to me without trouble.  My patch is wrapping it a 
little differently, but the sed is certainly the same.

Amazingly it does work though...

>  * quoting with dq means you are losing one level of backslash
>    to the shell and sed is not seeing them.

Unusual.  It doesn't seem to apply to non-recognised escapes:

$ echo "\1\(\)\+$/"
\1\(\)\+$/

>  * one-or-more regexp '+' is typically not found in sed.

Seems to be in mine (GNU sed version 4.1.5).

$ echo "xxxxxx" | sed -n 's/\(x\+\)$/MATCH/p'
MATCH

> off that new change as well, I think.  So checking the last
> instance of the existing signed-off-by line, ignoring earlier
> ones, may be more preferrable.

Accepted.

Notwithstanding the fact that it seems to be working for me; I'll fix the 
problems you highlight and re-patch.


Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@gmail.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-12-22  9:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-29 11:20 [PATCH] hooks/pre-commit: add example to add Signed-off-by line to message Johannes Schindelin
2006-12-20 15:54 ` Andy Parkins
2006-12-20 16:04 ` Andy Parkins
2006-12-20 16:18   ` Johannes Schindelin
2006-12-20 17:29     ` Junio C Hamano
2006-12-20 17:37       ` Johannes Schindelin
2006-12-20 17:44         ` Junio C Hamano
2006-12-21  8:26           ` Johannes Schindelin
2006-12-21  9:24           ` [PATCH] hooks/commit-msg: " Andy Parkins
2006-12-22  5:45             ` Junio C Hamano
2006-12-22  9:28               ` Andy Parkins

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).