git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Neal Kreitzinger <nkreitzinger@gmail.com>
Cc: Chris Patti <cpatti@gmail.com>, git@vger.kernel.org
Subject: Re: Has anyone written a hook to block fast forward merges to a branch?
Date: Wed, 21 Mar 2012 17:22:01 -0400	[thread overview]
Message-ID: <20120321212201.GA16734@sigill.intra.peff.net> (raw)
In-Reply-To: <4F6A44AD.4040600@gmail.com>

On Wed, Mar 21, 2012 at 04:14:21PM -0500, Neal Kreitzinger wrote:

> >When I wrote my response, I assumed the intent was that people
> >_should_ be using --no-ff, but that he wanted to enforce it via hook
> >during a push to a central repository.
> >
> Would your script only work at "push time", or would it also work at
> "commit time"?  I'm not sure at what point he thinks he wants to
> enforce it.  I don't think git yet knows the info your script is
> asking for at "commit time" (ie, pre-commit hook and its brethren),
> and by the time it does know it's too late to block the commit
> locally.  Maybe it does know that inof at the point one of those
> "commit time" hooks runs.  I haven't tried it.

Completely untested, but you could probably do something like this in a
pre-commit hook:

  if test "`git symbolic-ref HEAD 2>/dev/null`" = "refs/heads/master" &&
     ! test -e "`git rev-parse --git-dir`/MERGE_HEAD"
  then
    echo >&2 "Don't commit right on master. Go make a topic branch."
    exit 1
  fi

but I'm not sure if that would catch fast-forward merges or not. You
might also have to do an ancestry check against MERGE_HEAD.

Whether such a thing would be useful depends on your workflow and
exactly what you're trying to achieve. Usually people try to enforce
policy like this on pushes, just because that is an easy central point
(e.g., somebody who forgets to use topic branches or --no-ff may also
forget to set up their hooks; but if you have a central publishing
point, it's easy to set up the policies there just once).

-Peff

      reply	other threads:[~2012-03-21 21:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21 18:22 Has anyone written a hook to block fast forward merges to a branch? Chris Patti
2012-03-21 18:40 ` Jeff King
2012-03-21 20:32 ` Neal Kreitzinger
2012-03-21 20:43   ` Jeff King
2012-03-21 21:14     ` Neal Kreitzinger
2012-03-21 21:22       ` Jeff King [this message]

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=20120321212201.GA16734@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=cpatti@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=nkreitzinger@gmail.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.
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).