2

What I'm trying to do is have a master repo with root dir named 'lib', within this are 2 sub-directories 'js' and 'html'. When creating local/dev branches based on 'lib', I need to pull the master 'html' directory, but inside that directory I need the latest 'js' directory.

Fyi, 'html' contains several templates for various projects, 'js' contains our own Javascript libraries but also 3rd party: jquery, YUI, Cufon, etc. Ideally I want to pull from 3rd party repo's where possible, though I can live without that for the time being.

In my case, 'js' should be separate from 'html' because it is used by other projects that have nothing to do with the 'html' directory, but projects based on templates from 'html' always require 'js'.

So my questions:

  • Am I able to nest 'js' within 'html' for dev/local branches?

I read about submodules in this SO question, and sparse checkouts, but I didn't understand how either of these could achieve the above - unless I'd clone '/lib' and sparse checkout '/lib/html/template1/' for example, and then inside '/lib/html/template1/js/' clone the same repo and sparse checkout '/lib/js'. In which case my second question:

  • If I nest sparse checked out repo's, what will happen when I a) commit at the higher level ('/lib/html/template1/'), and also when I commit at the nested level ('/lib/html/template1/js/')? That sounds a bit dodgy to me.

When work is complete on local branch(es), we'd merge with the dev branch. When the project is complete, we'd merge dev with master. So the third question:

  • Will a proposed solution allow the above directory structures and the described workflow?

Diagram outlining the proposed workflow: Diagram outlining the proposed workflow


I'm more than happy to be told I have the concept skewed, but if so please help me by explaining why, and how I might achieve the above. I'm absolutely no Git pro, I'm trying to start working with Git.

Community
  • 1
  • 1
danjah
  • 2,939
  • 2
  • 30
  • 47

1 Answers1

1

Note: a submodule can be checked-out at whatever branch you need: you can be in branch A in the parent repo, and branch B in a submodule, the parent repo doesn't care. All a parent repo records is the commit SHA1 of the submodule repo.

I would really recommend not using sparse checkout but:

  • maintain three separate Git repos (lib, js and html)
  • link js and html as submodules within lib repo
  • (this is the trick) maintain a separate lib directory structure with symbolic links to html and js.

In other words:

  • you clone lib, and initialize yours html and js repo, which doesn't give you the expected directory structure (you don't even have html or js directories within lib, since you didn't update your submodules).
  • You clone html and js repos separately
  • you create a separate directory structure (non-git) with:
    • symlink to lib cloned repo
    • lib/html being a symlink to html cloned repo
    • lib/html/js being a symlink to js cloned repo

In order to your parent repo lib (with submodules initialized but not updated) to detect changes from your two submodules, you can also make symlinks from your lib repo to the two separate html and js cloned repos.
That way, you can commit lib repo with the newly updated two submodules.

However, all your current developments are made from a non-git directory structure which follows your expected organization.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Here's where I'm @: I set up 3 the separate repos at github. Cloned lib locally, added js & html as submodules. They appeared inside the local lib folder along with some Git system files. I think is where my confusion starts as you said to link the submodules but also that I don't have html and js dirs inside lib since I haven't updated my submodules - but they are in fact there... I didn't clone html, but when I added it as a submod to lib, it cloned all html files to lib (inside the submodule html dir). Should this not have happened? I almost follow, I'll try symlinking when above is clear. – danjah Jan 30 '12 at 01:48
  • @Danjah when I spoke about "you clone `lib`, and initialize yours `html` and `js` repo", I was talking about a `lib` where `html` and `js` were already added as submodule. Ie about a second clone of `lib` (after that you declared / added the submodules in the first one) – VonC Jan 30 '12 at 07:03