git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Has anyone written a hook to block fast forward merges to a branch?
@ 2012-03-21 18:22 Chris Patti
  2012-03-21 18:40 ` Jeff King
  2012-03-21 20:32 ` Neal Kreitzinger
  0 siblings, 2 replies; 6+ messages in thread
From: Chris Patti @ 2012-03-21 18:22 UTC (permalink / raw)
  To: git

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.

Thanks,
-Chris


-- 
Christopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:
chrisfeohpatti | P: (260) 54PATTI
"Technology challenges art, art inspires technology." - John Lasseter, Pixar

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Has anyone written a hook to block fast forward merges to a branch?
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff King @ 2012-03-21 18:40 UTC (permalink / raw)
  To: Chris Patti; +Cc: git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Has anyone written a hook to block fast forward merges to a branch?
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Neal Kreitzinger @ 2012-03-21 20:32 UTC (permalink / raw)
  To: Chris Patti; +Cc: git

On 3/21/2012 1:22 PM, 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.
>
Maybe git-merge --no-ff would also be helpful to "do what you want".

(I'm not sure why you would tell people they can't do their work really 
fast or rebase to make it look like they did, but it seems that's what 
you are also implying.)

v/r,
neal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Has anyone written a hook to block fast forward merges to a branch?
  2012-03-21 20:32 ` Neal Kreitzinger
@ 2012-03-21 20:43   ` Jeff King
  2012-03-21 21:14     ` Neal Kreitzinger
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2012-03-21 20:43 UTC (permalink / raw)
  To: Neal Kreitzinger; +Cc: Chris Patti, git

On Wed, Mar 21, 2012 at 03:32:10PM -0500, Neal Kreitzinger wrote:

> On 3/21/2012 1:22 PM, 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.
> >
> Maybe git-merge --no-ff would also be helpful to "do what you want".

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.

Reading it again, I'm not sure whether that is the case or not. If not,
the disregard my original response. :)

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Has anyone written a hook to block fast forward merges to a branch?
  2012-03-21 20:43   ` Jeff King
@ 2012-03-21 21:14     ` Neal Kreitzinger
  2012-03-21 21:22       ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Neal Kreitzinger @ 2012-03-21 21:14 UTC (permalink / raw)
  To: Jeff King; +Cc: Chris Patti, git

On 3/21/2012 3:43 PM, Jeff King wrote:
> On Wed, Mar 21, 2012 at 03:32:10PM -0500, Neal Kreitzinger wrote:
>
>> On 3/21/2012 1:22 PM, 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.
>>>
>> Maybe git-merge --no-ff would also be helpful to "do what you
>> want".
>
> 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.
>
> Reading it again, I'm not sure whether that is the case or not. If
> not, the disregard my original response. :)
>
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.

v/r,
neal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Has anyone written a hook to block fast forward merges to a branch?
  2012-03-21 21:14     ` Neal Kreitzinger
@ 2012-03-21 21:22       ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2012-03-21 21:22 UTC (permalink / raw)
  To: Neal Kreitzinger; +Cc: Chris Patti, git

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-21 21:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).