开发者

How to do a quick push with Mercurial

开发者 https://www.devze.com 2023-03-08 20:59 出处:网络
After a change in my local repo, I commit with hg commit -m <message>, then I push to my server with hg pu开发者_StackOverflowsh, then in my server I update working dir with hg update.

After a change in my local repo, I commit with hg commit -m <message>, then I push to my server with hg pu开发者_StackOverflowsh, then in my server I update working dir with hg update.

Is there a better way to do this?


The first two steps you have described:

hg commit -m <message>
hg push

are required as per the fact that commits are kept completely separate from the server in Mercurial (and most other DVCS as well). You could write a post-commit hook to perform the push after each commit, but this is not advised because it prevents you from correcting simple mistakes during the commit and before the push.

Because you're trying to perform an update on 'the server' I'm assuming you are executing a version of the code in your repository on the server. I'm assuming this because typically the server would simply act as a master repository for you and your developers to access (and also to be subject to backups, etc..), and would not need the explicit hg update.

Assuming you are executing code on the server, you can try and replace the push and the update with this command:

hg pull <path to development repo> -u

which will perform a pull from your local repo and then an automatic update. Depending on your server configuration, it might be difficult to get the path to your local repo.


For the first part of the question (ie. automatically push when you do a commit), you can use the trick described in this answer : mercurial automatic push on every commit .

If you want to automatically update the working directory, you can do this with a hook. Add this in the hgrc of your repository (.hg/hgrc on your server directory) :

[hooks]
changegroup = hg update >&2

This will automatically update the working directory every time a push is made to this server. This hook is described in the Mercurial FAQ.

If you use these 2 solutions, the next time you do hg commit -m "message", the commit will be automatically pushed to the remote server and the working directory on the server will be updated.


There is an extension called autosync you might find useful:

This extension provides the autosync command which automatically and continuously commits working copy changes, fetches (pull, merge, commit) changes from another repository and pushes local changes back to the other repository. Think of configuration files or to-do lists as examples for things to synchronize. On a higher level the autosync command not only synchronizes repositories but working copies. A central repository (usually without a working copy) must be used as synchronization hub:

0

精彩评论

暂无评论...
验证码 换一张
取 消