Local project workflow with Mercurial Hg and Bitbucket - mercurial

Usually I create my websites (PHP, HTML, CSS) local on my mac. I've MAMP and Mercurial (Hg) installed.
When I start a new project I draw up a new project directory in "htdocs" and begin with hg init. New files were added by hg add to the project or excluded in .hgignore. All changes in this project are completed with an hg commit.
Additional to the local project I push my whole project into a private repository to Bitbucket (hg push https://bitbucket.org/MyUser/MyProjectRepository). That works perfectly.
The problem begins when a second person works at the project at the same time. He clones with hg clone https://bitbucket.org/MyUser/MyProjectRepository my private Bitbucket repository.
When I change and commit a css file local on my mac, push it afterwords to Bitbucket and the second person changes something on his local css file at the same time he gets a merge problem when he he tries to push his changes to Bitbucket.
Does anyone know what the problem is?

The second person needs to pull and merge your changes from the bitbucket repository before pushing his changes back.
Take a look at HGInit here for a great introduction to using Mercurial with a team.

Related

Moving my mercurial repository to the central server, make mine a clone

Let's say my development team has a central server where we all clone our repos from, and commit/push back to it.
Now let's say I create a new repo on my desktop, hg init, commit. How can I make this repo on my desktop become the "parent" repo in the central server? I know I can either clone or just copy the repo to the central server. But the key is, without me having to clone that repo to my desktop again? Its really big so that initial clone can take a long time. Isn't there a way I can just edit a file to make my repo think its a clone instead of being the "parent"?
Information from where repository is cloned is written in .hg/hgrc file in your repository.
Create that file (if it does not exist) and add following lines
[paths]
default = https://my.parent.repository
Similary, if you want repository to think it is not clone of any repository, just remove those lines if they exist.

Embedding a github repository inside a mercurial (kiln) repository - how integrated is it?

Summarised Question:
Are github-hosted sub repositories within a mercurial/kiln repository possible, and if so are they automatically updated/cloned when the parent mercurial repository is operated on by a hg clone or hg commit command?
Detailed Question:
Following on from my question that was answered so excellently here , some of my third party code is in folders I downloaded a while ago from opensource efforts on github. Since at that stage I was not using version control, those folders where just standard folders that now been incorporated as sub repositories in mercurial.
This is obviously not ideal, as for one thing, new versions of the libraries may have bug fixes, or new features I wish to use in the future. I also may need to locally customise some of the libraries.
I can see from reading this link that it possible to have mercurial "know" about those git server urls (and revisions), so I can then have mercurial clone the github hosted libraries direct from their parent repos.
Am I right in saying that when I clone the parent (mercurial) repos, those files will be pulled from github, without having to separately manage this using git?
What is also not clear is, if I were to do this, and it transpired that code might need to be customized from within that github-cloned repository, would I need to use git to manage revisions of the local files, or would mercurial do that by proxy? eg id I were to hg commit -S would mercurial invoke git on my behalf to handle that?
Am I right in saying that when I clone the parent (mercurial) repos, those files will be pulled from github, without having to separately manage this using git?
Yes, clone of a Mercurial repository that contain subrepositories will trigger a clone of the subrepos too. It really happens on update. Mercurial notices the .hgsub file and issues the needed hg clone and git clone commands for you. It uses the information in .hgsubstate to know exactly what revision to checkout.
The subrepositories can be hosted anywhere. For a Git subrepository declared like
foo = [git]https://github.com/user/repo.git
Mercurial will simply issue the corresponding clone command:
git clone https://github.com/user/repo.git foo
It's then your reponsibility to later go into the foo repo and use Git to fetch new commits as necessary. After you fetch/pull new commits, you can make a top-level commit to record the new state of the subrepo in the .hgsubstate file. Use hg summary to see if a subrepo is dirty in this sense.
[...] would I need to use git to manage revisions of the local files, or would mercurial do that by proxy? eg id I were to hg commit -S would mercurial invoke git on my behalf to handle that?
When you edit files and make a top-level hg commit, Mercurial will make sure to commit the subrepo first (if you use hg commit -S or if ui.commitsubrepos=True). If you make a top-level push, then Mercurial will always push the subrepos first so that you always have a consistent set of changes on your server.

What's the best way to start a project in mercurial when you already have files in the project?

I'm starting with Mercurial. I'm reading the mercurial book but still have a question.
I've started my project month ago, and i have a lot of files and directories in it. Now, i want to use Mercurial and made myself an account in bitbucket. Now, i want to set this project up in Bitbucket. How can i add all those files to the bitbucket repo?
This is what i was thinking i could do:
I could try to (1) clone the empty repo (from bitbucket) (1) copy all files into that directory, (3) issue an "hg add" and after that (4) commiting.
Maybe you have a better way to do this.
Thanks!
(1)
hg clone https://ME#bitbucket.org/ME/myproject
(2)
cp existing-project/* myproject/
cd myproject
(3)
hg add
(4)
hg commit -u ME
(5)
hg push (i think i have to do this to make the changes visible)
You can simply hg init, hg add, and hg commit in the original project folder, then edit ~/project/.hg/hgrc to add a default-push location of your bitbucket repo (you can clone it to a temporary folder to get the hgrc created for you which you can copy into your project, even, without needing to RTFM for the right syntax.)
Because of the distributed nature of mercurial, this hgrc entry is the only thing relating your local repo to bitbucket at all; you can even hg push https://ME#bitbucket.org/ME/myproject without making the link explicit anywhere. Each copy of a repository is completely self-sufficient.
Wooble's answer is ok, but it's missing something, so I'm supplementing here.
When you first create an empty repository (by hg init or creating on bitbucket), it has no identity. However, as soon as it has any changesets, it has an identity and you can only push/pull between it and repositories that share that identity.
If you had 2 repositories A and B for separate projects, you wouldn't be able push/pull between them. Once you create a new repository on bitbucket you can push changesets from either A or B to that repo once. If you push changes from B that first time, the bitbucket repository is now related to B. You can't then push changesets from A into it, or pull changesets into A from it.
So when Wooble says,
...this hgrc entry is the only thing relating your local repo to bitbucket at all;
That is correct while it is still empty as it is not related to any repositories until it has changesets. And you still need that address to be able to push/pull between your local repo and the bitbucket repo, but once you've pushed changesets to it it also has that identity that relates it to your local repo.

TortoiseHG Update Remote Repository

I have recently added several projects to an existing repository on my local dev box. I periodically synchronize the local repository to a network drive repository. However, the new projects do not automatically show up on the network repo---only the ones that were there when I performed the initial clone.
How do I get the new projects into my network repo?
You use the 'hg push' command to push changesets from local to remote and use 'hg pull' to pull changesets from remote to local.
Moving the changesets over is sufficient to get the contents there, but if you want to see them in the working directory you hg update.
Also it sounds like you have multiple projects in a single repo. That's the normal setup in subversion, but in Mercurial or git you want separate repositories per project. It's better that way because all changesets/commits span the entire repo and it's not possible to hg update or hg clone only a portion of the repo like it is with svn.

Pushing a local clone to remote repository with Mercurial

Here is what I did:
Cloned a remote repository to my local computer. Created a second clone from the first clone. Made changes in the second clone. Never touched anything that resides in the first clone.
Now what happens if I directly push to remote repo from the second clone? A new branch is introduced in the remote repo?
Maybe a stupid question but I can't test it because there are other developers working on the code and I don't want to mess anything.
Thanks.
Now what happens if I directly push to remote repo from the second clone? A new branch is introduced in the remote repo?
What you would want to do in this situation is clone the central repo again (in case any other programmers made changes) merge your changes with those, and then push that back to the central repo.
This ensures that your branch is now part of the main branch again.
Metropolis
EDIT
Maybe this will be a little more clear
Clone repo1 to your machine
Make a clone of repo1 on your machine to keep the original in tact
Make changes to repo2 on your machine
Pull changes from repo2 to repo1, merge (if needed)
Clone CR again (in case other programmers made changes)
Pull changes from repo1 to the newly cloned repo (merge if needed)
Push newly cloned repo back to CR
Clone CR again and remove all of your repos to get the newest copy