From: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Christian Couder <christian.couder@gmail.com>
Subject: "git intepret-trailers" vs. "sed script" to add the signature
Date: Sat, 01 Jul 2017 21:46:30 +0530 [thread overview]
Message-ID: <1498925790.4321.7.camel@gmail.com> (raw)
In-Reply-To: <1498918546.4321.1.camel@gmail.com>
On Sat, 2017-07-01 at 19:45 +0530, Kaartic Sivaraam wrote:
> On Fri, 2017-06-30 at 09:44 -0700, Junio C Hamano wrote:
> > It does look like a hack. I was wondering if "interpret-trailers"
> > is mature enough and can be used for this by now.
>
> It does look promising except for a few differences from the hook
> which
> I'll explain in the following mail.
interpet-trailers
=================
After enabling the script I tried the following (shown here as a diff)
to add the signature with "interpret-trailers",
diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample
index 6473bcacd..9f8cbe7fd 100755
--- a/templates/hooks--prepare-commit-msg.sample
+++ b/templates/hooks--prepare-commit-msg.sample
@@ -33,4 +33,4 @@ case "$2,$3" in
esac
SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
-grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
+git interpret-trailers --in-place --trailer "$SOB" "$1"
It adds the signature if it's not present in the following cases,
* commit
* merge
* commit --amend
* commit -F
* cherry-pick
It's pretty good in adding the signature except that it's not in line
with "git commit -s" whose resulting "spacing" (new lines before and
after) as shown in the editor is given below,
>
>
> Signed-off-by: Test <hello@example.org>
>
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> ...
The spacing of "git interpret-trailers" in the editor for the relevant
cases are,
commit
------
>
> Signed-off-by: Test <hello@example.org>
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> ...
commit --amend
--------------
> Empty commit to test amending
>
> Signed-off-by: Test <hello@example.org>
>
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> ...
merge
-----
> Merge branch 'hook-test' into hook-test-merge
>
> Signed-off-by: Test <hello@example.org>
>
> # Please enter a commit message to explain why this merge is necessary,
> # especially if it merges an updated upstream into a topic branch.
> #
> # Lines starting with '#' will be ignored, and an empty message aborts
> # the commit.
So, it seems that excepting for 'commit' it has quite a nice spacing. I
guess we could add something like the following to fix that,
# Add new line after SOB in case of "git commit"
NEW_LINE='\
'
if [ -z "$2" ]
then
sed -i "1i$NEW_LINE" "$1"
fi
sed-script
==========
I also tried to add the signature that immitates the "-s" option
of "git commit" using "sed" but it works only in following cases,
* commit
* commit --amend
* merge
It doesn't seem to work in cases where user doesn't edit the message
using the editor. I'm not sure why.
I'm not including a patch of my manual way here as "git interpret-
trailers" (with the fix added) seems quite promising (at least to me).
I'll send a typical patch that uses "git interpret-headers" as a
follow-up.
--
Regards,
Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
next prev parent reply other threads:[~2017-07-01 17:23 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-30 15:43 [PATCH] hooks: add signature to the top of the commit message Kaartic Sivaraam
2017-06-30 16:44 ` Junio C Hamano
2017-07-01 14:15 ` Kaartic Sivaraam
2017-07-01 16:16 ` Kaartic Sivaraam [this message]
2017-07-01 17:32 ` [PATCH/RFC] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-03 16:58 ` "git intepret-trailers" vs. "sed script" to add the signature Junio C Hamano
2017-07-04 19:16 ` Kaartic Sivaraam
2017-07-05 1:48 ` Junio C Hamano
2017-07-05 17:00 ` [PATCH] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-05 17:35 ` Kaartic Sivaraam
2017-07-05 19:37 ` Junio C Hamano
2017-07-05 20:14 ` Ramsay Jones
2017-07-06 14:30 ` Kaartic Sivaraam
2017-07-01 17:36 ` [PATCH] hooks: add signature to the top of the commit message Junio C Hamano
2017-07-01 18:40 ` Philip Oakley
2017-07-01 20:28 ` Junio C Hamano
2017-07-01 21:00 ` Philip Oakley
2017-07-01 18:52 ` Kaartic Sivaraam
2017-07-01 20:31 ` Junio C Hamano
2017-07-02 11:19 ` Kaartic Sivaraam
2017-07-02 11:27 ` [PATCH/RFC] hooks: replace irrelevant hook sample Kaartic Sivaraam
2017-07-05 16:51 ` [PATCH] " Kaartic Sivaraam
2017-07-05 19:50 ` Junio C Hamano
2017-07-07 11:53 ` Kaartic Sivaraam
2017-07-07 15:05 ` Junio C Hamano
2017-07-07 15:24 ` Kaartic Sivaraam
2017-07-07 16:07 ` [PATCH 1/2] " Kaartic Sivaraam
2017-07-07 16:07 ` [PATCH 2/2] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-07 18:27 ` [PATCH 1/2] hooks: replace irrelevant hook sample Junio C Hamano
2017-07-10 14:17 ` [PATCH 1/4] hook: cleanup script Kaartic Sivaraam
2017-07-10 14:17 ` [PATCH 2/4] hook: name the positional variables Kaartic Sivaraam
2017-07-10 19:51 ` Junio C Hamano
2017-07-10 14:17 ` [PATCH 3/4] hook: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-10 15:13 ` Ramsay Jones
2017-07-10 19:53 ` Junio C Hamano
2017-07-11 14:11 ` [PATCH 1/4] hook: cleanup script Kaartic Sivaraam
2017-07-11 14:11 ` [PATCH 2/4] hook: name the positional variables Kaartic Sivaraam
2017-07-11 14:11 ` [PATCH 3/4] hook: add sign-off using "interpret-trailers" Kaartic Sivaraam
2017-08-14 8:46 ` [PATCH] hook: use correct logical variable Kaartic Sivaraam
2017-08-14 17:54 ` Stefan Beller
2017-08-14 18:19 ` Junio C Hamano
2017-08-15 9:31 ` Kaartic Sivaraam
2017-08-15 17:28 ` Junio C Hamano
2017-08-17 2:47 ` Kaartic Sivaraam
2017-08-17 2:50 ` [PATCH v2/RFC] " Kaartic Sivaraam
2017-08-15 9:32 ` [PATCH] " Kaartic Sivaraam
2017-07-11 14:11 ` [PATCH 4/4] hook: add a simple first example Kaartic Sivaraam
2017-07-11 14:30 ` Kaartic Sivaraam
2017-07-11 13:10 ` [PATCH 3/4] hook: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-11 13:18 ` Kaartic Sivaraam
2017-07-10 14:17 ` [PATCH 4/4] hook: add a simple first example Kaartic Sivaraam
2017-07-10 20:02 ` Junio C Hamano
2017-07-11 13:29 ` Kaartic Sivaraam
2017-07-11 16:03 ` Junio C Hamano
2017-07-11 18:04 ` Kaartic Sivaraam
2017-07-11 18:06 ` Kaartic Sivaraam
2017-07-10 19:50 ` [PATCH 1/4] hook: cleanup script Junio C Hamano
2017-07-02 11:29 ` [PATCH] hooks: add script to HOOKS that allows adding notes from commit message Kaartic Sivaraam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498925790.4321.7.camel@gmail.com \
--to=kaarticsivaraam91196@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).