All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Martin Langhoff <martin.langhoff@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Pitfalls in auto-fast-forwarding heads that are not checked out?
Date: Sat, 04 May 2013 09:34:17 +0200	[thread overview]
Message-ID: <5184B9F9.2010708@kdbg.org> (raw)
In-Reply-To: <CACPiFCLnjCeCpt8wR71bFweFyA3rFCsnbEiR1yRD1n=X5K84Mw@mail.gmail.com>

Am 04.05.2013 00:46, schrieb Martin Langhoff:
> I am building a small git wrapper around puppet, and one of the
> actions it performs is auto-fastforwarding of branches without
> checking them out.
> 
> In simplified code... we ensure that we are on a head called master,
> and in some cases "ppg commit", will commit to master and...
> 
>   ## early on
>   # sanity-check we are on master
>   headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
>   if [ "$headname" -ne "refs/heads/headname" ]; then

You mean "refs/heads/master" and "!=" here because -ne is numeric
comparison in a shell script.

>       echo >&2 "ERROR: can only issue --immediate commit from the
> master branch!"
>       exit 1
>   fi
> 
>   ## then
>   git commit -bla blarg baz
> 
>   ## and then...
> 
>   # ensure we can ff
>   head_sha1=$(git rev-parse --revs-only master)
>   mb=$(git merge-base $production_sha1 refs/heads/master)
>   if [[ "$mb" -ne "$production_sha1" ]]; then

Your approach looks OK (but note again the incorrect "-ne").

Since git 1.8.0 you can express this check as

    if git merge-base --is-ancestor $production_sha1 refs/heads/master

>       echo >&2 "ERROR: cannot fast-forward master to production"

	echo >&2 "ERROR: cannot fast-forward production to master"

>       exit 1
>   fi
>   $GIT_EXEC_PATH/git-update-ref -m "ppg immediate commit"
> refs/heads/production $head_sha1 $production_sha1 || exit 1
> 
> Are there major pitfalls in this approach?

I don't think there are.

> I cannot think of any, but
> git has stayed away from updating my local tracking branches; so maybe
> there's a reason for that...

I don't understand what you are saying here. What is "that"?

-- Hannes

  reply	other threads:[~2013-05-04  7:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-03 22:46 Pitfalls in auto-fast-forwarding heads that are not checked out? Martin Langhoff
2013-05-04  7:34 ` Johannes Sixt [this message]
2013-05-04 11:35   ` Martin Langhoff
2013-05-04 13:17     ` John Szakmeister
2013-05-04 18:51     ` Jonathan Nieder
2013-05-07 14:27       ` Martin Langhoff

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=5184B9F9.2010708@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=martin.langhoff@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.