{"thread":{"id":"33052","subject":"suggestion for a simple addition: git update-ref --ff-only","startedAt":"2013-03-01T23:18:59Z","lastAt":"2013-03-02T01:10:50Z","messageCount":3,"participants":["David Madore","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"210489","messageId":"20130301231859.GA334@achernar.madore.org","threadId":"33052","inReplyTo":null,"subject":"suggestion for a simple addition: git update-ref --ff-only","fromName":"David Madore","fromEmail":"david+news@madore.org","sentAt":"2013-03-01T23:18:59Z","receivedAt":"2013-03-01T23:18:59Z","isPatch":false,"sender":{"key":"david+news@madore.org","avatar":null},"body":"Hi list,\n\nI'd like to suggest a very simple, but IMHO quite useful, additional\noption to git-update-ref: an option --ff-only which would cause the\ncommand to refuse unless the current ref is an ancestor of the new\none.\n\nThe reason I think it would be useful: I occasionally wish to perform\na trivial (i.e., fast-forward) merge of some branch into another\n(e.g., after a git-fetch) without checking it out.  Now git-update-ref\nis perfect for that, but there is always the possibility of getting\nsomething wrong (which one would not have with git merge --ff-only,\nbut the latter requires checking out the branch), and this option\nwould avoid tedious verifications.\n\nHappy hacking,\n\n-- \n     David A. Madore\n   ( http://www.madore.org/~david/ )\n"},{"id":"210490","messageId":"7vehfyelvg.fsf@alter.siamese.dyndns.org","threadId":"33052","inReplyTo":"20130301231859.GA334@achernar.madore.org","subject":"Re: suggestion for a simple addition: git update-ref --ff-only","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-01T23:33:23Z","receivedAt":"2013-03-01T23:33:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Madore <david+news@madore.org> writes:\n\n> Hi list,\n>\n> I'd like to suggest a very simple, but IMHO quite useful, additional\n> option to git-update-ref: an option --ff-only which would cause the\n> command to refuse unless the current ref is an ancestor of the new\n> one.\n\nMild NAK.\n\nWhat you want may be \"git push . new_commit:refs/heads/foo\", by the\nway.\n\nThe \"update-ref\" plumbing does not want any such frill.\n"},{"id":"210500","messageId":"20130302011049.GA16458@sigill.intra.peff.net","threadId":"33052","inReplyTo":"20130301231859.GA334@achernar.madore.org","subject":"Re: suggestion for a simple addition: git update-ref --ff-only","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-02T01:10:50Z","receivedAt":"2013-03-02T01:10:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Mar 02, 2013 at 12:18:59AM +0100, David Madore wrote:\n\n> I'd like to suggest a very simple, but IMHO quite useful, additional\n> option to git-update-ref: an option --ff-only which would cause the\n> command to refuse unless the current ref is an ancestor of the new\n> one.\n> \n> The reason I think it would be useful: I occasionally wish to perform\n> a trivial (i.e., fast-forward) merge of some branch into another\n> (e.g., after a git-fetch) without checking it out.  Now git-update-ref\n> is perfect for that, but there is always the possibility of getting\n> something wrong (which one would not have with git merge --ff-only,\n> but the latter requires checking out the branch), and this option\n> would avoid tedious verifications.\n\nThe update-ref command is plumbing, which is supposed to do one small,\nwell-defined job. But you can compose many plumbing commands to do what\nyou want:\n\n  # input\n  ref=refs/heads/master\n  new=$some_sha1\n\n  # where are we now?\n  old=`git rev-parse --verify $ref` || exit 1\n\n  # is it a fast-forward?\n  if ! git merge-base --is-ancestor $old $new; then\n    echo >&2 \"Not a fast-forward\"\n    exit 1\n  fi\n\n  # update it; we do not have to worry about race conditions because\n  # update-ref will abort if somebody touched the ref in the meantime\n  git update-ref $ref $new $old\n\nYes, it's three commands instead of one, but it's much more flexible\n(you get to write your own message, you can use the same \"merge-base\" to\nhandle the \"already up to date\" case, etc).\n\n-Peff\n"}]}