Simplifying the Pull-Merge-Commit Sequence
The process of merging changes as outlined above is straightforward, but requires running three commands in sequence:
hg pull -u hg merge hg commit -m 'Merged remote changes'
In the case of the final commit, you also need to enter a commit message, which is almost always going to be a piece of uninteresting “boilerplate” text.
It would be nice to reduce the number of steps needed,
if this were possible. Indeed, Mercurial is distributed with an
extension called fetch
that does just
this.
Mercurial provides a flexible extension mechanism that lets people extend its functionality, while keeping the core of Mercurial small and easy to deal with. Some extensions add new commands that you can use from the command line, while others work “behind the scenes,” for example adding capabilities to Mercurial’s built-in server mode.
The fetch
extension
adds a new command called, not surprisingly, hg
fetch. This extension acts as a combination of hg pull -u, hg
merge, and hg commit. It
begins by pulling changes from another repository into the current
repository. If it finds that the changes added a new head to the
repository, it updates to the new head, begins a merge, then (if the
merge succeeded) commits the result of the merge with an automatically
generated commit message. If no new heads were added, it updates the
working directory to the new tip changeset.
Enabling the fetch
extension is easy. Edit the .hgrc file in your home directory, and either go ...
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.