sorin
sorin

Reputation: 170440

How to write a smart push for mercurial, one that does a pull and merge before doing the push?

I am looking to make some kind of alias for hg push so it will auto do a hg pull, hg merge, hg commit and hg push by itself.

Obviously if anything goes wrong, like conflicts on merge, it will stop.

So far I wrote this but it doesn't work when you do not have anything to pull:

hg pull -u && hg merge && hg ci -m "merge" && hg push

When you do not have anything to merge it will fail with:

abort: there is nothing to merge

Upvotes: 2

Views: 133

Answers (1)

Helgi
Helgi

Reputation: 5436

An built-in extension named fetch does all of that but push:

In the simplest case, hg fetch acts like hg pull -u — it pulls changes from a remote repository into a local one and updates the working directory. (This is like the "update" command as found in Subversion or CVS.)

If the pulled changes require merging, the fetch extension attempts an hg merge followed by an hg commit.

Enable the extension, then do:

$ hg fetch && hg push

Nevertheless, consider doing rebase (fast-forward merge) instead of a regular merge. This helps keeping the lineage clean from the endless "merge" commits, as is as safe as a regular merge if you --keep the original changesets.

As a matter of the fact, my usual workflow when working on a single task is like this:

# edit some files, test
$ hg commit
# edit some more files, test
$ hg commit
$ hg pull --rebase
$ hg push

Upvotes: 2

Related Questions