{"thread":{"id":"33716","subject":"Pitfalls in auto-fast-forwarding heads that are not checked out?","startedAt":"2013-05-03T22:46:08Z","lastAt":"2013-05-07T14:27:46Z","messageCount":6,"participants":["Martin Langhoff","Johannes Sixt","John Szakmeister","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"216377","messageId":"CACPiFCLnjCeCpt8wR71bFweFyA3rFCsnbEiR1yRD1n=X5K84Mw@mail.gmail.com","threadId":"33716","inReplyTo":null,"subject":"Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-05-03T22:46:08Z","receivedAt":"2013-05-03T22:46:08Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"I am building a small git wrapper around puppet, and one of the\nactions it performs is auto-fastforwarding of branches without\nchecking them out.\n\nIn simplified code... we ensure that we are on a head called master,\nand in some cases \"ppg commit\", will commit to master and...\n\n  ## early on\n  # sanity-check we are on master\n  headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)\n  if [ \"$headname\" -ne \"refs/heads/headname\" ]; then\n      echo >&2 \"ERROR: can only issue --immediate commit from the\nmaster branch!\"\n      exit 1\n  fi\n\n  ## then\n  git commit -bla blarg baz\n\n  ## and then...\n\n  # ensure we can ff\n  head_sha1=$(git rev-parse --revs-only master)\n  mb=$(git merge-base $production_sha1 refs/heads/master)\n  if [[ \"$mb\" -ne \"$production_sha1\" ]]; then\n      echo >&2 \"ERROR: cannot fast-forward master to production\"\n      exit 1\n  fi\n  $GIT_EXEC_PATH/git-update-ref -m \"ppg immediate commit\"\nrefs/heads/production $head_sha1 $production_sha1 || exit 1\n\nAre there major pitfalls in this approach? I cannot think of any, but\ngit has stayed away from updating my local tracking branches; so maybe\nthere's a reason for that...\n\ncheers,\n\n\nm\n--\n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"},{"id":"216403","messageId":"5184B9F9.2010708@kdbg.org","threadId":"33716","inReplyTo":"CACPiFCLnjCeCpt8wR71bFweFyA3rFCsnbEiR1yRD1n=X5K84Mw@mail.gmail.com","subject":"Re: Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-05-04T07:34:17Z","receivedAt":"2013-05-04T07:34:17Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 04.05.2013 00:46, schrieb Martin Langhoff:\n> I am building a small git wrapper around puppet, and one of the\n> actions it performs is auto-fastforwarding of branches without\n> checking them out.\n> \n> In simplified code... we ensure that we are on a head called master,\n> and in some cases \"ppg commit\", will commit to master and...\n> \n>   ## early on\n>   # sanity-check we are on master\n>   headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)\n>   if [ \"$headname\" -ne \"refs/heads/headname\" ]; then\n\nYou mean \"refs/heads/master\" and \"!=\" here because -ne is numeric\ncomparison in a shell script.\n\n>       echo >&2 \"ERROR: can only issue --immediate commit from the\n> master branch!\"\n>       exit 1\n>   fi\n> \n>   ## then\n>   git commit -bla blarg baz\n> \n>   ## and then...\n> \n>   # ensure we can ff\n>   head_sha1=$(git rev-parse --revs-only master)\n>   mb=$(git merge-base $production_sha1 refs/heads/master)\n>   if [[ \"$mb\" -ne \"$production_sha1\" ]]; then\n\nYour approach looks OK (but note again the incorrect \"-ne\").\n\nSince git 1.8.0 you can express this check as\n\n    if git merge-base --is-ancestor $production_sha1 refs/heads/master\n\n>       echo >&2 \"ERROR: cannot fast-forward master to production\"\n\n\techo >&2 \"ERROR: cannot fast-forward production to master\"\n\n>       exit 1\n>   fi\n>   $GIT_EXEC_PATH/git-update-ref -m \"ppg immediate commit\"\n> refs/heads/production $head_sha1 $production_sha1 || exit 1\n> \n> Are there major pitfalls in this approach?\n\nI don't think there are.\n\n> I cannot think of any, but\n> git has stayed away from updating my local tracking branches; so maybe\n> there's a reason for that...\n\nI don't understand what you are saying here. What is \"that\"?\n\n-- Hannes\n"},{"id":"216412","messageId":"CACPiFCK=8KFX++Bg+LhymorSMnWgrj5Js+-f=UYyZnNY=n9WiA@mail.gmail.com","threadId":"33716","inReplyTo":"5184B9F9.2010708@kdbg.org","subject":"Re: Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-05-04T11:35:27Z","receivedAt":"2013-05-04T11:35:27Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On Sat, May 4, 2013 at 3:34 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> You mean \"refs/heads/master\" and \"!=\" here because -ne is numeric\n> comparison in a shell script.\n\nthanks! Yeah, I fixed those up late last night :-)\n\n> Since git 1.8.0 you can express this check as\n>\n>     if git merge-base --is-ancestor $production_sha1 refs/heads/master\n\nAh, that's great! Unfortunate it's not there in earlier / more widely\nused releases of git.\n\n>> Are there major pitfalls in this approach?\n>\n> I don't think there are.\n\nThanks...\n\n>> I cannot think of any, but\n>> git has stayed away from updating my local tracking branches; so maybe\n>> there's a reason for that...\n>\n> I don't understand what you are saying here. What is \"that\"?\n\nWhen I do git pull, git is careful to only update the branch I have\nchecked out (if appropriate). It leaves any other branches that track\nbranches on the remote that has just been fetched untouched. I always\nthought that at some point git pull would learn to evaluate those\nbranches and auto-merge them if the merge is a ff.\n\nI would find that a natural bit of automation in git pull. Of course\nit would mean a change of semantics, existing scripts could be\naffected.\n\ncheers,\n\n\n\nm\n--\n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"},{"id":"216414","messageId":"CAEBDL5W6J60KhAjnWyCkMbR_tu2kftqp_w0rc0RsUr2-rDNgUQ@mail.gmail.com","threadId":"33716","inReplyTo":"CACPiFCK=8KFX++Bg+LhymorSMnWgrj5Js+-f=UYyZnNY=n9WiA@mail.gmail.com","subject":"Re: Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"John Szakmeister","fromEmail":"john@szakmeister.net","sentAt":"2013-05-04T13:17:13Z","receivedAt":"2013-05-04T13:17:13Z","isPatch":false,"sender":{"key":"john@szakmeister.net","avatar":"https://avatars.githubusercontent.com/u/448087?v=4"},"body":"On Sat, May 4, 2013 at 7:35 AM, Martin Langhoff\n<martin.langhoff@gmail.com> wrote:\n[snip]\n> When I do git pull, git is careful to only update the branch I have\n> checked out (if appropriate). It leaves any other branches that track\n> branches on the remote that has just been fetched untouched. I always\n> thought that at some point git pull would learn to evaluate those\n> branches and auto-merge them if the merge is a ff.\n>\n> I would find that a natural bit of automation in git pull. Of course\n> it would mean a change of semantics, existing scripts could be\n> affected.\n\nI agree.  I've been using this script for quite a while now:\n\n<https://github.com/jszakmeister/etc/blob/master/git-addons/git-ffwd>\n\nI've been pretty happy with it.  It's not of my own design, I picked\nup from StackOverflow:\n\n<http://stackoverflow.com/a/9076361/683080>\n\nAnd made a couple of minor tweaks to cope with my configuration (I\nhave merge setup to not fast-forward merge by default).\n\n-John\n"},{"id":"216418","messageId":"20130504185146.GD25863@elie.Belkin","threadId":"33716","inReplyTo":"CACPiFCK=8KFX++Bg+LhymorSMnWgrj5Js+-f=UYyZnNY=n9WiA@mail.gmail.com","subject":"Re: Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-05-04T18:51:46Z","receivedAt":"2013-05-04T18:51:46Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Martin Langhoff wrote:\n> On Sat, May 4, 2013 at 3:34 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n\n>> Since git 1.8.0 you can express this check as\n>>\n>>     if git merge-base --is-ancestor $production_sha1 refs/heads/master\n>\n> Ah, that's great! Unfortunate it's not there in earlier / more widely\n> used releases of git.\n\nAnother trick is to use \"git push\":\n\n\tgit push . $production_sha1:refs/heads/master\n\nThis advances the \"master\" branch if\n\n (1) it is not the current branch, and\n (2) that update is a fast-forward\n\nIt can be convenient sometimes.\n\nHope that helps,\nJonathan\n"},{"id":"216613","messageId":"CACPiFCJ9Jcd8VG3aTocaJ_jkcY8=3aUJUbDMJcfRXOaW41EsmQ@mail.gmail.com","threadId":"33716","inReplyTo":"20130504185146.GD25863@elie.Belkin","subject":"Re: Pitfalls in auto-fast-forwarding heads that are not checked out?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-05-07T14:27:46Z","receivedAt":"2013-05-07T14:27:46Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On Sat, May 4, 2013 at 2:51 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Another trick is to use \"git push\":\n>         git push . $production_sha1:refs/heads/master\n\nGreat trick -- thanks! In use in ppg now :-)\n\n\n\nm\n--\n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"}]}