How to run test before merging pullrequest
I am using GIT with a pull-request workflow ( https://www.atlassian.com/git/workflows#!pull-request ).
Usually, all developers run all tests before creating a pull request, but I want to make sure the pull request does not break the build.
How can I execute my entire test before merging the pull request?
# Create a temporary branch in your local repository.
git checkout -b temp-branch
# Merge the remote branch that contains the pull request.
git pull git://foo.com/repo.git feature-branch
# Run tests.
make test
# Go back to the previous branch.
git checkout -
# Delete the temporary branch.
git branch -D temp-branch
If the tests pass, merge the pull request into the actual target branch.
Another way to do this is to create a staging branch that only exists for testing purposes. Once the tests pass in that branch, commits can go to master. This method is probably easier to automate.
Perhaps by running git merge --no-commit
, then running the test and then either git commit
or git reset --hard HEAD
depending on the test result?