mercurial automatic push on every commit

10,228

You could add a hook to run push after a successful commit.

EDIT: I just tried it out and it seems to work fine. I added the following to the .hg/hgrc file of the repository I wanted to activate automatic pushing for:

[hooks]
commit.autopush = hg push

EDIT 2: Also, you don't have to worry about something like this:

  • You're in a repository that you don't want to automatically push.
  • You use hg -R ~/another-repo-that-autopushes commit to commit in a different repo that does automatically push.
  • Will the hg push hook end up pushing the changes in the current directory instead of the one you're committing in?

No, it won't. According to the page I linked:

An executable hook is always run with its current directory set to a repository's root directory.

It's an edge case, but Mercurial handles it correctly.

Share:
10,228

Related videos on Youtube

Sridhar Ratnakumar
Author by

Sridhar Ratnakumar

Updated on June 29, 2020

Comments

  • Sridhar Ratnakumar
    Sridhar Ratnakumar about 4 years

    Being very familiar with the subversion workflow and that fact that 99.9% of the time my computer is connected to the internet, I don't like doing 'hg ci' and 'hg push' separately.

    I remember bzr had a 'checkout' command that would bind subsequent 'commit' commands to automatically commit directly to the server ('push').

    Does mercurial have something similar to this?

    PS: Writing a shell script or alias that runs 'hg ci $* && hg push' would be the last thing I'd do.

    • David Sykes
      David Sykes over 14 years
      Why not a script? Doesn't a hook make the 0.1% of times you want to commit without a push much harder?
  • hwiechers
    hwiechers over 12 years
    The problem with this hook is that mq commands that create temporary commits (qnew, qpush, etc.) will trigger a push. Using the post-commit hook might be a better idea.
  • max
    max over 12 years
    @hwiechers: can you give an example of how to write a post-commit hook?
  • hwiechers
    hwiechers over 12 years
    @max: Instead of using commit.autopush = hg push do post-commit.autopush = hg push. The post-commit hook runs after the commit command successfully completes. The commit hook runs whenever a changeset is created in the local repository. See linux.die.net/man/5/hgrc for details.