git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neal Kreitzinger <nkreitzinger@gmail.com>
To: Adrian Cornish <git@bluedreamer.com>
Cc: git@vger.kernel.org
Subject: Re: Stop a git commit by a specific author using pre-commit hook
Date: Sat, 10 Mar 2012 13:41:18 -0600	[thread overview]
Message-ID: <4F5BAE5E.5030407@gmail.com> (raw)
In-Reply-To: <CAGc=MuCQoQ711uXnB8J80RqsY+pqbaeCOXHjy0-mjq7a_ESdyA@mail.gmail.com>

On 3/8/2012 7:15 PM, Adrian Cornish wrote:
> My plan is to use git to keep track of changes in /etc but when
> committing I want to have the person making the change specify
> themselves as author by adding the --author option on the commandline.
>
> So I would like to stop accidental commits as root.
>
> I tried creating this pre-commit hook but it is not working - git var
> is still returning root even if I specify the author on commit line.
>
> AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
> if [ "$AUTHOR" == "root<root@localhost>" ];
> then
>     echo "Please commit under your own user name instead of \"$AUTHOR\":"
>     echo 'git commit --author="Adrian"'
>     echo "or if your name is not already in logs use full ident"
>     echo 'git commit --author="Adrian Cornish<a@localhost>"'
>     exit 1
> fi
> exit 0

We use whoami in our pre-commit hook to see who the user is that is 
doing the commit.  I think you could also use GIT_COMMITTER_NAME or 
linux $USER environment variables.  Either way, the --author seems like 
an unnecessary and unreliable way to get the username.  You're relying 
on the user to remember or obey that step.  By doing --author, you also 
seem to be implying that the git commit author value may not be the same 
as the user doing the commit so that would also ruin the original commit 
author data audit trail.  I haven't used these particular git 
environment variables, but I suspect they are dependent upon the user 
having their gitconfig filled out properly, so the linux whoami and 
$USER are probably more reliable.  If people can su to root then $USER 
will not work because it will still be set to their original user name 
(before they did su to root).  Therefore, "whoami" seems like your best 
solution.

v/r,
neal

  reply	other threads:[~2012-03-10 19:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-09  1:15 Stop a git commit by a specific author using pre-commit hook Adrian Cornish
2012-03-10 19:41 ` Neal Kreitzinger [this message]
2012-03-10 21:54   ` Junio C Hamano
2012-03-10 23:03     ` Neal Kreitzinger
2012-03-11 11:05       ` Junio C Hamano
2012-03-11 11:08         ` [PATCH 1/(3/4)] test: does pre-commit-hook learn authorship? Junio C Hamano
2012-03-11 20:30           ` Johannes Sixt
2012-03-11 21:09             ` Junio C Hamano
2012-03-11 11:09         ` [PATCH 2/(3/4)] ident.c: add split_ident_line() to parse formatted ident line Junio C Hamano
2012-03-11 11:11           ` [PATCH 3/3] commit: pass author/committer info to hooks Junio C Hamano
2012-03-12 11:29             ` Jeff King
2012-03-11 11:15           ` [PATCH 3/4] run_hook(): enhance the interface to pass arbitrary environment Junio C Hamano
2012-03-11 11:16           ` [PATCH 4/4] commit: pass author/committer info to hooks Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F5BAE5E.5030407@gmail.com \
    --to=nkreitzinger@gmail.com \
    --cc=git@bluedreamer.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).