I have a file (some kind of database) which is updated as developers test their code and pushed to a central mercurial repository.
I would like everyone to reuse this file and therefore whenever there is a pull / update from our central repository the local version should be replaced by the one stored centrally. In other words I would like to do a hg update -C for that file only, and having it done automatically upon a pull.
Is this possible to do with mercurial?
Developers can add a hook that does this, but you can't make them (unless you have control over their machines).
Something like this in a clone's .hg/hgrc file will delete the local file so the update replaces it fresh:
[hooks]
preupdate = rm path/to/databasefile
Keep in mind, of course, that update will put in place the version of the file as it appeared in the changeset to which the user is updating. So if you do hg update --rev 0 you'll get the very first version of that file, not the one in the most recent revision.
As an aside, usually if there's a file that changes a lot and is unumergeable you're better off having it be an untracked/ignored file that's fetched out of band -- for example, have your launch script download the latest version.
Related
Can I say "deleting this file is part of this commit" in hg? I know about hg rm, but it seems to only remove tracking of a file, not track its removal.
Concretely, if I have a repository containing file t in two places (A and B), and at A say hg rm t, and commit, and push, and at B say hg pull -u, file t will be there. :-(
I can't imagine anyone wanting that behaviour actually, but that's not the question. The question is: can I somehow sync working trees via hg, or only existing files?
If you pull, the deleted file will be deleted in your history, but not in your sources, locally. You have to update (hg up) for that.
If you have modified this file, and not committed it, Mercurial will tell you that you have uncommited changes, it won't be able to update.
Once it's commited, the deleted file will conflicts with the modified file, you'll be asked either you want to keep the modified file, or delete it.
I have a situation where I renamed a few files I was tracking in a mercurial repo without using hg rename command (just doing it via the file system).
This occured several revisions ago
Now I want to return to a revision prior to the file renames, fix a bug, and then rebuild that old revision
problem i have is that i am getting error messages along the lines of:
remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?
Is there a way I can fix the mistake I made when renaming the files all those revisions ago?
Depends on whether you committed the deletion of the files, but I assume you didn't and it doesn't seem so.
Then you can simply revert them in order to restore them to your working dir: hg revert file.txt. After that you can update to the previous revision without this question popping up. Alternatively just update to the previous revision you want to fix and accept the (c)changed version from remote.
If you want the rename to be permanent and also tracked by the repository, then commit that rename. Use hg addremove, possibly check with --dry-run first what it does so that no unwanted changes are added and commit the renaming of the files. Then go and update to the old revision and do whatever changes you want to commit there.
I have a tag created on mercurial on my Dev server called "today". I would like to update thee files on th Test server to the tag level "today". Can someone tell me how do I do that?
Is it going to be hg pull origin "today"
You're missing some basics. hg pull will never update local files (unless you use -u but don't do that). So first you need to get the changeset that defines the tag onto the server:
hg pull origin
That pulls over all the changesets but doesn't update any files. Then if you want all the files on the server to match those of the today tag you do:
hg update today
That makes sure all the files look like they do at the today tag. That command does no network activity at all -- it's just getting files out of the local repository you filled up using pull.
If you really, really want to only update those 3 files you'd do:
hg update --rev file1 pathto/file2 other/path/to/file3
In general though you should try find a workflow where all the files in your server's working directory are at the same revision. Files checked out at different revisions in the same repository was a svn sort of thing -- git and hg don't generally work that way.
I use Mercurial on desktops, and then push local repositories to a centralized server. I noticed that this remote server does not hold local copies of files in its repositories (the directory is empty, except obviously for the .hg one).
What is the preferred way to populate these directories with local copies? (which in turn are used by various unrelated services on that server).
What I came up so far is to use a hook and hg archive to create a local copy. This would be a satisfactory solution but I need to configure a per-repository hgrc file (which is tedious but I did not find a way to centralize this in /etc/mercurial/hgrc). Maybe a global script (in /etc/mercurial/hgrc, run for each changegroup event)? (in that case how can I get the repository name to use in a if...then scenario?)
If you can get access to the remote repository, you could install a hook for when changegroups come in, and perform an hg update when that happens.
A quick check shows this in the FAQ (question 4.21), but to summarize/duplicate: edit the .hg/hgrc file on the remote repository, and add the following lines:
[hooks]
changegroup = hg update
Whenever the remote repository gets pushed to (or when it performs a pull), it will update to the latest changeset.
Some caveats - this may fail if any changes have been made to the files on the remote side (you could use hg update -C instead). Also, if you have pushed any anonymous branches (which you would have to consciously force), you may not update to what you want to update to.
I've just recently moved a lot of my Views and Controllers into more appropriate locations and am now wanting to pull down recent changes from our central repo.
I've done a hg pull which worked fine and asked me to do a hg update to bring the changes down locally. This in turn informed me that I needed to do a hg merge however when I try this, I get a message stating that
abort: outstanding uncommitted changes
When I check this using hg status I see in the list all of the files that I've moved (so they're now deleted from their old location).
How do I tell Mercurial that I've removed these files? Do I have to go through each one of them and manually do a remove? Is this something that's possible using only the command line rather than doing it with a GUI tool?
From the command line to automatically hg rm the files you've removed you'd:
hg addremove
It's likely your GUI (you didn't say which you use) exposes that functionality too.
However, that's not what's causing your message. You have some already made local changes that mercurial does know about (unlike the removed files which it doesn't know about until you tell it), and you need a hg commit before you can merge.