{"thread":{"id":"33046","subject":"Elegant subdirectory checkout of remote-tracking branch?","startedAt":"2013-03-01T15:22:53Z","lastAt":"2013-03-02T08:04:25Z","messageCount":3,"participants":["W. Trevor King","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"210463","messageId":"20130301152253.GA9312@odin.tremily.us","threadId":"33046","inReplyTo":null,"subject":"Elegant subdirectory checkout of remote-tracking branch?","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2013-03-01T15:22:53Z","receivedAt":"2013-03-01T15:22:53Z","isPatch":false,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"I'm trying to figure out the most efficient way to keep an up to\ndate `todo` branch checked out in Meta [1].  I've tried a few\nthings like:\n\n  $ git submodule add -b refs/remotes/origin/todo --reference ./ -- ./ Meta\n\nand:\n\n  $ git clone --single-branch --branch refs/remotes/origin/todo ./ Meta\n\nThese fail because I can't use a remote tracking branch as a\nsource for the clone.  It should be possible to do:\n\n  $ git clone --reference . --single-branch --branch todo git://git.kernel.org/pub/scm/git/git.git Meta\n\nbut that will require (I think) network access during a fetch.\nSince I'm already fetching `origin` from the superproject, I\ndon't want to have to refetch them for the submodule (or whatever\nMeta ends up being).  Here's what I think happens with a\nsubmodule fetch:\n\n1. Query the remote URL to dereference its current `todo` branch.\n2. Check if we have that object in our local object share (which\n   we should, due to --reference and a recent superproject\n   fetch).\n3. Fetch any missing objects from the remote URL.\n\nI want to replace step 1 with:\n\n1b. Query the superproject to dereference its current\n    `origin/todo` branch.\n\nand step 3 with:\n\n3b. Access objects from the superproject directly (as with\n    --reference / --shared).\n\nDo I need to setup something like:\n\n  [remote \"origin\"]\n    url = ../.git\n    fetch = +refs/remotes/origin/todo:refs/remotes/origin/todo\n\nby hand, or is there an easier way?\n\nI can, of course, clone a local `todo` branch if I've set one up in my\nsuperproject.  However, then I'd have to update-ref that branch to\nsync with origin/todo after every fetch (that updates origin/todo).\nThis could be handled with a `git fetch` wrapper, but… yuck :p.\n\nAny suggestions for an elegant solution would be appreciated :).\nOnce we figure something out, I can write it up and stick it in\nhowto/maintain-git.txt.\n\nCheers,\nTrevor\n\n[1]: http://article.gmane.org/gmane.comp.version-control.git/144748\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"},{"id":"210469","messageId":"7vwqtrf120.fsf@alter.siamese.dyndns.org","threadId":"33046","inReplyTo":"20130301152253.GA9312@odin.tremily.us","subject":"Re: Elegant subdirectory checkout of remote-tracking branch?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-03-01T18:05:27Z","receivedAt":"2013-03-01T18:05:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"W. Trevor King\" <wking@tremily.us> writes:\n\n> Any suggestions for an elegant solution would be appreciated :).\n\nMy Meta checkout is not a submodule of anything.  It is a totally\nindependent repository and is not linked with git.git in any way.\nIt started as an independent repository, and it still is.\n\nThat it has been pushed to the same repository at k.org was a mere\nhistorical accident (I only had that repository writable there when\nI started); it not even a recommended practice to publish unrelated\nhistories in a single repository. You are seeing 'todo' in some of\nmy public mirrors only due to historical inertia.\n\nJust treat the git.git primary directory and the Meta directory as\nwhat they are: two checkouts of two totally independent projects,\none of which happens to be designed to be checked out at a fixed\nlocation relative to the other.  When running \"pull --ff-only\", do\nso in both independently.\n\nThat is what I do in my secondary repositories.\n\n> Once we figure something out, I can write it up and stick it in\n> howto/maintain-git.txt.\n\nYou are free to write and do whatever suites yourself, but a\ndescription of a workflow that is not what I use does not belong to\nthe howto/maintain-git.txt document ;-)\n"},{"id":"210503","messageId":"20130302080425.GA22861@sigill.intra.peff.net","threadId":"33046","inReplyTo":"20130301152253.GA9312@odin.tremily.us","subject":"Re: Elegant subdirectory checkout of remote-tracking branch?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-03-02T08:04:25Z","receivedAt":"2013-03-02T08:04:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 01, 2013 at 10:22:53AM -0500, W. Trevor King wrote:\n\n> These fail because I can't use a remote tracking branch as a\n> source for the clone.  It should be possible to do:\n> \n>   $ git clone --reference . --single-branch --branch todo git://git.kernel.org/pub/scm/git/git.git Meta\n> \n> but that will require (I think) network access during a fetch.\n\nYes, it will. Junio mentioned already that for him, \"Meta\" is really a\nseparate repository, and I think the simplest thing is to just treat it\nthat way (that's how I handle my personal \"meta\" branch).\n\nBut if you really want to save the extra network round trip during a\nfetch, you can either:\n\n  1. Just fetch from the surrounding repository using a custom refspec,\n     like:\n\n       git init Meta\n       cd Meta\n       git config add remote.origin.url ..\n       git config add remote.origin.fetch \\\n         refs/remotes/origin/todo:refs/remotes/origin/todo\n       git fetch\n       git checkout todo\n\nor\n\n  2. Look into the git-new-workdir script in contrib/workdir, which lets\n     you check out an alternate branch in a separate directory.\n\nThe latter would probably be the most seamless, but it's also the most\nlikely to have bugs. :)\n\n-Peff\n"}]}