git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Tim Harper" <timcharper@gmail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: pre-rebase safety hook
Date: Thu, 04 Dec 2008 11:35:56 -0800	[thread overview]
Message-ID: <7vbpvrens3.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <e1a5e9a00812040958u3af4c69ofba66567baacb79c@mail.gmail.com> (Tim Harper's message of "Thu, 4 Dec 2008 10:58:41 -0700")

"Tim Harper" <timcharper@gmail.com> writes:

> 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.

  reply	other threads:[~2008-12-04 19:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 17:58 pre-rebase safety hook Tim Harper
2008-12-04 19:35 ` Junio C Hamano [this message]
2008-12-04 22:29   ` Junio C Hamano

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=7vbpvrens3.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=timcharper@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).