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

Re: pre-rebase safety hook

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 4, 2008, 19:35 UTC
Message-ID
<7vbpvrens3.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<e1a5e9a00812040958u3af4c69ofba66567baacb79c@mail.gmail.com>
"Tim Harper" <timcharper@gmail.com> writes:
Show 10 quoted lines
> Is anyone aware of a pre-rebase hook script that will prevent (or at
> least warn) you from letting a rebase rewrite a commit that has been
> pushed or merged into any branch except it's own?
>
> I've activated the pre-rebase.sample, and it does seem to give me any
> warnings at all:
>
> Here's the terminal output demonstrating what I mean:
>
> http://pastie.org/331082
The example script starts like this:
    #!/bin/sh
    # ...
    # This sample shows how to prevent topic branches that are already
    # merged to 'next' branch from getting rebased, because allowing it
    # would result in rebasing already published history.
As it says, it explicitly checks against 'next'.

The sample was written way before "branch --with" feature was added, and I suspect what it does can be expressed more concisely in modern git.

If you want to prevent a branch whose tip commit is on more than one branches from being rebased, I think something like this would suffice.

    #!/bin/sh
    LF='
    '
    in_branches=$(git branch -a --with "${2-HEAD}")
    case "$in_branches" in
    *"$LF"*)
	: this commit is on more than two branches
        exit 1
        ;;
    esac
    exit 0
But I didn't test it.
Previous: Tim HarperNext: Junio C Hamano
Message 2 of 3 in “pre-rebase safety hook”
  1. Tim HarperDec 4, 2008
  2. Junio C HamanoDec 4, 2008
  3. Junio C HamanoDec 4, 2008

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.