[API] Improve the logic for checking out `current_branch` after test run

(Mainly an attempt to fix Travis.)