tags:

views:

40

answers:

2

Say if we have a project known as main, and then we have a project that is analytics, and in Bash, we are at the analytics working directory and accidentally push to the main remote repository, will all the files in analytics be added to the main project, and is it reversible?

+2  A: 

You will get a complaint from Mercurial and the push will be aborted. It looks like this:

# create main repo:
% hg init main
% touch main/a.txt
% hg -R main commit --addremove -m main
adding a.txt

# create analytics repo
% hg init analytics
% touch analytics/a.txt
% hg -R analytics commit --addremove -m analytics
adding a.txt

# try the push:
% hg -R analytics push main
pushing to main
searching for changes
abort: repository is unrelated

Mercurial knows if two repositories are related based on their root nodes. That is, repositories A and B are related if they share a common root node.

Martin Geisler
how does Mercurial know? Say, if both projects only have 1 file that is `index.html`, then how does it know which project is which project? Or if both projects both happen to have a file at the same path, such as `config/database.yml`
動靜能量
I'm not sure about this comment - I just tried this with two local repos and from the CLI there were no warnings. I know that TortoiseHg will throw some warnings, but these can be avoided by selecting the 'force push' options.
dls
Interesting, how does hg know they are unrelated? Is it by using the rev number (the long one) to check they come from the same "root"? The fact that I can push to John's machine, or push to staging, push to testing, or push from testing to staging make it seem like it can be arbitrary.
動靜能量
@Marting: ok I take that back :) I retried and saw the same warning you did. The posters questions has a lot of worth in terms of related repos, however. For example, even with related repos there are times when you don't want to push changes (ie: in the middle of development, etc..)
dls
@Jian correct, it uses the hash-id from the root nodes.
tonfa
I've updated the answer to mention when two repositories are related.
Martin Geisler
A: 

if main is a local repository, you can navigate to main and perform a histedit to drop the offending commits. You can histedit from a server-based main as well, but if any other users have created clones, when they push to main they will re-add the changes.

histedit is an Hg extension that doesn't come bundled with Hg. Once you install it you can use it like this:

> hg histedit <rev>

where is the start of the offending commits. Histedit will generate a list of commits from up to the tip. In this list you can indicate to histedit that you want to keep the commit, edit the comment, or drop the commit. Drop should do the trick.

dls