Subject: Re: Checking for fast-forward

From: Michael J Gruber <[email-masked]>
Date: Tue, 07 Jul 2009 10:21:40 +0200

Florian Mickler venit, vidit, dixit 06.07.2009 23:26:
> this is more of a git question, than smth special to msysgit. 
> 
> (git ml cc'd)
> 
> On Mon, 6 Jul 2009 17:36:54 +0100
> Lee Griffiths <[email-masked]> wrote:
> 
>>
>> I have a script that checks for fast-forwarding by doing a git push
>> --dry-run. This strikes me as the wrong way to do it as it does _all_
>> of the stuff a git push would normally do i.e., packing and so on, and
>> I'm only really after the fast-forward check. Seeing as I already do a
>> git push at the end of the script (actualy two, as I do a --tags one
>> as well[1]), it seems like a big waste of time. Is there anyother way
>> to check and see if the git push would work? (I want the script to
>> avoid doing a git pull if possible).

No. (I infer your question is how to find out whether a push is a
fast-forward.)

If you don't know the state of the branch head in the remote repo you
simply cannot know whether the push will be a fast-forward.

If you know that your corresponding remote branch (say
remotes/origin/foo) is up-to-date with the destination branch (say foo)
in the remote repo (e.g., because you know you've fetched before and
nobody else is allowed to push there) then you can compare your branch
to be pushed (say foo) with your remote branch:

If $(git rev-list bar..remotes/origin/foo) is empty then the branch foo
in the remote repo can be fast-forwarded to bar.

Chhers,
Michael