[FIXED JENKINS-15806] Check return code of hg pull.

I merged the code from pull request #31 and the master, as well as added a test as requested in the comments of the original pull request. [JENKINS-15806](https://issues.jenkins-ci.org/browse/JENKINS-15806)