Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

automation - mercurial automatic push on every commit

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...