git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Has anyone written a hook to block fast forward merges to a branch?

From
Jeff King <peff@peff.net>
Date
Mar 21, 2012, 18:40 UTC
Message-ID
<20120321184051.GB14638@sigill.intra.peff.net>
In-Reply-To
<CAJ8P3RCQjh1ehjsihAmu8roC1aeRo=R0sN2Wm0Y4bVk=st4ivw@mail.gmail.com>
On Wed, Mar 21, 2012 at 02:22:46PM -0400, Chris Patti wrote:
> I know there are hooks out there to block various other kinds of
> change, but I was wondering if anyone had specifically ever written
> one to block fast forward merges.

How would you detect them? If I do a fast-forward merge, the result is indistinguishable from simply building the commits directly on the branch in the first place.

If you mean "nobody should ever build commits directly on master, but always be merging in commits from topic branches", then that is easier to enforce; just look for non-merge commits down the --first-parent line, and reject if you find any. I think you could do it with:

  git rev-list --max-parents=1 --first-parent $OLD..$NEW

If that produces output, then somebody build directly on master (or did a backwards master->topic merge, but if you care about first-parents lineage, then that is equally bad).

-Peff
Previous: Chris PattiNext: Neal Kreitzinger
Message 2 of 6 in “Has anyone written a hook to block fast forward merges to a branch?”
  1. Chris PattiMar 21, 2012
  2. Jeff KingMar 21, 2012
  3. Neal KreitzingerMar 21, 2012
  4. Jeff KingMar 21, 2012
  5. Neal KreitzingerMar 21, 2012
  6. Jeff KingMar 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.