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

Re: Anyone have a commit hook for forbidding old branches from being merged in?

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 1, 2011, 15:50 UTC
Message-ID
<201112011650.51547.trast@student.ethz.ch>
In-Reply-To
<CACBZZX4LyTaz=fU1vvgpeL904QFjJULCMVSP0uutcuxZT+-vWQ@mail.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 6 quoted lines
> 
> So before I write a hook to do this, is there anything that implements
> a hook that:
> 
>  * Checks if you're pushing a merge commit
>  * If so, is that merge based off and old version of $MAINBRANCH

I think it suffices to check whether any boundary commit in the updated range is older than what you allow, e.g.

while read old new rev; do
    # omitted: check it's an update, i.e., neither old nor new is 0..0
    git rev-list --boundary $old..$new |
    sed -n 's/^-//p' |
    xargs git rev-list --no-walk --before='cutoff limit' >bad
    test -s bad || exit 1
done

(Not tested much; in particular I'm not sure you can get away without limiting the number of args to rev-list to 1. A simple test seems to indicate so, however.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Ævar Arnfjörð BjarmasonNext: Neal Kreitzinger
Message 2 of 4 in “Anyone have a commit hook for forbidding old branches from being merged in?”
  1. Ævar Arnfjörð BjarmasonDec 1, 2011
  2. Thomas RastDec 1, 2011
  3. Neal KreitzingerDec 2, 2011
  4. Ævar Arnfjörð BjarmasonDec 2, 2011

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.