Importing a Mercurial repository automatically (e.g. SVN Externals) - linux

I have a project that I am developing built off CodeIgniter. The main part of the project is a private system I am creating, but I want to add it to source control, to gain all the associated goodies. Now I'm using Mercurial, so I did the whole hg init bit, so I've got the repository set up.
Now, one of the things I've done is to make a library for CodeIgniter, which I use in this project. Now I want to make this library open, so I need a separate repo for that.
For anyone unfamiliar with CodeIgniter library development, here's a reference:
application
/config <- configuration files
/libraries <- library logic in here
Now I will probably develop a few more libraries in the course of this project, so I can't just dump a repo in the application folder without clumping them all together.
What I did was this:
dev/ci/library <- library here
dev/project <- project here
Now in both of those folders, I have made a repository. What I want to do is make the project repository automatically reference the library repository, so I can have a private and a public repository, as I explained earlier.
The main way to do this, I have read, is to use subrepositories, but I can only find examples on nested ones (which are unclear anyway, I find). How do I make it reference another repository like svn:externals?

You are correct, subrepos in Mercurial (or submodules in Git) are based on a nested organization.
But in your specific case you need:
two separate repos,
not nested
A way to reconcile both organizations (yours and the nested "subrepo") would be to have three repos
a parent repo (private one, as in can be pushed to a private repo)
the project (private one, as in can be pushed to a private repo)
the library (public one, as in can be pushed to a public repo)
That would give the following:
/dev
.hg (private repo)
.hgsubs (declare the two nested repos 'project' and 'ci/library')
project
.hg (private repo for your project)
config
.hgignore (for ignoring anyhting from libraries)
libraries (private directory, not version)
(symlink to /dev/ci/library)
ci
library
.hg (public repo
That way, you keep:
your two repo separate as you want
a link between the two in order to be able to get back those two repo at the exact reference you left them (i.e. you last pushed each of those repos).

Implemented in Mercurial 1.3, here's the instructions.

Related

Access files from different git repository

I want to separate out some files to a another git repository so that different projects can use it. These files contains some common functions that can be used by different projects in gitlab.
How can I access the newly created 'common' repository in my existing project?
Sample code:
file generate.py contents: *import common_xyz
def using_common_xyz: do something...*
I have now moved the file containing common_xyz to a different repository. I read that we can use "Include" keyword in .gitlab-ci.yml to access files in other repository. Or should I treat them as library? Can anyone suggest what is the best way?
Git submodules would be the way to go.
From git-scm.com:
Submodules allow you to keep a Git repository as a subdirectory of
another Git repository. This lets you clone another repository into
your project and keep your commits separate.
Here's a cool guide (theserverside.com) to get started using both GitHub and GitLab.
Here's another, on git-scm.com

Share and manage rc files (or config files) between mltiple projects

I'm working on different projects based on node, and one thing I always have to do is create the configuration files in all the projects since you all share a lot of configuration, for example, in all projects I use commitlint, lint-stage, husky, eslint, nodemon, and typescript and other settings.
How could I share all these settings in all projects and if I update any of them, update them in all projects?
The first thing that occurs to me is to create a npm packet with all the configurations, and several scripts, that copies / updates these configuration files in the root directory of the project where user is, something like
> myscript update
> myscrpt init
Another option would be to use the configurations programmatically, that is, instead of using a .rc use a .js, but this would force me to manage the dependencies in each project and create a .rc file that uses the configuration of the js file which is in the configuration package.
Another option is to create a github repository as a template, but if I update this repository, the projects I have created using this template are not updated, right?
What do you think is the best way to do it?
Even though git submodules seem to be discouraged lately, I think it's the most reasonable choice (assuming all of your projects are git-based): https://git-scm.com/book/en/v2/Git-Tools-Submodules
In your case, you'd have a 'common' repository with configuration, eg. configuration and two projects: projectA and projectB. Both of them would have the submodules added:
git submodule add <your_git_repo_server>/configuration
Please notice, however, that submodule refers to a particular commit (not a branch or tag - commit). You always have to take big care of synchronizing your dependencies correctly.

Gitlab repository vs project vs submodule

I started exploring Gitlab for version control management and I got an issue at the first step itsself. When ever I create a project its creating a new repository. I have few webapplications which are independent to each other. In that case do I need to use different repository for every project.
What I am looking for is what is what and when to use what but not able to find what is repository and what is project in gitlab website as well as through other sources as well.
Also I came across a term submodule, when can it be used. Can I create one global project and have all the webapplications as different submodules.
Can any one please help me in understanding the difference between those 3 and when to use what based on their intended way of usage. Also please help me by pointing to a good learning site where I can get the information of doing basic version control operations in gitlab.
Thanks.
Gitlab manages projects: a project has many features in addition of the Git repo it includes:
issues: powerful, but lightweight issue tracking system.
merge requests: you can review and discuss code before it is merged in the branch of your code.
wiki: separate system for documentation, built right into GitLab
snippets: Snippets are little bits of code or text.
So fear each repo you create, you get additional features in its associated project.
And you can manage users associated to that project.
See GitLab documentation for more.
The Git repo and Git submodule are pure Git notions.
In your case, a submodule might not be needed, unless you want a convenient way to remember the exact versions of different webapp repo, recorded in one parent repo.
But if that is the case, then yes, you can create one global project and have all the webapplications as different submodules.
Each of those submodules would have their own GitLab project (and Git repo).

In gitorious, is it possible to move repositories to a different project?

We have a bunch of small projects that have a single repository in Gitorious. Most of these repositories are really related. Had the foresight been put into the original creation, these would have all been created under the same project.
Now that there is all of this sprawl, is there any way to keep the repositories (or at least their history) intact, yet group them under a new project?
There is no such move option in gitorious.
The only way I know is to create a new repository inside the target project and then push the code to this repository. Afterwards, you can delete the repository. Note: moving the repository will update the associated URL. This will require coordinating the new URL with any local clones.

Two close repos in Mercurial

I have a project I'm currently working on, which I am contemplating making open source, but I definitely want to keep it closed-source for the time being. Inside this project, I have a sort of subproject that I want to make public, so anyone can access/fork it.
So here's what I want:
A mercurial SCC with:
Repo 1: All files from /dir/project/ - Private repo, requires username/password to pull/push/fork/browse etc.
Repo 2: Some files from /dir/project/stuff - Public repo, but requires username/password to modify.
How can I do this? Is there a better way I can do this? I'm using my shared hosting Linux environment to do this, so is symbolic linking a better idea?
I'm open to all suggestions thanks, still a bit of a HG newbie.
You should use "subrepository" to define the two parts of your project:
your parent repo would be the private one, with a reference (in a .hgsub file) to your public repo ()
your public repo woud be stored in a public referential, with no knowledge of the private part.
(No symlink necessary here)
See also in the same kind of problem the SO question "Mercurial Subrepos - How do you create them and how do they work?".
Subrepositories is a feature that allows you to treat a collection of repositories as a group. This will allow you to clone, commit to, push, and pull projects and their associated libraries as a group.

Resources