[PATCH v2/RFC] hook: use correct logical variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In general, a 'Sign-off' added should be that of the *committer* and not
that of the *commit's author*. As the 3rd part of the 'prepare-commit-msg'
hook appended the sign-off of the *commit's author* it worked weirdly in
some cases. For example 'git commit --amend -s' when coupled with that part
of the script woked weirdly as illustrated by the following scenario in which
the last commit's log message has the following trailer,

    ...

    Signed-off-by: Random Developer <developer@xxxxxxxxxxx>

and the commit's author is "Random Developer <developer@xxxxxxxxxxx>". Assume
that the commit is trying to be amended by another developer who's identity is
"Another Developer <another-dev@xxxxxxxxxxx>". When he tries to do

    $ git commit --amend -s

with the 3rd part of the hook enabled then the trailer he would see in his editor
would be,

    ...

    Signed-off-by: Random Developer <developer@xxxxxxxxxxx>
    Signed-off-by: Another Developer <another-dev@xxxxxxxxxxx>
    Signed-off-by: Random Developer <developer@xxxxxxxxxxx>

This is because,

  * the hook is invoked only after the sign-off is appended by the '-s' option

  * the script tries to add the sign-off of the *commit's author* using interpret-trailers
    and 'interpret-trailers' in it's default configuration tries to adds the trailer
    when the *neighbouring* trailer isn't the same as the one trying to be added.

This is just an example and this kind of issue could repeat if similar conditions are
satisified for other cases.

Moreover the rest of Git adds the sign-off of the *committer* using sequencer.c::append_signoff().
So, use the correct logical variable that identifies the committer to append the sign-off
in the sample hook script.

Bottom line: Being consistent prevents all sorts of weird issues.

Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@xxxxxxxxx>
---
 Changes in v2:

    - updated the commit message
 
 Suggestions regarding ways to improve the message are most welcome.

 templates/hooks--prepare-commit-msg.sample | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample
index a84c3e5a8..12dd8fd88 100755
--- a/templates/hooks--prepare-commit-msg.sample
+++ b/templates/hooks--prepare-commit-msg.sample
@@ -34,7 +34,7 @@ SHA1=$3
 #  *) ;;
 # esac
 
-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
+# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
 # git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
 # if test -z "$COMMIT_SOURCE"
 # then
-- 
2.14.0.rc1.434.g6eded367a




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux