Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple repositories in one directory (same level) - is it possible?

My original problem is that I have a directory where I write various scripts. Each of them is independent of others, and usually one-file-long. I want to have some versioning applied to them, but I have the following problems/requirements:

  1. I don't want to have to store each small script in a separate directory!
  2. I don't want to store them all in one repository OTOH, as they are completely unrelated, and:
    • some of them may later grow to more files (and then they will need a separate dir),
    • I sometimes want to copy one of them to a different machine (and I want to clone the whole repo).
  3. I want to benefit from (distributed) version control mechanisms -- at least:
    • "infinite" number of revisions,
    • ability to clone repositories on different computers,
    • ability to do "atomic" multi-file commits.

Is it possible?
I'd prefer to do it in some mainstream distributed VCS (a solution using Mercurial would be preferable, but I'm not fixed).

EDIT: the solution has to be free (at least "as in beer") and cross-platform (at least Win32 & Linux).

Related, but didn't help:

  • "two-git-repositories-in-one-directory" -- didn't find it helpful: the accepted answer looks like point 2. (above) to me; the current "community voted" answer sounds like 1.
  • "Version control of single files using Subversion" -- also too much of 2. or 1.
like image 950
akavel Avatar asked Apr 14 '11 09:04

akavel


4 Answers

These requirements seem pretty "special" to me, so here is a solution on par with them ^^

You may use two completely different VCS, in the same directory. Even two "instances" of SVN might work: SVN stores its metadata in a directory called .SVN and has (for historical reasons regarding ASP) the option to use _SVN. The Directory listing should look like this

.SVN    // Metadata for rep1
_SVN    // Metadata for rep2
script1 // in rep1
script2 // in rep2
...

Of course, you will need to hide or ignore the foreign scripts or folders from each VCS...

Added: This only accounts for two scripts in one folder and needs one additional VCS per script beyond that, so if you even consider this route and need more repositories, rename each Metadir and use a script to rename it back before updating:

MOVE .SVN-script1 .SVN
svn update
MOVE .SVN .SVN-script1
like image 191
Stephan B Avatar answered Nov 10 '22 11:11

Stephan B


Why don't you simply create a separate branch (in the git sense) for each (group of) script(s)?

You can develop them individually as you please. Switching to a branch will show you only the scripts from that branch. It's sort of like directories but managed by the version control system. If you later want to pluck a branch out into another repository, you can do that and if you want to combine two scripts into a single project, you can do that as well. The copying them to the different machine point might be a problem but you can clone the branch you're interested in and you it should work for you.

like image 42
Noufal Ibrahim Avatar answered Nov 10 '22 11:11

Noufal Ibrahim


Another proposition for my own consideration is "Using Convert to Decompose Your Repository" article on hgtip.com. It fails as a "standalone" solution, but could be helpful as an addition to the "mv .hgN .hg / MOVE .SVN-script1 .SVN" idea.

like image 1
akavel Avatar answered Nov 10 '22 09:11

akavel


You can create multiple hidden repository directories and symlink .hg to whichever one you want to be active. So if you have two repositories, create directories for them:

.hg_production
.hg_staging

Then to activate either of them just do:

ln -sf .hg_production .hg

You could easily create a bash command to do this. So instead you could write something like activate-repo production, which would run ln -sf .hg_production .hg.

Note: Mac doesn't seem to support ln -sf so instead you'll need to do:

rm .hg; ln -s .hg_production .hg
like image 1
Jonathan Potter Avatar answered Nov 10 '22 10:11

Jonathan Potter